From e6e3725933bfb8dd01a4e2eb668d07374b0aab1a Mon Sep 17 00:00:00 2001 From: "Bingxi Zhao (Frank)" <13051345080@163.com> Date: Wed, 2 Dec 2026 11:02:14 +0800 Subject: [PATCH] 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 --- tests/modules/test_worker_stream.py | 31 ++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) 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)