Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Tests: autosave retry waits for the finished write, not a mid-write listing

Brandon Thomas7250e6e29a92
diff --git a/apps/photocraft/src/services.rs b/apps/photocraft/src/services.rs
index d4a3869f3..e6c882d19 100644
--- a/apps/photocraft/src/services.rs
+++ b/apps/photocraft/src/services.rs
@@ -907,6 +907,7 @@ mod tests {
let mut app = launch(&recovery);
new_doc(&mut app, "#ff0000");
let revision = app.session.active().unwrap().revision;
+ assert_ne!(revision, 0, "a sidecar-less bundle lists as revision 0");
autosave(&mut app, &ctx);
let mut failed = false;
@@ -927,12 +928,16 @@ mod tests {
std::fs::remove_file(&recovery).unwrap();
std::fs::create_dir(&recovery).unwrap();
autosave(&mut app, &ctx);
+ // The worker commits the bundle's manifest before it publishes the sidecar, and
+ // `list_recovery` lists a committed sidecar-less bundle (revision 0) on its own, so
+ // the first non-empty listing can come from the middle of the write. Wait for the write
+ // to finish: the entry then carries the sidecar's revision.
let mut recovered = Vec::new();
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(30);
while std::time::Instant::now() < deadline {
prefs_ui::tick(&mut app, &ctx);
recovered = list_recovery(&recovery);
- if !recovered.is_empty() {
+ if recovered.iter().any(|e| e.info.revision == revision) {
break;
}
std::thread::sleep(std::time::Duration::from_millis(10));