Repository navigation
fix(tests): wait on install.sh's own events in install-star's tests, not on set times - #1895
Conversation
…not on set times
On a loaded PC scripts/install-star.test.ts failed in three ways:
- atTerminal's type() wrote to script(1)'s stdin with no guard. As script
exits it closes its end of the pipe, and until Bun reaps it a write there
throws EPIPE synchronously; typed from the Ctrl-C test's interval, that was
an unhandled error between tests. type() now drops the keys on EPIPE only.
- Whole runs of install.sh outlasted bun's 5 s default timeout. Each helper
now waits for the installer's own end (output closed and exit), bounded by
RUN_ENDS_WITHIN_MS (45 s), and a run still going then is ended and fails
with what it printed. setDefaultTimeout() is only a backstop above it.
- Elapsed-time checks (< 8, 15 and 20 s) and fs.watch (EMFILE once the PC is
out of inotify instances) failed under load. They are replaced by what the
installer did:
- a bash stand-in passes through to the real bash and records how the
question's read ended, so a test tells an answer read (0) or the end of
input (1) apart from its 20 seconds running out; a raised timeout alone
let a lost answer pass, since both end with no star;
- the stand-in gh leaves its pid, so the tests see a gh that never answers
or ignores TERM was ended by the installer, and a lingering child of gh
still running when the installer had already ended;
- the browser opener's record is polled within a deadline, not watched.
Fixes #1866
|
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 43 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 |
|
Fast checks failed on this run (40105758528) in two files this PR does not touch; both are known timing flakes, not the change:
|
|
Re-ran the failed Fast checks job (run 40105758528, attempt 2): it passed, and every other job passed in the first attempt. The PR is green. |
|
Merge pass review-work report. Overall: PASSED. This PR changes a test 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-up (MEDIUM, accepted for a loaded PC): install.sh gives gh 10 s, but the tests now allow 45 s instead of the old 20 s. A regression that stretched that 10 s toward 30 s would go unnoticed. 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>
What it does
scripts/install-star.test.tsfailed on a loaded PC in three ways (seen inbun run check fastat a load average of about 97 on 32 cores). This makes each test wait on what install.sh itself did, bounded, instead of on set times:atTerminal'stype()wrote to script(1)'s stdin with no guard. As script exits it closes its end of the pipe, and until Bun reaps it a write there throwsEPIPEsynchronously (reproduced: a child that closed its stdin but is not reaped yet makesFileSink.write/flushthrow{code: "EPIPE", errno: -32, syscall: "write"}). Typed from the Ctrl-C test's interval, that was an unhandled error outside any test.type()now drops the keys onEPIPEonly; any other error still throws.RUN_ENDS_WITHIN_MS(45 s); a run still going then is ended and the test fails with what it printed.setDefaultTimeout()stays above that only as a backstop. The per-test 30 s/60 s timeouts are gone.fs.watch.< 8 s,< 15 sand< 20 schecks failed under load, andfs.watchfailed withEMFILEonce the PC was out of inotify instances. They are replaced by evidence of what the installer did:bashstand-in passes through to the real bash and records how the question'sread -r -t 20ended, so a test tells an answer read (0) or the end of input (1) apart from its 20 seconds running out (over 128). Without this, a lost answer and a timed-out question both end with no star, so a longer timeout alone would let a broken installer pass;ghleaves its pid: a gh that never answers, or ignores TERM, is gone once the installer ended (it sleeps 60 s otherwise); a lingering child of gh is still running when the installer has already ended;No production code changes.
Why it can no longer flake under load
No assertion depends on how fast the PC is any more, except the 20 s question test, where time is the behaviour under test and its bounds are wide. Every wait is for an event of the installer's (its output, its exit, the question on the terminal, a file the stand-ins write), bounded so a hung run fails with its output instead of hanging, and a write into an installer that already ended is not an error.
How it was verified
EMFILE). This approach: 24 of 24 runs passed 39/39 at a load average of 86 to 154, and the final revision (with the Ctrl-C assertion) 16 of 16 runs passed 40/40 at a load average of 50 to 119.bun run typecheckandscripts/conventions.test.tspass.omo-native-code-reviewer. On the first revision (EPIPE guard plus 30 s timeouts) it found that a longer timeout lets a lost answer pass; on the second, the same gap in the Ctrl-C test. Both are fixed: every answered test asserts how the question's read ended, and the Ctrl-C test fails (read status 142) with an install.sh that ignores Ctrl-C. Its LOW notes (a gh deadline of 30 s instead of 10 would still pass, which follows dropping wall-clock checks; the stand-in matching the read's text, now guarded by a test that install.sh still asks with it) are addressed or accepted.bun run check fast(throughdori heavy) on this commit: typecheck, build and unit tests ok (6397 pass, 0 fail, 13 skip).Fixes #1866