Repository navigation
fix(tests): stop two unit tests from measuring timer timing - #1870
Conversation
…swered ones server/rpc-diagnostics.test.ts "logs a timeout once, then one recovery" failed in check fast: expected 4 requests, received 3. Its two stalled calls had a 30 ms timeout, and on a busy event loop that timeout can fire before the request is written, or the daemon reads the bytes only after the test moved on; how many stalled requests arrive is not the test's to fix. Stalled calls now carry stall: true, which the fixture counts apart and never answers. The test asserts exactly the two answered requests (one per call, none sent again) and at most two stalled ones. The first stalled call gets 500 ms, so the timeout it logs is the response's. Reproduced on demand by blocking the event loop 80 ms after starting the second stalled call: main fails with "Expected: 4, Received: 3", this passes. 200 runs, 8 at a time: 0 failures.
server/collector.test.ts "backs off while a subscription keeps closing before it starts, and resets once one starts" asserted wall-clock time (a reconnect within 100 ms of Date.now()), which a busy PC's late timers overran: 2 of 10 runs under contract-test load. A 120 ms event loop stall after the drop reproduces it on demand (121 < 100 fails). It now runs on jest's fake timers and asserts each delay exactly: no reopen one ms before 20, 40, 80, 160 and the 160 ms cap, one at it, and 20 again once a connection started. Tripling the backoff or not resetting it fails the test.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 10 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
CodeRabbit's review was rate-limited ("Review limit reached"), so no CodeRabbit review ran on this PR. The reviews below stand in for it. omo-native-code-reviewer: APPROVE, no blockers. Its two optional notes are applied: the collector is started inside the |
|
Merge pass review-work report. Overall: PASSED. This PR changes tests only, so under the maintainer's token rule it merges on the code review, the merge pass's own check and CI, without the gate reviewer.
What was checked
Follow-ups (MINOR)
All required checks are green, and no review thread is open. CodeRabbit did not review this PR (rate-limited or skipped). The reviews above stand in for it. |
…1900) ## What it does `server/collector.test.ts` waited on fixed sleeps (`await tick(20)`, `tick(70)`, ... 61 of them by `scripts/fixed-sleeps.ts`'s count) for the collector's debounce, snapshot retry, replay settle and reconnect timers (5 ms in `fakeHerdr`). On a loaded PC a test could read the handler log before those timers had run (1 failure in 200 runs seen in the flaky-tests lane; it failed again on CI today, in #1895's Fast checks: "tells what the snapshot that closes the subscription already shows" read `[]` where it expected `w1:p1:unknown (was working)`). #1870 moved the backoff test to fake timers and left the rest to this issue. Now the whole `startStatusCollector recovery` describe runs on bun's fake timers, so every timer fires at its own moment of the test's clock however busy the PC is: - `beforeEach`/`afterEach` turn fake timers on and off for the describe. - `elapse(ms)` moves the clock a millisecond at a time and, after each step, lets the promise chains that step started settle (`setImmediate`, which bun does not fake). `elapse()` runs what is due now, as a 0 ms timeout did. Each `tick()`/`tick(N)` became `elapse()`/`elapse(N)` with the same amount, so every test reads the log at the same point of the collector's timeline as before. - The one recovery test that polled with `until()` (real sleeps and `Date.now()`, which a frozen clock never moves) steps the clock and asserts exact values. - The first describe's only remaining wait is the marked `// fixed wait:` that proves no refresh comes; `scripts/fixed-sleeps.json` drops the collector entry (61 to 0). No production code changes. ## Why it can no longer flake under load What a test reads is decided by how far it moved the fake clock, not by how long the PC took to run real timers: a debounce or replay settle cannot be late, because it only runs when the test advances to it, and the test waits for what it started to settle before it reads. ## How it was verified - `bun test server/collector.test.ts`: 57 pass, 0 fail, in 3.5 s. - 200 runs of the file, 8 at a time, at a load average of 150 to 162 on 32 cores (other lanes' checks running): 200 of 200 passed, 0 failures. - The fake clock still catches timing regressions in `server/collector.ts`: a reconnect delay 100 ms late fails 3 tests; a replay settle 100 ms late fails 9. - `scripts/conventions.test.ts` (fixed-sleep ratchet) passes. - Review: `omo-native-code-reviewer` APPROVE. It ran the same collector mutations against the old and the new test file and found each fails the same tests with both (replay settle +100 ms: 9; reconnect +100 ms: 3; snapshot retry +1000 ms: 1). Of its three LOW notes, the reopened-subscription check now also asserts the subscription exists; the marked fixed wait that proves no refresh comes and #1870's own (now redundant) fake-timer calls are left as they are. - `bun run check fast` (through `dori heavy`) on this commit: typecheck, build and unit tests ok (6396 pass, 0 fail, 13 skip). Fixes #1867 Co-authored-by: mp <mp@local>
Two unit tests that measured timer timing, both seen failing in
bun run check faston a loaded PC. Test-only.1.
server/rpc-diagnostics.test.ts: "logs a timeout once, then one recovery"Failed with
Expected: 4, Received: 3requests. Its two stalled calls had a 30 ms timeout; on a busy event loop that timeout can fire before the request is written, or the daemon reads the bytes only after the test moved on, so how many stalled requests arrive is not the test's to fix.stall: true; the fixture counts them apart and never answers them. The test asserts exactly the two answered requests (one per call, none sent again) and one or two stalled ones.phase: "response").Expected: 4, Received: 3; this version passes. 200 runs, 8 at a time: 0 failures.2.
server/collector.test.ts: "backs off while a subscription keeps closing before it starts, and resets once one starts"Asserted wall-clock time (a reconnect within 100 ms of
Date.now()), which late timers overran: 2 of 10 runs under contract-test load. Reproduced on demand: a 120 ms event-loop stall after the drop gives 121 ms against the 100 ms limit.scripts/fixed-sleeps.json: the file's baseline drops 62 → 61, as the ratchet asks.The rest of
collector.test.tsstill waits on fixedtick()sleeps; one other case failed once in 200 runs under load. That is filed as #1867 rather than converted here.Verification
bun run check fast: passed (6393 pass, 0 fail) on current main.try, assert at least one stalled request arrived — are applied). Test-only, so no Codex review.Part of the flaky-tests lane (
check fastreliability).