Skip to content

Commit 878379a

Browse files
authored
Merge pull request DeusData#2411 from DeusData/fix/harness-timeout-race-deterministic
test(harness): hold the scheduler contract's fixtures by construction
2 parents f4ff01b + 0d783bc commit 878379a

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)