Skip to content

test: write scheduler barrier files atomically - #2069

Open
DeusData wants to merge 2 commits into
mainfrom
fix/test-wave-atomic-barrier-writes
Open

test: write scheduler barrier files atomically#2069
DeusData wants to merge 2 commits into
mainfrom
fix/test-wave-atomic-barrier-writes

Conversation

@DeusData

@DeusData DeusData commented Sep 5, 2026

Copy link
Copy Markdown
Owner

What

scripts/run-test-wave.py publishes its test-barrier files (<suite>.ready, <suite>.leader-exited) through a new publish_barrier_file() helper: write a same-directory temp file, then os.replace() it onto the destination. All three barrier writes go through it.

tests/test_parallel_harness_contract.sh gains a structural pin: the scheduler may not write a barrier file in place with Path.write_text, and it must rename into place. No timing, no sleeps.

Why

Path.write_text is open-then-write: it creates and truncates the file first and the content lands afterwards. The harness contract polls for <suite>.ready to 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 with ValueError: 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.replace is 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

  • Reproduce-first in the canonical runner: bash tests/test_parallel_harness_contract.sh with origin/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, including timeout_exit_race, which exercises the barrier path end to end).
  • python3 -m py_compile scripts/run-test-wave.py OK; the helper exercised directly: exact content, overwrite works, no temp-file residue.
  • bash scripts/check-no-test-skips.sh OK.
  • Repo lint (cppcheck + clang-format) covers C only and no C is touched; shellcheck -s bash on the contract: 0 findings before and after.

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>
@DeusData DeusData mentioned this pull request Sep 5, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant