Skip to content

Commit 0d783bc

Browse files
committed
test(harness): hold the scheduler contract's fixtures by construction
The parallel-scheduler contract failed twice on test-windows CLANG64 while running fake suites only: - PR DeusData#2394 (run 36364479687): "Windows timeout race refused without a surviving descendant to refuse over". The refusal came 38s after the forced leader exit (a cold powershell/CIM descendant probe, once in the wave loop and again in the cleanup pass), while the fixture's descendant was a `time.sleep(30)` that had already exited on its own. - PR DeusData#2345 (run 36199749518): "suite 'hang_after_summary' taskkill could not prove process-tree cleanup". The scheduler bounded taskkill.exe with --kill-grace, which the contract passes as 1s, so a slow cold start of the tool was reported as a failed cleanup. Both verdicts were a race between a clock and runner latency. An audit of the fixture found more of the same shape: - Every hanging fixture ended on its own after 30s. A starved scheduler could therefore see a "hung" leader exit 0, and a descendant the scheduler failed to kill could vanish before the leak check looked. - The 1s --timeout could kill a slow leader before it had printed its summary (asserted pass=1), spawned its descendant or written the descendant pid. That pid was then read back with int() from a file written create-then-write, so a reader could see no file or an empty one. The empty-file read recorded earlier was the scheduler's ready file, which 3b9052c already publishes atomically; the fixture's own writer had the same shape. - The descendant installed its SIGTERM-ignore during its own start-up. A SIGTERM that won that race skipped the SIGKILL escalation the POSIX leg exists to cover, silently and with the verdict unchanged. - On Windows, the stubborn-tree leak check was a single look right after taskkill, but TerminateProcess returns before its target has exited. Fix it by construction, not by budget: - A gate. Every process that must outlive the scheduler's decision blocks reading stdin. That is a pipe whose only write end the contract holds, handed down through the scheduler, and the read returns only at EOF. The contract closes the pipe once the verdict is recorded. If the contract dies, EOF releases everything, so nothing is orphaned and no fixture ends on a clock. - The three hanging scenarios run under the scheduler's existing pre-terminate barrier. They are released only once the fixture has published `<suite>.established`, which happens after the summary is flushed, the descendant has confirmed it is armed, and its pid is known. The marker is written to a temp file and moved into place with os.replace, so a reader sees either no file or the whole file. - The Windows leak check waits on the descendant's process handle. That wait is exact, not a race: the descendant is held by the gate, so the scheduler's kill is the only way it can end. - run-test-wave.py runs taskkill through windows_taskkill_tree() with its own stable-state budget (WINDOWS_TASKKILL_SECONDS = 15), as 132e8fc did for the descendant probe. --kill-grace keeps bounding what its name says. Real runs already pass --kill-grace 15, so they are unchanged. The contract pins this structurally, the same way it pins the probe: exactly one taskkill site, no kill-grace there, and a helper bounded by the constant that fails closed on a timeout, a start failure or a non-zero exit. Every assertion keeps its contract: - A leader that hangs after a green summary is recorded as rc=124 pass=1. - A zero-test child is recorded as rc=97. - The wave continues after a bounded failure. - A SIGTERM-resistant tree is killed in full. - A leader that exits between the timeout decision and termination is still cleaned up on POSIX. On Windows the scheduler refuses (rc=2, naming the cleanup failure) over a descendant that is really alive. A new self-check fails loudly if a held leader or descendant is not live while the barrier holds, that is, if the fixture no longer exercises what those assertions claim. Proof, on macOS arm64 and a Linux arm64 container. The Windows branch was reasoned through; the VM is down. - Torture hook (proof only) that delays each hanging leader 2s, past the 1s timeout. The old fixture is RED 3/3 on every scenario (pass=0, FileNotFoundError on descendant.pid, "lost its bounded result"). The new one is green, including at 8s, and 10/10 under the hook plus CPU load. - The DeusData#2394 mechanism: after an injected 31s refusal latency the old descendant is gone and the new one is live. It exits 0.02s after the gate closes. - The taskkill pin is RED on the old scheduler and green on the new one. - Stress, 20 runs each under CPU load. The old full contract passed 20/20 on macOS and 20/20 on Linux, so these hosts do not reproduce the CI timing. The rebuilt held scenarios passed 20/20 on macOS and 20/20 on Linux. The full contract after the change passes a single run on macOS and on Linux, and 20/20 on each leg under CPU load (4 load workers; the Linux container is capped at 4 CPUs). Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 1f9b4db commit 0d783bc

2 files changed

Lines changed: 416 additions & 280 deletions

File tree

‎scripts/run-test-wave.py‎

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@
5555
WINDOWS_DESCENDANT_PROBE_SECONDS = 15
5656
WINDOWS_DESCENDANT_PROBE_ATTEMPTS = 2
5757

58+
# WHY: the same defect as the probe above, one call earlier. `taskkill /F`
59+
# cannot be resisted -- a live tree is terminated as soon as the tool runs --
60+
# so what bounding it measures is taskkill.exe's own cold start on the runner,
61+
# not the tree. Timed with --kill-grace (1s in the harness contract), a slow
62+
# start was reported as "taskkill could not prove process-tree cleanup" for an
63+
# ordinary hung suite (#2345). The tree does not change while the tool starts,
64+
# so this is a stable-state budget; --kill-grace keeps bounding what it names:
65+
# how long the leader may take to be reaped once taskkill has succeeded.
66+
WINDOWS_TASKKILL_SECONDS = 15
67+
5868

5969
@dataclass
6070
class ActiveSuite:
@@ -225,6 +235,27 @@ def windows_tree_cleanup_blocker(pid: int) -> str | None:
225235
return unproven
226236

227237

238+
def windows_taskkill_tree(pid: int) -> bool:
239+
"""Force-terminate `pid` and its whole tree; True only on proven success.
240+
241+
A tool that cannot start, cannot finish within its own budget, or reports
242+
failure is never read as success -- the caller refuses to call the tree
243+
clean.
244+
"""
245+
try:
246+
completed = subprocess.run(
247+
["taskkill.exe", "/PID", str(pid), "/T", "/F"],
248+
check=False,
249+
stdin=subprocess.DEVNULL,
250+
stdout=subprocess.DEVNULL,
251+
stderr=subprocess.DEVNULL,
252+
timeout=WINDOWS_TASKKILL_SECONDS,
253+
)
254+
except (OSError, subprocess.TimeoutExpired):
255+
return False
256+
return completed.returncode == 0
257+
258+
228259
def terminate_process_tree(active: ActiveSuite, kill_grace: int) -> None:
229260
process = active.process
230261
leader_exited = process.poll() is not None
@@ -243,24 +274,7 @@ def terminate_process_tree(active: ActiveSuite, kill_grace: int) -> None:
243274
f"could not be proven: {blocker}"
244275
)
245276
return
246-
try:
247-
completed = subprocess.run(
248-
[
249-
"taskkill.exe",
250-
"/PID",
251-
str(process.pid),
252-
"/T",
253-
"/F",
254-
],
255-
check=False,
256-
stdin=subprocess.DEVNULL,
257-
stdout=subprocess.DEVNULL,
258-
stderr=subprocess.DEVNULL,
259-
timeout=kill_grace,
260-
)
261-
except (OSError, subprocess.TimeoutExpired):
262-
completed = None
263-
if completed is None or completed.returncode != 0:
277+
if not windows_taskkill_tree(process.pid):
264278
if process.poll() is None:
265279
process.kill()
266280
try:

0 commit comments

Comments
 (0)