fix: preserve native calls on stop and keep status reads observational
This commit is contained in:
1 parent
97a3de20c9
commit
8d3eab1164
19 files changed
+631
-290
No files matched your search
@@ -120,7 +120,7 @@ End Class
|
||||
assert ('NATIVE_QUIT' in outcome.stdout) is (identity and close_ok and not other_document)
|
||||
|
||||
|
||||
def test_cancel_after_native_save_returns_stops_later_native_operations(tmp_path):
|
||||
def test_cancel_after_native_save_returns_keeps_save_fact_and_normal_close(tmp_path):
|
||||
source = Path('src/cbb_refresh_verify/save_verified_block.vbs').read_text('utf-8')
|
||||
classes = r'''
|
||||
Class FakePi
|
||||
@@ -182,9 +182,10 @@ End Class
|
||||
'//nologo', str(harness), 'expected.prj', 'CBB.pcb', str(tmp_path/'cancel.signal')],
|
||||
capture_output=True, text=True, timeout=10)
|
||||
assert 'NATIVE_SAVE_RETURNED' in outcome.stdout
|
||||
assert outcome.returncode == 9, outcome.stderr
|
||||
assert 'VERIFY_CANCELLED' in outcome.stdout
|
||||
assert 'CLOSE_OK' not in outcome.stdout
|
||||
assert 'SAVE_OK' in outcome.stdout
|
||||
assert 'CLOSE_OK' in outcome.stdout
|
||||
assert 'SAVE_REJECTED' not in outcome.stdout
|
||||
assert outcome.returncode == 10, outcome.stderr # FakeApp retains another document.
|
||||
|
||||
|
||||
def test_worker_attempts_normal_close_after_idle_integration_failure(tmp_path, monkeypatch):
|
||||
@@ -200,14 +201,16 @@ def test_worker_attempts_normal_close_after_idle_integration_failure(tmp_path, m
|
||||
assert not any(event['stage'] == 'save_start' for event in events)
|
||||
|
||||
|
||||
def test_stop_cancels_then_stops_automation_client_after_deadline(tmp_path):
|
||||
def test_stop_cancels_without_killing_pending_native_call(tmp_path):
|
||||
calls = []
|
||||
class BusyWorker:
|
||||
def request_stop(self): calls.append('cancel')
|
||||
def wait(self, timeout): raise TimeoutError('native Save still running')
|
||||
def kill(self): calls.append('kill')
|
||||
runner._stop_worker(BusyWorker(), timeout=0)
|
||||
assert calls == ['cancel', 'kill']
|
||||
def stop_automation_clients(self): calls.append('stop-helper')
|
||||
def poll(self): return None
|
||||
assert runner._stop_worker(BusyWorker(), timeout=0) is False
|
||||
assert calls == ['cancel']
|
||||
|
||||
|
||||
def test_status_server_close_allows_eof_cleanup_before_termination(tmp_path):
|
||||
@@ -255,13 +258,14 @@ def test_shared_address_is_diagnostic_after_successful_native_execution(tmp_path
|
||||
assert any(event['stage'] == 'icdb_address_remaining' for event in events)
|
||||
|
||||
|
||||
def test_cooperative_supervisor_loss_keeps_pending_save_helper_alive(tmp_path):
|
||||
@pytest.mark.parametrize('stop_clients', [False, True])
|
||||
def test_cooperative_supervisor_loss_keeps_pending_save_helper_alive(tmp_path, stop_clients):
|
||||
import win32api, win32con, win32process
|
||||
supervisor = subprocess.Popen([sys.executable, '-c', 'import time;time.sleep(30)'])
|
||||
script, ready, cancel = tmp_path/'worker.py', tmp_path/'ready.json', tmp_path/'cancel.signal'
|
||||
script.write_text('import subprocess,sys,time,json\nfrom pathlib import Path\n'
|
||||
'from cbb_refresh_verify.desktop_worker import start_supervisor_watchdog,launch_save_helper\n'
|
||||
f'start_supervisor_watchdog({supervisor.pid},cancel_path={str(cancel)!r})\n'
|
||||
f'start_supervisor_watchdog({supervisor.pid},cancel_path={str(cancel)!r},stop_clients={stop_clients!r})\n'
|
||||
'helper=launch_save_helper([sys.executable,"-c","import time;time.sleep(30)"])\n'
|
||||
f'Path({str(ready)!r}).write_text(json.dumps(helper.pid))\n'
|
||||
'time.sleep(30)\n', encoding='utf-8')
|
||||
@@ -280,6 +284,7 @@ def test_cooperative_supervisor_loss_keeps_pending_save_helper_alive(tmp_path):
|
||||
while not cancel.exists() and time.monotonic()<deadline:
|
||||
time.sleep(.05)
|
||||
assert cancel.exists()
|
||||
time.sleep(5.2 if stop_clients else .1)
|
||||
assert worker.poll() is None
|
||||
assert win32process.GetExitCodeProcess(handle) == 259
|
||||
finally:
|
||||
|
||||
Reference in new issue
Block a user