From 9c643e302e320a632a3fa578d152624c60e6dcfe Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 20:41:56 -0800 Subject: [PATCH] Tests: canvas tests that compare renders keep the proof view while they run The proof view is process-wide, and the Proof Setup dialog tests turn Proof Colors on while other tests run. A change between two renders of a canvas test made the frames differ, and a_drag_on_the_canvas_draws_raster_effects_at_a_lower_resolution failed in full runs of the crate's tests. The Proof Setup tests' lock is now a read-write lock, and keeping_color_settings holds it for reading. --- crates/ui-egui/src/canvas/tests.rs | 2 ++ crates/ui-egui/src/dialogs/proof_setup.rs | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) 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();