Make database interactions deterministic in test
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
co-authored by
Nathan Sobo
parent
3ba530bca1
commit
98f691d16d
+1
-19
@@ -14,7 +14,7 @@ use keymap::MatchResult;
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use pathfinder_geometry::{rect::RectF, vector::vec2f};
|
||||
use platform::Event;
|
||||
use postage::{mpsc, oneshot, sink::Sink as _, stream::Stream as _};
|
||||
use postage::{mpsc, sink::Sink as _, stream::Stream as _};
|
||||
use smol::prelude::*;
|
||||
use std::{
|
||||
any::{type_name, Any, TypeId},
|
||||
@@ -2310,24 +2310,6 @@ impl<T: Entity> ModelHandle<T> {
|
||||
cx.update_model(self, update)
|
||||
}
|
||||
|
||||
pub fn next_notification(&self, cx: &TestAppContext) -> impl Future<Output = ()> {
|
||||
let (tx, mut rx) = oneshot::channel();
|
||||
let mut tx = Some(tx);
|
||||
|
||||
let mut cx = cx.cx.borrow_mut();
|
||||
self.update(&mut *cx, |_, cx| {
|
||||
cx.observe(self, move |_, _, _| {
|
||||
if let Some(mut tx) = tx.take() {
|
||||
tx.blocking_send(()).ok();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
async move {
|
||||
rx.recv().await;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn condition(
|
||||
&self,
|
||||
cx: &TestAppContext,
|
||||
|
||||
+10
-4
@@ -122,9 +122,14 @@ impl Deterministic {
|
||||
smol::pin!(future);
|
||||
|
||||
let unparker = self.parker.lock().unparker();
|
||||
let waker = waker_fn(move || {
|
||||
unparker.unpark();
|
||||
});
|
||||
let woken = Arc::new(AtomicBool::new(false));
|
||||
let waker = {
|
||||
let woken = woken.clone();
|
||||
waker_fn(move || {
|
||||
woken.store(true, SeqCst);
|
||||
unparker.unpark();
|
||||
})
|
||||
};
|
||||
|
||||
let mut cx = Context::from_waker(&waker);
|
||||
let mut trace = Trace::default();
|
||||
@@ -166,10 +171,11 @@ impl Deterministic {
|
||||
&& state.scheduled_from_background.is_empty()
|
||||
&& state.spawned_from_foreground.is_empty()
|
||||
{
|
||||
if state.forbid_parking {
|
||||
if state.forbid_parking && !woken.load(SeqCst) {
|
||||
panic!("deterministic executor parked after a call to forbid_parking");
|
||||
}
|
||||
drop(state);
|
||||
woken.store(false, SeqCst);
|
||||
self.parker.lock().park();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user