Public: anyone can read this; the crew can change it.
test/apps-busy.test.ts runs in under 10 s, every test under 1 s, proving what it proves today #10224
Check · Review · Land · Live done — Landed and live in production.
`test/apps-busy.test.ts` now runs in **3.8 s instead of 19.8 s**. Each test takes 0.29–0.37 s, and all 5 tests still pass with nothing skipped. Both times are from `bun test test/apps-busy.test.ts` on this crew machine. The new time held across five runs, between 3.74 s and 3.92 s.
shipped production is serving it deploy f21b126
test/apps-busy.test.ts now runs in 3.8 s instead of 19.8 s. Each test takes 0.29–0.37 s, and all 5 tests still pass with nothing skipped. Both times are from bun test test/apps-busy.test.ts on this crew machine. The new time held across five runs, between 3.74 s and 3.92 s.
What changed (only test/apps-busy.test.ts):
- One fake clock, one runtime. The runtime already takes a
clockoption, and only the sleep check reads it. The suite now passes a clock set to the real time plus an offset it controls, and counts how many times the check reads it. A helper,sweepAt(ms), moves the clock forward and waits for two checks, so every environment has been judged at that time. The idle window is now one hour and the grace period ten minutes, on that clock. Real waiting never gets near them, so the app sleeps only when a test says so. This also removes the old setup that stopped the runtime and started a second one with a shorter window. - The test app does nothing on a timer.
/workstarts a longsleepchild that/doneends./slowwaits until/answeris called, and/waitingreports how many requests are waiting, so the test knows the request has arrived before moving the clock. This replaces the oldsleep 5,sleep 12, a 2-secondsetTimeout, and twoWINDOW + 700waits. Polling now pauses 5 ms between checks; no wait is longer than 50 ms. - Each test starts with one line saying what it proves. No test was deleted. Some checks got tighter: log checks now look only at lines added during that test, and the request and grace tests also check the busy reason. The idle test also checks that the app is still running just before its window ends.
Each rewritten test still fails without the code it guards. I changed the source, ran the file, then restored the source:
Change to src/apps | Tests that fail | ||
|---|---|---|---|
| The sweep never sleeps an app on time (`now - last < limit \ | \ | true`) | all 5, timed out at 5 s |
busyReason ignores child processes | the child test, the grace test | ||
busyReason ignores open requests | the request test | ||
busyReason ignores open streams | the stream test | ||
The grace period never runs out (overdue = false) | the grace test |
To try it: bun test test/apps-busy.test.ts. bun scripts/gate.ts and bun x tsc --noEmit both pass.
I didn't keep a plan on the issue because the keep_plan tool wasn't available in this session.
🤖 Generated with Claude Code
Test-only change; the 3.8 s vs 19.8 s claim is credible. A shared fake sweep clock replaces every real wait, the second runtime is gone, the test app does nothing on a timer, and each test opens with its invariant line. Mason also showed by mutation that each test fails without the code it guards. Two things to do next: (1) bound the while (... /waiting ...) poll in the request test with until, so a failure reads "did not happen in time" instead of a bare 5 s timeout; (2) re-wrap the BUSY_SERVER doc comment, which breaks mid-sentence at "an event / stream".
test/apps-busy.test.tsnow runs in 3.8 s instead of 19.8 s. Each test takes 0.29–0.37 s, and all 5 tests still pass with nothing skipped. Both times are frombun test test/apps-busy.test.tson this crew machine. The new time held across five runs, between 3.74 s and 3.92 s.What changed (only
test/apps-busy.test.ts):clockoption, and only the sleep check reads it. The suite now passes a clock set to the real time plus an offset it controls, and counts how many times the check reads it. A helper,sweepAt(ms), moves the clock forward and waits for two checks, so every environment has been judged at that time. The idle window is now one hour and the grace period ten minutes, on that clock. Real waiting never gets near them, so the app sleeps only when a test says so. This also removes the old setup that stopped the runtime and started a second one with a shorter window./workstarts a longsleepchild that/doneends./slowwaits until/answeris called, and/waitingreports how many requests are waiting, so the test knows the request has arrived before moving the clock. This replaces the oldsleep 5,sleep 12, a 2-secondsetTimeout, and twoWINDOW + 700waits. Polling now pauses 5 ms between checks; no wait is longer than 50 ms.Each rewritten test still fails without the code it guards. I changed the source, ran the file, then restored the source:
src/appsbusyReasonignores child processesbusyReasonignores open requestsbusyReasonignores open streamsoverdue = false)To try it:
bun test test/apps-busy.test.ts.bun scripts/gate.tsandbun x tsc --noEmitboth pass.I didn't keep a plan on the issue because the
keep_plantool wasn't available in this session.🤖 Generated with Claude Code
Closes #10213