test: stop probing worker liveness with os.kill on Windows

On Windows os.kill(pid, 0) is not a probe: signal 0 is CTRL_C_EVENT, so CPython broadcasts Ctrl+C to every process on the console. The three existence checks in test_worker_stream aborted pytest and the shell that started it, so the file could not run on Windows at all. Use deeptutor.runtime.process.probe_process_liveness, which already documents the hazard, and leave the POSIX path unchanged.

Refs #2354
This commit is contained in:
Bingxi Zhao (Frank)
2026-12-02 11:02:14 +08:00
parent e70a6be7e3
commit e6e3725933

View File

@@ -8,6 +8,26 @@ import sys
import pytest
from deeptutor.plugins.runtime import _WorkerClient
from deeptutor.runtime.process import probe_process_liveness
def assert_alive(pid: int) -> None:
"""On Windows os.kill(pid, 0) is CTRL_C_EVENT, broadcast to the console.
It does not probe the worker; it aborts pytest and the shell that started it.
"""
if os.name == "nt":
assert probe_process_liveness(pid) == "alive"
else:
os.kill(pid, 0)
def assert_reaped(pid: int) -> None:
if os.name == "nt":
assert probe_process_liveness(pid) == "dead"
else:
with pytest.raises(ProcessLookupError):
os.kill(pid, 0)
def worker(tmp_path, source):
@@ -36,10 +56,9 @@ time.sleep(60)
stream = client.stream("run_capability", {})
event = await asyncio.wait_for(anext(stream), timeout=5)
pid = int(event["content"])
os.kill(pid, 0)
assert_alive(pid)
await asyncio.wait_for(stream.aclose(), timeout=5)
with pytest.raises(ProcessLookupError):
os.kill(pid, 0)
assert_reaped(pid)
@pytest.mark.asyncio
@@ -73,8 +92,7 @@ async def test_malformed_or_truncated_stream_fails(tmp_path, output):
async with asyncio.timeout(5):
async for _ in client.stream("run_capability", {}):
pass
with pytest.raises(ProcessLookupError):
os.kill(int(ready.read_text()), 0)
assert_reaped(int(ready.read_text()))
@pytest.mark.asyncio
@@ -97,5 +115,4 @@ time.sleep(60)
task.cancel()
with pytest.raises(asyncio.CancelledError):
await asyncio.wait_for(task, 5)
with pytest.raises(ProcessLookupError):
os.kill(pid, 0)
assert_reaped(pid)