test: write scheduler barrier files atomically - #2069
Open
DeusData wants to merge 2 commits into
Open
Conversation
Path.write_text is open-then-write: it creates and truncates the file first and the content lands afterwards. The parallel harness contract polls for `<suite>.ready` to appear and then parses its content as the leader pid, so a reader that wins that window sees an empty file and fails with `ValueError: invalid literal for int() with base 10: ''` -- a spurious FAIL of the harness contract with a scheduler-side cause. The same shape applied to `<suite>.leader-exited`. Publish the barrier files through a helper that writes a same-directory temp file and os.replace()s it onto the destination, which is atomic on POSIX and Windows: a poller now sees either no file or complete content. All three barrier publications go through it. Pin the contract structurally (no timing): the scheduler may not write a barrier file in place, and it must rename into place instead. The pin is RED on the previous scheduler. Distilled from #1188 with co-author credit. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com> Co-authored-by: Kody <kaidi.shi.1121@gmail.com> Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
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.
What
scripts/run-test-wave.pypublishes its test-barrier files (<suite>.ready,<suite>.leader-exited) through a newpublish_barrier_file()helper: write a same-directory temp file, thenos.replace()it onto the destination. All three barrier writes go through it.tests/test_parallel_harness_contract.shgains a structural pin: the scheduler may not write a barrier file in place withPath.write_text, and it must rename into place. No timing, no sleeps.Why
Path.write_textis open-then-write: it creates and truncates the file first and the content lands afterwards. The harness contract polls for<suite>.readyto appear and then parses its content as the leader pid (int(ready.read_text())), so a reader that wins that window sees an empty file and fails withValueError: invalid literal for int() with base 10: ''— a spurious FAIL of the harness contract with a scheduler-side cause (an O9 flake, fixed in production, not in the test).os.replaceis atomic on POSIX and Windows, so a poller now sees either no file or complete content.Distilled from #1188 with co-author credit to @Geek0x0 — the fix was buried in that feature PR (commit
f1aea59600, "fix(ci): make test-barrier writes atomic"); this PR lands only that fix and leaves the rest of #1188 untouched.Verification
bash tests/test_parallel_harness_contract.shwithorigin/main's scheduler swapped in → rc=1,FAIL: scheduler barrier files are written in place (non-atomic); with this branch →Parallel harness contract passed(every case unchanged, includingtimeout_exit_race, which exercises the barrier path end to end).python3 -m py_compile scripts/run-test-wave.pyOK; the helper exercised directly: exact content, overwrite works, no temp-file residue.bash scripts/check-no-test-skips.shOK.shellcheck -s bashon the contract: 0 findings before and after.