Fix process-group kill test to work without an init process
os.kill(pid, 0) succeeds on a zombie, and a killed orphan stays a zombie until reaped — which never happens inside a CI container with no init. The test read that as "still alive" and failed there while passing locally. It now reads the process state from /proc, with a control assertion so a broken liveness check cannot pass silently. The group kill itself was correct. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0fd0b2e4a5
commit
999a38a705
1 file changed
+14
-2
@@ -77,6 +77,18 @@ def test_command_timeout_is_reported(tmp_path: Path) -> None:
|
||||
assert "timed out" in outcome.result
|
||||
|
||||
|
||||
def _is_running(pid: int) -> bool:
|
||||
"""os.kill(pid, 0) is not enough: a killed orphan stays a zombie until
|
||||
something reaps it, and no init does that inside a CI container. Read the
|
||||
process state instead."""
|
||||
try:
|
||||
stat = Path(f"/proc/{pid}/stat").read_text()
|
||||
except FileNotFoundError:
|
||||
return False
|
||||
# State is the first field after the parenthesised comm.
|
||||
return stat.rsplit(")", 1)[1].split()[0] != "Z"
|
||||
|
||||
|
||||
def test_timeout_kills_the_whole_process_group(tmp_path: Path) -> None:
|
||||
ws = Workspace(tmp_path / "work", timeout_s=1)
|
||||
pidfile = ws.root / "child.pid"
|
||||
@@ -84,8 +96,8 @@ def test_timeout_kills_the_whole_process_group(tmp_path: Path) -> None:
|
||||
ws.run_command(f"(sleep 30 & echo $! > {pidfile}); sleep 30")
|
||||
assert pidfile.exists()
|
||||
pid = int(pidfile.read_text().strip())
|
||||
with pytest.raises(ProcessLookupError):
|
||||
os.kill(pid, 0)
|
||||
assert _is_running(os.getpid()), "liveness check is broken, not the kill"
|
||||
assert not _is_running(pid)
|
||||
|
||||
|
||||
def test_agent_credentials_are_not_inherited(
|
||||
|
||||
Reference in new issue
Block a user