fix: preserve native calls on stop and keep status reads observational

This commit is contained in:
阿白叔 committed 2026-11-06 15:42:33 +08:00
1 parent 97a3de20c9
commit 8d3eab1164
19 files changed
+631 -290

No files matched your search

+8 -5
View File
@@ -66,8 +66,8 @@ def test_stop_worker_escalates_only_after_cooperative_deadline():
if not self.stopped: raise TimeoutError()
def kill(self): calls.append('client_stop'); self.stopped = True
def poll(self): return 1 if self.stopped else None
assert runner._stop_worker(Worker(), timeout=.1) is True
assert calls == ['cancel', 'wait', 'client_stop', 'wait']
assert runner._stop_worker(Worker(), timeout=.1) is False
assert calls == ['cancel', 'wait']
def test_cancel_reaches_current_supervised_worker(tmp_path, monkeypatch):
@@ -223,7 +223,7 @@ def test_save_and_failure_close_clients_are_both_tracked(script, monkeypatch):
assert proof['safe_to_continue'] is False and proof['remaining_pids'] == [22]
def test_watchdog_with_cancel_signal_stops_clients_after_supervisor_exit(tmp_path):
def test_watchdog_with_cancel_signal_retains_callers_after_supervisor_exit(tmp_path):
import subprocess, sys, time
import win32api, win32con, win32process
supervisor = subprocess.Popen([sys.executable, '-c', 'import time; time.sleep(30)'])
@@ -246,9 +246,12 @@ def test_watchdog_with_cancel_signal_stops_clients_after_supervisor_exit(tmp_pat
for pid in json.loads(ready.read_text()):
handles.append(win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION | win32con.PROCESS_TERMINATE, False, pid))
supervisor.terminate(); supervisor.wait(5)
assert worker.wait(10) == 75 and cancel.is_file()
deadline = time.monotonic()+3
while not cancel.is_file() and time.monotonic()<deadline:
time.sleep(.02)
assert worker.poll() is None and cancel.is_file()
assert win32process.GetExitCodeProcess(handles[0]) == 259
assert win32process.GetExitCodeProcess(handles[1]) != 259
assert win32process.GetExitCodeProcess(handles[1]) == 259
finally:
for p in (supervisor, worker):
if p.poll() is None: p.terminate()