Commit 0559e64
committed
test(keyviz): replace fixed sleep with eventually in TestHotKeysAggregatorRaceFree
CI flake observed on Actions run 26765510693 (PR #902 branch but
unrelated to that PR -- the keyviz/ change is on main and surfaced
there by chance):
--- FAIL: TestHotKeysAggregatorRaceFree (0.11s)
hot_keys_test.go:356: Expected value not to be nil.
Root cause: same wall-clock racing pattern as the SQS-throttle and
Redis-TTL flake series (PR #891, #903). The test:
1. Launches an aggregator goroutine (Step=5ms tick).
2. Spawns 8 workers each calling Observe 500 times.
3. Sleeps 50ms.
4. Asserts both per-route snapshots are non-nil.
The aggregator publishes a snapshot only on a tick (or on ctx-done
drain). Under -race on a slow CI runner, the Run goroutine itself
can be slow to schedule -- the 50ms wait may not contain a single
actual tick worth of scheduler time, so hotKeysSnap stays at its
initial nil atomic.Pointer load and the assertion fires.
Fix: require.Eventually with a 3-second budget + 5ms poll cadence,
asserting both snapshots non-nil. The test still pins the load-bearing
property (snapshot reads are lock-free; the atomic.Pointer.Load works
without contention with the publisher); only the WAIT mechanism
changes from "sleep blindly and hope" to "poll until ready or fail".
Total time bound is at most 3 s on a slow runner, ~5-50 ms in the
common case.
Validation:
go test ./keyviz/ -run TestHotKeysAggregatorRaceFree -race -count=5 -> ok 1.1s
gofmt + golangci-lint -> 0 issues
Caller audit: test-only file; no Go callers affected. The flake
linage matches the structural fixes in PR #891/#903 (replace
fixed-time-window sleep with require.Eventually); future flakes
in this category should follow the same pattern.1 parent c40e0c9 commit 0559e64
1 file changed
Lines changed: 13 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
348 | 348 | | |
349 | 349 | | |
350 | 350 | | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
358 | 364 | | |
359 | 365 | | |
360 | 366 | | |
0 commit comments