From a327d9295a57b4738438b3e8e0f801799cc963dd Mon Sep 17 00:00:00 2001 From: Nikolaus Schuetz Date: Thu, 13 Aug 2026 02:22:40 -0400 Subject: [PATCH] indexheader: replace fixed sleep with require.Eventually in reader pool idle test TestReaderPool_ShouldCloseIdleLazyReaders slept a fixed idleTimeout*2 (2s) before asserting the pool's background reaper had unloaded the idle reader. The reaper runs every idleTimeout/10 and unloads once a reader has been idle for idleTimeout, so on a loaded runner the fixed sleep can race the reaper and is dead time otherwise. Poll for the unload with require.Eventually instead: deterministic and faster. Signed-off-by: Nikolaus Schuetz --- pkg/block/indexheader/reader_pool_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/block/indexheader/reader_pool_test.go b/pkg/block/indexheader/reader_pool_test.go index 2b41bab21bd..89c62786808 100644 --- a/pkg/block/indexheader/reader_pool_test.go +++ b/pkg/block/indexheader/reader_pool_test.go @@ -115,8 +115,11 @@ func TestReaderPool_ShouldCloseIdleLazyReaders(t *testing.T) { testutil.Equals(t, float64(1), promtestutil.ToFloat64(metrics.lazyReader.loadCount)) testutil.Equals(t, float64(0), promtestutil.ToFloat64(metrics.lazyReader.unloadCount)) - // Wait enough time before checking it. - time.Sleep(idleTimeout * 2) + // Wait until the pool's background reaper (which runs every idleTimeout/10) + // has closed the idle reader, rather than sleeping for a fixed duration. + require.Eventually(t, func() bool { + return promtestutil.ToFloat64(metrics.lazyReader.unloadCount) == 1 + }, 5*idleTimeout, idleTimeout/20) // We expect the reader has been closed, but not released from the pool. testutil.Assert(t, pool.isTracking(r.(*LazyBinaryReader)))