Skip to content

Fix flaky TestMemoryStorage_CleanupLoop timing test#4098

Merged
rdimitrov merged 1 commit intomainfrom
fix/flaky-cleanup-loop-test
Mar 11, 2026
Merged

Fix flaky TestMemoryStorage_CleanupLoop timing test#4098
rdimitrov merged 1 commit intomainfrom
fix/flaky-cleanup-loop-test

Conversation

@JAORMX
Copy link
Copy Markdown
Collaborator

@JAORMX JAORMX commented Mar 11, 2026

Summary

  • TestMemoryStorage_CleanupLoop/cleanup_runs_periodically was flaky because it used a fixed 100ms time.Sleep to wait for a 50ms cleanup goroutine. Under load (especially with -race and many parallel tests), the goroutine wouldn't always fire within that window, causing intermittent expected: 0, actual: 1 failures.
  • Replace the sleep with require.Eventually polling (25ms interval, 2s timeout), making the test deterministic regardless of system load. Also switch context.Background() to t.Context() per project conventions.

Fixes #4096

Type of change

  • Bug fix

Test plan

  • Unit tests (task test)
  • Ran the specific test 5 times with -race -count=5 — all passed consistently.
  • Ran the full pkg/authserver/storage/ test suite with -race — all passed.

Generated with Claude Code

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>
@github-actions github-actions bot added the size/XS Extra small PR: < 100 lines changed label Mar 11, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.60%. Comparing base (8e92eba) to head (46da0cc).
⚠️ Report is 3 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rdimitrov rdimitrov merged commit c94afc2 into main Mar 11, 2026
42 checks passed
@rdimitrov rdimitrov deleted the fix/flaky-cleanup-loop-test branch March 11, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Extra small PR: < 100 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky test: TestMemoryStorage_CleanupLoop/cleanup_runs_periodically

2 participants