diff --git a/crates/ui-egui/src/apply_off_thread_tests.rs b/crates/ui-egui/src/apply_off_thread_tests.rs index 0cd4c134b..c261fe077 100644 --- a/crates/ui-egui/src/apply_off_thread_tests.rs +++ b/crates/ui-egui/src/apply_off_thread_tests.rs @@ -43,15 +43,12 @@ fn until_applied(h: &mut Harness) { fn ok_computes_off_the_window_thread_saying_so_then_applies() { let mut h = square_on_a_block(); h.app.apply_off_thread = Some(Duration::ZERO); + // The evaluation is held until the dialog has been seen saying so (it is in the cache all + // the same), so no frame can apply it before the checks below. + let (finish, gate) = std::sync::mpsc::channel(); + h.app.apply_gate = Some(std::sync::Arc::new(std::sync::Mutex::new(gate))); h.step(&json!({"key": "Enter"})).unwrap(); assert!(h.app.applying.is_some() && h.app.dialog.is_some(), "computing, the dialog open"); - // The evaluation may be in by the next frame: it is held until the dialog has been seen - // saying so (the evaluation itself is in the cache all the same). - let (finish, done) = std::sync::mpsc::channel(); - if let Some(job) = h.app.applying.as_mut() { - let _ = job.done.recv(); - job.done = done; - } h.frames(1); assert!(h.widget("Computing… 0 s").is_some(), "the dialog says it computes"); // Enter again does not start it twice. diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index aeaa2115d..5e874f3de 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -451,10 +451,16 @@ fn begin_applying(app: &SolveApp, d: &Dialog) -> Option { let scratch = app.session.scratch(); let (tx, rx) = std::sync::mpsc::channel(); let computed = cmds.clone(); + #[cfg(test)] + let gate = app.apply_gate.clone(); std::thread::Builder::new() .name("apply".into()) .spawn(move || { let _ = scratch.preview(&computed); + #[cfg(test)] + if let Some(gate) = gate { + let _ = gate.lock().unwrap().recv(); + } let _ = tx.send(()); }) .ok()?; diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 1b3b9a446..8e68c929b 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -384,6 +384,9 @@ pub struct SolveApp { /// How long OK waits for a feature before computing it off the window thread, saying so; /// `None`: it waits as long as it takes (headless use, tests). The desktop app sets it. pub apply_off_thread: Option, + /// Tests: the off-thread evaluation waits for this before it reports done. + #[cfg(test)] + pub(crate) apply_gate: Option>>>, /// The last command started interactively (id, label), for Repeat. pub last_command: Option<(String, String)>, /// Esc was already acted on this frame (by the shortcuts), so later handlers skip it. @@ -512,6 +515,8 @@ impl SolveApp { deferred_queue: Vec::new(), delete_check: None, apply_off_thread: None, + #[cfg(test)] + apply_gate: None, last_command: None, esc_handled: false, status: None,