diff --git a/tests/modules/test_worker_stream.py b/tests/modules/test_worker_stream.py index f4d87452b..214ea4f82 100644 --- a/tests/modules/test_worker_stream.py +++ b/tests/modules/test_worker_stream.py @@ -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)