From 82e9aa69aa82088302af15be2e1cd7a8d32dfde4 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 6 Mar 2026 11:24:36 +0000 Subject: [PATCH] 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. --- vfs/vfscache/downloaders/downloaders_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vfs/vfscache/downloaders/downloaders_test.go b/vfs/vfscache/downloaders/downloaders_test.go index 8d82c3f99..ea12c65ae 100644 --- a/vfs/vfscache/downloaders/downloaders_test.go +++ b/vfs/vfscache/downloaders/downloaders_test.go @@ -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") }) }