diff --git a/internal/api/age_retention_test.go b/internal/api/age_retention_test.go index 29b06450..7c968155 100644 --- a/internal/api/age_retention_test.go +++ b/internal/api/age_retention_test.go @@ -72,7 +72,13 @@ func TestSettings_AutoDeleteOldSnapshots_SweepsWhenSwitchedOn(t *testing.T) { if _, err := ts.daemon.Store.GetSnapshot(newest[0].ID); err != nil { t.Errorf("the branch's newest snapshot was deleted") } - if _, err := os.Stat(filepath.Join(backups, "snap_old_auto.zip")); err == nil { + // Waited for, not looked at once: the sweep deletes the rows first and + // the archives after its last row (PruneOlderThan), so under load the row + // was found gone while the archive was still there. + if !waitFor(10*time.Second, func() bool { + _, err := os.Stat(filepath.Join(backups, "snap_old_auto.zip")) + return os.IsNotExist(err) + }) { t.Errorf("the deleted snapshot's archive is still on disk") } } diff --git a/internal/api/savefiles_edge_test.go b/internal/api/savefiles_edge_test.go index 0e62616e..8fe89943 100644 --- a/internal/api/savefiles_edge_test.go +++ b/internal/api/savefiles_edge_test.go @@ -8,6 +8,7 @@ import ( "runtime" "strconv" "testing" + "time" ) // A location whose folder is gone must not blank the listing. Somebody who @@ -33,9 +34,13 @@ func TestSaveFiles_MissingLocationDoesNotBreakTheListing(t *testing.T) { } ts.do(t, http.MethodPost, "/api/games/gone-loc/roots", map[string]string{"name": "config", "path": cfg}) - // The drive goes away. - if err := os.RemoveAll(cfg); err != nil { - t.Fatal(err) + // The drive goes away. Retried briefly: adding the location started its + // watch and first read in the background (RewatchGame), and on Windows a + // folder being read cannot be removed ("used by another process") — this + // test racing the app, as testutil.RemoveTree says of the same race. + var rmErr error + if !waitFor(5*time.Second, func() bool { rmErr = os.RemoveAll(cfg); return rmErr == nil }) { + t.Fatal(rmErr) } list := getSaveFiles(t, ts, "gone-loc", nil)