diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index d5244aa234..1922842acd 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -3059,7 +3059,9 @@ fn the_art_renders_within_the_largest_texture_side() { /// Run a test that compares two renders with the color settings that are active when it starts. /// A test on another thread can change the process's active settings; this thread keeps its own. +/// The proof view is process-wide, so the tests that change it wait until this one ends. fn keeping_color_settings(test: fn()) { + let _view = crate::dialogs::proof_setup::tests::keeping_the_proof_view(); vectorcraft_color::cms::with_active(vectorcraft_color::cms::active(), test); } diff --git a/crates/ui-egui/src/dialogs/proof_setup.rs b/crates/ui-egui/src/dialogs/proof_setup.rs index 44350ac659..735fafaaef 100644 --- a/crates/ui-egui/src/dialogs/proof_setup.rs +++ b/crates/ui-egui/src/dialogs/proof_setup.rs @@ -492,18 +492,19 @@ pub fn saved_items() -> Vec { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use vectorcraft_engine::Session; /// Proof views are process-wide: these tests take turns, and each leaves the default view. - static VIEW: std::sync::Mutex<()> = std::sync::Mutex::new(()); + /// Tests that compare renders hold it for reading ([`keeping_the_proof_view`]). + static VIEW: std::sync::RwLock<()> = std::sync::RwLock::new(()); - struct DefaultView<'a>(#[allow(dead_code)] std::sync::MutexGuard<'a, ()>); + struct DefaultView<'a>(#[allow(dead_code)] std::sync::RwLockWriteGuard<'a, ()>); impl DefaultView<'_> { fn new() -> Self { - let g = VIEW.lock().unwrap_or_else(|e| e.into_inner()); + let g = VIEW.write().unwrap_or_else(|e| e.into_inner()); proof::set_view(Default::default()); DefaultView(g) } @@ -515,6 +516,11 @@ mod tests { } } + /// Keeps the proof view as it is while the guard lives: the tests here wait to change it. + pub(crate) fn keeping_the_proof_view() -> std::sync::RwLockReadGuard<'static, ()> { + VIEW.read().unwrap_or_else(|e| e.into_inner()) + } + fn frame(app: &mut VectorcraftApp, ctx: &egui::Context) { let mut out = ctx.run_ui(egui::RawInput::default(), |ui| super::super::show(app, ui.ctx())); out.textures_delta.clear();