Repository navigation
test: fix three flakes from tests racing each other in one process - #181
Merged
Merged
Conversation
…hits text file busy Tests that fake `rex`, `herdr`, `hc`, `gh` and `herdr-app` wrote the script with std::fs::write and then ran it. A fork on another test thread while the file was open inherited the write handle until that child exec'd, and exec of the script failed with ETXTBSY in the meantime: rex::agent's tests failed this way about 1 in 80 runs of the module alone. `test_support::write_script` has /bin/sh write the file, so this process never holds it open. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lds its writer The piped-stdin test closed a pipe writer and asserted the reader hung up. A child that another test is spawning holds a copy of every descriptor between fork and exec, so the writer could outlive the drop and the pipe not hang up yet. A socket pair stands in: shutting the writer down hangs the reader up however many copies stay open. Co-Authored-By: Claude Opus 5.5 <[email protected]>
pty() opened the controller with openpt and set close-on-exec afterwards. A child that another test spawned in between (e.g. the delivery test's `sleep 5 &`) kept the controller past its exec, so the tty did not hang up within the neighbouring test's 5 s deadline. Opening /dev/ptmx with O_CLOEXEC closes that window on Linux and macOS alike. Co-Authored-By: Claude Opus 5.5 <[email protected]>
closed_port() bound port 0 and released it, so a test running alongside could be given the same port and find the "closed" session answering. Port 1 lies below every ephemeral range. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… written from a child too The same text file busy race as in the app's unit tests: the review crate's fake gh, and the fake gh, rex, hc and herdr-app of tests/pr_review.rs and tests/rex_hc_review.rs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes three test flakes, all from tests racing each other inside one process:
rex::agentmostly, alsorex::agents,hc::*,app::pi_target,review::tests::*): fixtures wrote a fake command withstd::fs::writeand then ran it. When another test thread forked in that moment, the child inherited the open write handle until it exec'd, and running the script failed withText file busy (os error 26)meanwhile.test_support::write_scriptnow has/bin/shwrite the file, so the test process never holds it open; the review crate and the integration tests (tests/support) get the same helper.rex::agentalone went from 13 failures in 1000 runs to 0.hangup::tests::piped_stdin_is_passed_over_for_the_terminal: a child forked by another test holds a copy of the pipe's writer until it execs, so the pipe hadn't hung up yet when checked. A socket pair withshutdown(Both)hangs up regardless of copies. In the same module,pty()opens/dev/ptmxclose-on-exec rather than setting it afteropenpt, which left a gap for a child to keep the controller.pi::tests::a_closed_session_is_gone_and_its_entry_removed: the "closed" port was bound and released, so a parallel test'sbind(0)could be given it. It's now port 1, below every ephemeral range, sobind(0)never hands it out.AGENTS.md gets a section on writing tests that share one process, so new tests avoid these races.
The full
plannotator-tuisuite failed on 4–7% of runs onmain; with these, 0 in 200.The
hangupchanges are Unix-only and untested on macOS, which only post-merge CI covers: they rely on a shut-down Unix socket reportingPOLLHUPand on/dev/ptmxworking withgrantpt/unlockpt, as on Linux.🤖 Co-created with Claude Opus 5.5