From 8a743367131b2948e8cb71e67ef16c0ef46969e0 Mon Sep 17 00:00:00 2001 From: kaltenbrunnermarkus <153593707+kaltenbrunnermarkus@users.noreply.github.com> Date: Wed, 4 Nov 2026 05:22:20 +0000 Subject: [PATCH] Tests: the autosave recovery test no longer fails at random on a busy machine (#11815) * claim: Recovery: the save test waits for the autosave worker before it checks * Recovery: the save test waits for the autosave worker before it checks saving_drops_the_entry_and_a_clean_close_leaves_nothing marked the session saved right after the tick that started an autosave. Under load the worker was still writing, so the next tick found the write running, took nothing up and dropped nothing; the file landed afterwards and the check that it is gone failed (seen in CI on #9021). The test now ticks, bounded, until the autosave has caught up (Autosaver::caught_up), as the app's own frames would, before it marks the session saved. A small helper in the test module does this. The app's behaviour is unchanged. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- crates/engine/src/recovery.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/engine/src/recovery.rs b/crates/engine/src/recovery.rs index e05c079fb..7aefc4c15 100644 --- a/crates/engine/src/recovery.rs +++ b/crates/engine/src/recovery.rs @@ -466,6 +466,19 @@ mod tests { d } + /// Ticks (bounded) until the autosave a tick started has been written and taken up, as the + /// app's own frames would. A tick right after the one that started a write can find it still + /// running under load and take nothing up, so a test that then changes the session (marking + /// it saved) and checks the files would race the worker. + fn tick_until_caught_up(a: &mut Autosaver, s: &Session) { + let began = Instant::now(); + while !a.caught_up(s) { + assert!(began.elapsed() < Duration::from_secs(30), "the autosave never caught up"); + std::thread::sleep(Duration::from_millis(1)); + a.tick(s, false).unwrap(); + } + } + #[test] fn autosave_only_unsaved_changes_and_recover_after_a_crash() { let d = dir("crash"); @@ -590,6 +603,7 @@ mod tests { let mut a = Autosaver::new(&d, Duration::ZERO).unwrap(); s.execute("solid.box", &json!({"length": 10, "width": 10, "height": 10})).unwrap(); assert!(a.tick(&s, false).unwrap()); + tick_until_caught_up(&mut a, &s); s.mark_saved(); a.tick(&s, false).unwrap(); assert!(!file(&d, &a.id, solidcraft_io::DESIGN_EXT).exists());