vfs/vfscache/downloaders: fix flaky TestDownloaders/EnsureDownloader

The test was racy: it asserted the async download hadn't completed yet
(which could fail on fast machines) then slept for a fixed 1 second
(which could be too short on slow CI runners, especially macOS).

Replace with assert.Eventually which polls until the download
completes, with a generous timeout.
This commit is contained in:
Nick Craig-Wood
2026-03-06 11:24:36 +00:00
parent c172172c2e
commit 82e9aa69aa

View File

@@ -122,9 +122,9 @@ func TestDownloaders(t *testing.T) {
r := ranges.Range{Pos: 40 * 1024 * 1024, Size: 250}
err := dls.EnsureDownloader(r)
require.NoError(t, err)
// FIXME racy test
assert.False(t, item.HasRange(r))
time.Sleep(time.Second)
assert.True(t, item.HasRange(r))
// The download happens asynchronously, so poll until it completes
assert.Eventually(t, func() bool {
return item.HasRange(r)
}, 10*time.Second, 100*time.Millisecond, "timed out waiting for download to complete")
})
}