Repository navigation
fix(tests): run the collector's recovery tests on the test's clock - #1900
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Fake-timer helpers and setup server/collector.test.ts |
Adds helpers to settle pending promises and advance fake timers in controlled increments. Recovery tests enable fake timers and restore real timers. The lifecycle readiness test uses promise settling; the debounce test uses Bun.sleep(30). |
Recovery timing scenarios server/collector.test.ts, scripts/fixed-sleeps.json |
Recovery scenarios replace real-time waits with fake-clock advancement while retaining their existing assertions. Removes the fixed-sleep entry for server/collector.test.ts. |
Priority:
Estimated code review effort: 2 (Simple) | ~15 minutes
Change: Other · Severity of issue fixed: Low
Merge Risk: 
Minimal · up to b5ca0
-
The reviewed test-only change has no established merge-blocking risk.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Description check
-
Explanation
The description explains the problem, resulting behavior, scope, rationale, validation results, regression coverage, and linked issue. It uses headings different from the template, but it provides the required Change and Validation information.
Full details: Linked Issues check
-
Explanation
Issue
#1867targets fixed waits inserver/collector.test.ts. The recovery tests now usejest.useFakeTimers()withelapse()and settle promise work after each clock step. The polling recovery case uses deterministic clock advancement and exact assertions. The fixed-sleep registry no longer lists this test file. The remaining markedBun.sleep(30)checks that no refresh occurs and is not used to wait for a collector result.
Full details: Out of Scope Changes check
-
Explanation
The changes stay within issue
#1867. They modify collector test timing helpers, recovery test setup and waits, and the fixed-sleep registry. No production code or unrelated behavior changes are present.
-
-
Finishing Touches: 💡 2
-
📝 Generate docstrings: 💡
-
- Commit to this branch
- Create a new PR
🛠️ Fix failing CI checks: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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 @coderabbitai help to get the list of available commands.
server/collector.test.ts waited on fixed sleeps (tick(20), tick(70), ...) for the collector's debounce, snapshot retry, replay settle and reconnect timers (5 ms in fakeHerdr), so on a loaded PC a test could read the log before those timers had run. The recovery tests now run on bun's fake timers: elapse(ms) moves the clock a millisecond at a time and lets the promise chains each step started settle (setImmediate is not faked), so every timer fires at its own moment of the test's clock however busy the PC is. The one recovery test that polled with until() steps the clock as well. The file's last fixed wait is the marked one that proves no refresh comes, and scripts/fixed-sleeps.json drops its collector entry (61 to 0). Fixes #1867
|
Holding this as a draft for a moment: do not merge this head. Since it was opened, main gained #1865, whose new collector test calls The rebased commit (that test yields with this file's |
01e1aed to
b5ca085
Compare
|
Rebased onto main and marked ready for review. It was a draft only because its old head (01e1aed) broke the typecheck after #1865: main's lifecycle-subscription test calls |
|
Merge pass review-work report. Overall: PASSED. This PR changes tests only. Under the maintainer's token rule it merges on the code review, the merge pass's own check and CI, without the gate reviewer.
Mutants: each of these fails at least one test.
Fake timers
Ratchet: Follow-ups (LOW)
b5ca085 (out of draft, rebased onto main with #1865): the PR also turns the one All required checks are green and no review thread is open. |
What it does
server/collector.test.tswaited on fixed sleeps (await tick(20),tick(70), ... 61 of them byscripts/fixed-sleeps.ts's count) for the collector's debounce, snapshot retry, replay settle and reconnect timers (5 ms infakeHerdr). 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 expectedw1:p1:unknown (was working)). #1870 moved the backoff test to fake timers and left the rest to this issue.Now the whole
startStatusCollector recoverydescribe 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/afterEachturn 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. Eachtick()/tick(N)becameelapse()/elapse(N)with the same amount, so every test reads the log at the same point of the collector's timeline as before.until()(real sleeps andDate.now(), which a frozen clock never moves) steps the clock and asserts exact values.// fixed wait:that proves no refresh comes;scripts/fixed-sleeps.jsondrops 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.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.omo-native-code-reviewerAPPROVE. 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 fix(tests): stop two unit tests from measuring timer timing #1870's own (now redundant) fake-timer calls are left as they are.bun run check fast(throughdori heavy) on this commit: typecheck, build and unit tests ok (6396 pass, 0 fail, 13 skip).Fixes #1867