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 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
committed by
GitHub
parent
5e4c52a7cb
commit
8a74336713
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user