From c57be80318019686b6a466ef50c7e1bd3ac62932 Mon Sep 17 00:00:00 2001 From: Daniel Sabsay Date: Fri, 24 Jan 2025 16:01:12 -0800 Subject: [PATCH] Fix flaky test: wait until indexes are updated Indexes are updates after the loadAttempts counter is incremented. This means the test can fail if the test goroutine continues before the index update method completes. Signed-off-by: Daniel Sabsay --- pkg/storage/tsdb/bucketindex/loader_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/storage/tsdb/bucketindex/loader_test.go b/pkg/storage/tsdb/bucketindex/loader_test.go index 5bc87d1d27f..a148140ec08 100644 --- a/pkg/storage/tsdb/bucketindex/loader_test.go +++ b/pkg/storage/tsdb/bucketindex/loader_test.go @@ -473,7 +473,8 @@ func TestLoader_ShouldCacheIndexNotFoundOnBackgroundUpdates(t *testing.T) { // Wait until the next index load attempt occurs. prevLoads := testutil.ToFloat64(loader.loadAttempts) test.Poll(t, 3*time.Second, true, func() interface{} { - return testutil.ToFloat64(loader.loadAttempts) > prevLoads + // loadAttempts is incremented before the indexes are updated so we also check countLoadedIndexesMetric() + return testutil.ToFloat64(loader.loadAttempts) > prevLoads && loader.countLoadedIndexesMetric() == 0 }) // We expect the bucket index is not considered loaded because of the error.