test(daemon): make the upload deadline tests deterministic under load
Summary
Some upload deadline tests failed in the Coverage job on unrelated PRs (#4722 job 136185562286, #4724 job 136241335534). The cause was in the tests. They waited for the server by counting event-loop turns, or they moved the fake clock before the server had reached the state the case depends on. Under Coverage the server's filesystem completions run late. The product code did not change. No failure showed the server resetting an earlier answer.
Root cause per test (upload-http-deadline.test.ts):
- "an expired queued request with an unread body never resets the earlier answer", and also "a queued 308 behind a long finalize …": the test advanced the clock 150 s after
flushIO()and assumed B's 308 was already committed. When B's offsetstatran late, B's inactivity ceiling fired first, so B answered a typed 500. That is correct product behavior. The test now waits for the server to end B's response before it moves the clock. - "guard: a single-shot upload expiring behind a long finalize …": after the hash was released, a bounded loop (50 ×
flushIO) waited for two responses. It did not throw when it gave up, so a late rename produced[]. The test now waits for B's admission and for B's committed answer, then for two complete responses parsed from the socket. - "a chunk refused by its byte cap …": the same bounded loop waited for the 400, and the server-close check used
flushIOwithgetConnections. The test now waits for the parsed response, for the server FIN, and for the server-side connectionclose. - Same pattern, found under CPU load (2 of 60 runs): "a single-shot upload that expires mid-body …" moved the clock 61 s per step without checking that the server had accepted the bytes. The clock then fired the inactivity ceiling and later the 5 s grace. The test now waits for the accepted bytes before each step. The reason assertion is back to the strict
transfer_ingress_deadline_exceeded. - The oversized-JSON tests and the held-hook waits in
upload-http-socket-ownership.test.tshad the same turn counting. They now wait on the parsed response, the FIN, the connection close, the hook's own call, and the signal'sabortevent.
The new upload-loopback.fixtures.ts holds the shared event helpers: watchServer (the server's own request/response hooks and connection close), readResponses (complete HTTP responses, FIN and errors from a raw socket), and watchAcceptedArtifactBytes. No assertion is weaker, and there are no retries or new sleeps.
Validation
Head 32677009f7. pnpm check:affected --run passed with exactCommit=true (format, lint, typecheck, layering, fallow, vitest-related).
Reproduction: a probe that is not committed (NODE_OPTIONS=--import slow-io.mjs) adds a real-time delay after fs.promises completions. It reproduces each CI failure with the same assertion:
| Probe (10 runs each) | before (main) | after |
|---|---|---|
| stat/rename/truncate/rm +25 ms: both queued-308 tests | 10/10 fail | 0/10 |
| rename +1500 ms: guard test | 10/10 fail | 0/10 |
| stat/rename/truncate/rm +600 ms: byte-cap test | 10/10 fail | 0/10 |
| CPU load, coverage, 12 parallel runs + 24 busy loops | 2/60 fail (single-shot mid-body) | 0/200 (10 parallel + 16 busy loops) |
| 200 sequential runs under the coverage config (final head) | — | 0/200 |
The CPU-load runs had a low base rate: a second 100-run batch on main passed 100/100. That is why the probe is the reliable reproduction.
![Autofix with [code]smith](https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png)
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.