CI: recovery tests retry a load a lock race refused (#1957)

discovery_reclaims_a_crashed_first_write_but_keeps_valid_records failed in
a full workspace run: load() found the record locked for a moment by a
process another test was starting (the race #1939 handled for scan()).
The three tests that reopen a store and load now retry for up to a second.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brandon Thomas
2026-10-14 23:52:28 -04:00
committed by GitHub
co-authored by Claude Opus 5.5
parent e5d9b3e7cf
commit fbbf9c04eb
+16 -3
View File
@@ -572,6 +572,19 @@ mod tests {
}
panic!("the scan never reported the unreadable record");
}
/// `store.load(id)`, tried again for up to a second while the record can't be locked: a process
/// another test is starting holds the lock for a moment (see [`reopen_reporting_unreadable`]).
fn load_retrying(store: &mut Store, id: &str) -> Snapshot {
let mut last = String::new();
for _ in 0..50 {
match store.load(id) {
Ok(snapshot) => return snapshot,
Err(e) => last = e,
}
std::thread::sleep(std::time::Duration::from_millis(20));
}
panic!("the record never loaded: {last}");
}
fn snapshot(id: &str, text: &str) -> Snapshot {
Snapshot {
version: 1,
@@ -656,7 +669,7 @@ mod tests {
fs::write(second, b"{truncated").unwrap();
drop(store);
let mut reopened = reopen_reporting_unreadable(&t.0);
assert_eq!(reopened.load(&id).unwrap().document.plain_text(StoryRef::Body), "First valid copy");
assert_eq!(load_retrying(&mut reopened, &id).document.plain_text(StoryRef::Body), "First valid copy");
// Never reuse the corrupt generation's name or prune the valid fallback.
reopened.save(snapshot(&id, "Third valid copy")).unwrap();
assert_eq!(fs::read(first).unwrap(), bytes);
@@ -697,7 +710,7 @@ mod tests {
assert_eq!(fs::read(first).unwrap(), bytes);
drop(store);
let mut reopened = reopen_reporting_unreadable(&t.0);
assert_eq!(reopened.load(&id).unwrap().document.plain_text(StoryRef::Body), "Last valid copy");
assert_eq!(load_retrying(&mut reopened, &id).document.plain_text(StoryRef::Body), "Last valid copy");
}
#[test]
@@ -724,7 +737,7 @@ mod tests {
let mut reopened = Store::new(t.0.clone()).unwrap();
reopened.scan().unwrap();
assert!(!dir.exists());
assert_eq!(reopened.load(&id).unwrap().document.plain_text(StoryRef::Body), "Valid synthetic draft");
assert_eq!(load_retrying(&mut reopened, &id).document.plain_text(StoryRef::Body), "Valid synthetic draft");
}
#[test]