diff --git a/nisse-dev/tests/test_tools.py b/nisse-dev/tests/test_tools.py index 10952df..5e66c4f 100644 --- a/nisse-dev/tests/test_tools.py +++ b/nisse-dev/tests/test_tools.py @@ -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(