fix(test): wait for a whole pid in the ssh loopback kill tests #53
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/ssh-loopback-pid-race"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes the CI failure on #51. That failure wasn't caused by #51; it's a race in an existing test that could hit any PR.
The race
Four tests in
sandboxes/ssh/loopback.test.tsspawn a remote shell that runsecho $! > pidFile. They poll until the file exists, then read it once. But>creates (truncates) the file a moment beforeechowrites the number. A read in that window gets"", which becomesNumber("") = 0, andgone(0)is always true (there's no/proc/0/stat).expect(gone(child)).toBe(false)fails, which is #51's CI log (expected true to be false).waitGone(0)is instantly true, so they passed without checking anything.In a tight-poll probe, 358 of 400 reads landed in that window.
The fix
A
readPid(file)helper that waits for a complete<positive pid>\nline (up to ~5s, then throws a clear error). All four tests use it. Test-only, one file, +18 −8.Verification
expected true to be false); this branch passes.pnpm typecheckpassed. The fullpnpm testran 3 times, each 1336 passed / 246 skipped, 0 failed.loopback.test.tsalone passed 20 of 20.After merging
Re-run #51's CI, or merge
maininto it, and it should go green.The remote shell's `echo $! > file` creates (truncates) the file a moment before it writes the number. The tests polled for the file to EXIST, then read it once: in that window they read "", Number("") = 0, and pid 0 is always "gone". That failed CI on #51 (kill test: expected gone(0) false) and made the two abort tests pass vacuously. readPid waits for a full "<positive pid>\n" line instead.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.