Fix flaky TestMemoryStorage_CleanupLoop timing test#4098
Merged
Conversation
The cleanup_runs_periodically subtest used a fixed 100ms sleep to wait for a 50ms cleanup goroutine, which was unreliable under load (especially with -race). Replace with require.Eventually polling to make the test deterministic. Also switch context.Background() to t.Context() per project conventions. Closes #4096 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4098 +/- ##
==========================================
- Coverage 68.62% 68.60% -0.03%
==========================================
Files 448 448
Lines 45776 45779 +3
==========================================
- Hits 31415 31406 -9
- Misses 11940 11948 +8
- Partials 2421 2425 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
rdimitrov
approved these changes
Mar 11, 2026
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.
Summary
TestMemoryStorage_CleanupLoop/cleanup_runs_periodicallywas flaky because it used a fixed 100mstime.Sleepto wait for a 50ms cleanup goroutine. Under load (especially with-raceand many parallel tests), the goroutine wouldn't always fire within that window, causing intermittentexpected: 0, actual: 1failures.require.Eventuallypolling (25ms interval, 2s timeout), making the test deterministic regardless of system load. Also switchcontext.Background()tot.Context()per project conventions.Fixes #4096
Type of change
Test plan
task test)-race -count=5— all passed consistently.pkg/authserver/storage/test suite with-race— all passed.Generated with Claude Code