Repository navigation
test(wsl): make the bash relay reap test deterministic - #34329
Conversation
It raced the relay's kill against the stub cats setting their TERM trap, and picked the cat to keep blocked by start order. It now hangs up only once both traps are in place, and tells the socket reader from the stdin reader by whether its stdin is the relay's socket (fd 3).
|
No actionable comments were generated in the recent review.
|
The fake cat backgrounded the real cat with `&`, which a non-interactive sh starts on /dev/null (dash even under `<&0`). The socket reader therefore ended at once, before orcad hung up, and the relay killed its partner, sometimes before that cat's TERM trap was set: on Linux under load the trap count stayed at 1 even after #34329 (3 of 6 rounds of 50 failed). The fake cat now passes stdin on fd 5, as the relay itself does, so the socket reader ends only when orcad hangs up and the stdin reader blocks until killed.
* test(wsl): hand the reap test's fake cat its real stdin The fake cat backgrounded the real cat with `&`, which a non-interactive sh starts on /dev/null (dash even under `<&0`). The socket reader therefore ended at once, before orcad hung up, and the relay killed its partner, sometimes before that cat's TERM trap was set: on Linux under load the trap count stayed at 1 even after #34329 (3 of 6 rounds of 50 failed). The fake cat now passes stdin on fd 5, as the relay itself does, so the socket reader ends only when orcad hangs up and the stdin reader blocks until killed. * test(wsl): mark the fake cat armed only once its child is known; tighten the comment
ELI5
A test added in #34260 sometimes failed by chance. It checks that our WSL connection relay cleans up its helper processes. Sometimes the test's fake helpers weren't ready yet when the relay stopped them, so the check came out wrong. Now the test waits until the fakes are ready, and tells them apart reliably, so it passes or fails for real reasons only.
What Changed
Before:
orcad-bash-stdio-bridge.test.ts› "waits for the cat it kills before exiting" failed intermittently (for example, shard 5 of run 40471530389 failed in 12 ms). It had two races:catbefore that stub had installed its TERM trap;mkdirfirst.After:
expect.pollwith a 10 s bound).[ /dev/fd/0 -ef /dev/fd/3 ]). That reader exits with orcad; the stdin reader stays blocked until the relay kills it.The 0.3 s the killed stub takes to die is not a race. The relay must wait for it, and the test checks the mark exists the moment the relay exits.
Why
The test now waits on the conditions it depends on instead of on timing. Telling the two stubs apart by their file descriptors, rather than by file type, works whether stdin is a pipe or a socket pair: Bun, which runs the tests, hands the child a socket pair.
Linked Issue
Follow-up to #34260 (R40).
Visual Proof
N/A: this changes a test only.
Testing
waitremoved, it fails every time (3/3), so it still catches the bug.Flag-off: this is a test-only change; nothing ships.
Checklist
N/Afor visuals with reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (typecheck, the suite, the changed-code gate and the flaky-test ratchet pass locally; CI runs the rest)