SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Make the off-thread OK test deterministic (#3622)
bherbruckdb75b7bface3
diff --git a/crates/ui-egui/src/apply_off_thread_tests.rs b/crates/ui-egui/src/apply_off_thread_tests.rsindex 0cd4c134bd..c261fe077c 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.rsindex aeaa2115dc..5e874f3de0 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<Applying> {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.rsindex 1b3b9a4467..8e68c929ba 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<std::time::Duration>,+ /// Tests: the off-thread evaluation waits for this before it reports done.+ #[cfg(test)]+ pub(crate) apply_gate: Option<std::sync::Arc<std::sync::Mutex<std::sync::mpsc::Receiver<()>>>>,/// 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,