-
Notifications
You must be signed in to change notification settings - Fork 198
Flaky test: TestMemoryStorage_CleanupLoop/cleanup_runs_periodically #4096
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't workinggoPull requests that update go codePull requests that update go code
Description
Summary
TestMemoryStorage_CleanupLoop/cleanup_runs_periodically in pkg/authserver/storage/memory_test.go is flaky due to timing sensitivity.
Details
The test creates a storage with a 50ms cleanup interval, inserts an expired auth code, then sleeps 100ms and asserts the code was cleaned up:
storage := NewMemoryStorage(WithCleanupInterval(50 * time.Millisecond))
// ... insert expired session ...
time.Sleep(100 * time.Millisecond)
assert.Equal(t, 0, storage.Stats().AuthCodes) // fails intermittentlyUnder load (e.g., -race with many parallel tests), the cleanup goroutine may not have fired within the 100ms sleep window, causing the assertion to fail with expected: 0, actual: 1.
Location: pkg/authserver/storage/memory_test.go:716-729
Suggested fix
Replace the fixed sleep with a polling loop using require.Eventually or assert.Eventually:
require.Eventually(t, func() bool {
return storage.Stats().AuthCodes == 0
}, 2*time.Second, 25*time.Millisecond, "expired auth code should be cleaned up")This is deterministic regardless of system load while still testing the same cleanup behavior.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinggoPull requests that update go codePull requests that update go code