Commit 13f2353
committed
Fix flaky runWithRateLimit test by using fake timers
The 'throttles the task when the cache is populated recently' test was
flaky because it used real time with a 1-second timeout window. Under CI
load, the time between filling the rate limit cache and checking it could
exceed 1 second, causing the old occurrences to be swept out and the
rate limit to no longer be exceeded.
Fix by using vi.useFakeTimers() to freeze time during the test, matching
the pattern already used by the 'cache is populated but outdated' test
in the same describe block. The existing afterEach hook already calls
vi.useRealTimers() for cleanup.
Also applied the same fix to the 'rate limit isn't used up' test to
prevent the same class of flake.1 parent 330e89c commit 13f2353
1 file changed
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
474 | 474 | | |
475 | 475 | | |
476 | 476 | | |
| 477 | + | |
477 | 478 | | |
478 | 479 | | |
479 | 480 | | |
| |||
511 | 512 | | |
512 | 513 | | |
513 | 514 | | |
| 515 | + | |
514 | 516 | | |
515 | 517 | | |
516 | 518 | | |
| |||
0 commit comments