indexheader: replace fixed sleep with require.Eventually in reader pool idle test - #8978
Draft
nikolauspschuetz wants to merge 1 commit into
Draft
Conversation
…ol 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 <nikolauspschuetz@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8978 +/- ##
=======================================
Coverage 64.54% 64.54%
=======================================
Files 289 289
Lines 37359 37359
=======================================
Hits 24115 24115
Misses 11151 11151
Partials 2093 2093 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
TestReaderPool_ShouldCloseIdleLazyReaderswaited for the pool's backgroundreaper to unload an idle reader with a fixed
time.Sleep(idleTimeout * 2)(2s)and then asserted
unloadCount == 1.The reaper goroutine ticks every
idleTimeout/10and unloads a reader once ithas been idle for
idleTimeout, so the unload is an asynchronous event. Thisreplaces the blind sleep with
require.Eventually(testify is already importedin this file), polling
unloadCountuntil it reaches 1 with a generous 5×idleTimeoutcap and a short tick. The surroundingloadCount/isTrackingassertions are unchanged — they are stable at the moment the unload is observed.
Net effect: both a speedup (resolves in ~1s instead of a fixed 2s of dead
time) and a de-flake (a loaded CI runner where the reaper tick slips past
the fixed 2s window no longer fails a hard timing assertion). Test-only, no
production code touched.
Verification
Ran the target test with the race detector, repeated to shake out flakiness:
50/50 passes, no data races. Timing comparison (
-count=10, no race, same box):old fixed-sleep 58.4s vs. poll 54.9s — the per-iteration sleep saving shows
through even though block setup dominates each iteration.
gofmtclean.for the record: authored with AI assistance, reviewed and verified by me.