fix: preserve CAD shutdown failures and record desktop cleanup evidence
This commit is contained in:
1 parent
660bbe3736
commit
f3d2570e48
5 files changed
+131
-14
No files matched your search
@@ -107,6 +107,51 @@ def test_success_quits_owned_cad_before_releasing_desktop(monkeypatch, tmp_path)
|
||||
assert record['state'] == 'released' and record['clean']
|
||||
|
||||
|
||||
def test_cleanup_preserves_orderly_exit_failure_before_desktop_failure(monkeypatch, tmp_path):
|
||||
fake_desktop(monkeypatch, tmp_path, quit_code=1)
|
||||
session = runtime.IsolatedCadSession(tmp_path)
|
||||
session.__enter__()
|
||||
def failed_release():
|
||||
raise OSError('owned desktop still exists after cleanup')
|
||||
session.desktop.close = failed_release
|
||||
with pytest.raises(WorkerMonitorError) as caught:
|
||||
session.__exit__(None, None, None)
|
||||
record = json.loads((tmp_path / 'private-desktop.json').read_text())
|
||||
assert 'refused orderly exit' in record['error']
|
||||
assert 'desktop still exists' in record['error']
|
||||
assert 'refused orderly exit' in str(caught.value)
|
||||
assert [item['stage'] for item in record['cleanup_errors']] == ['orderly_shutdown', 'desktop_release']
|
||||
assert record['quit_helper_exit_code'] == 1
|
||||
assert record['shutdown_seconds'] >= 0
|
||||
assert record['state'] == 'uncertain' and (tmp_path / 'uncertain.flag').exists()
|
||||
|
||||
|
||||
def test_clean_release_records_helper_and_cad_exit_codes(monkeypatch, tmp_path):
|
||||
fake_desktop(monkeypatch, tmp_path)
|
||||
with runtime.IsolatedCadSession(tmp_path):
|
||||
pass
|
||||
record = json.loads((tmp_path / 'private-desktop.json').read_text())
|
||||
assert record['quit_helper_exit_code'] == 0 and record['cad_exit_code'] == 0
|
||||
assert record['cleanup_errors'] == []
|
||||
|
||||
|
||||
def test_exit_code_diagnostics_do_not_interrupt_the_normal_cad_wait(monkeypatch, tmp_path):
|
||||
_, cad = fake_desktop(monkeypatch, tmp_path)
|
||||
waited = []
|
||||
cad.wait = lambda timeout: waited.append(timeout) or 0
|
||||
session = runtime.IsolatedCadSession(tmp_path)
|
||||
record = session._record
|
||||
def unavailable_during_shutdown(**values):
|
||||
if 'quit_helper_exit_code' in values and not waited:
|
||||
raise PermissionError('diagnostic file temporarily locked before CAD exit')
|
||||
record(**values)
|
||||
session._record = unavailable_during_shutdown
|
||||
with session:
|
||||
pass
|
||||
assert waited == [15]
|
||||
assert session.record['clean']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('ready_after', [90, None])
|
||||
def test_slow_startup_is_bounded_and_cleanup_remains_owned(monkeypatch, tmp_path, ready_after):
|
||||
events, _ = fake_desktop(monkeypatch, tmp_path)
|
||||
|
||||
@@ -22,11 +22,16 @@ def test_release_does_not_report_success_while_another_handle_keeps_desktop_aliv
|
||||
assert retained.stdout.readline() == b'ready\r\n'
|
||||
with pytest.raises(TaskCenterError, match='still exists'):
|
||||
desktop.close()
|
||||
record = desktop.cleanup_record
|
||||
assert record['desktop_handle_closed']
|
||||
assert not record['desktop_confirmation']['released']
|
||||
assert record['desktop_confirmation']['elapsed_seconds'] >= 2
|
||||
finally:
|
||||
retained.terminate()
|
||||
retained.wait(timeout=5)
|
||||
retained.stdout.close()
|
||||
desktop.close()
|
||||
assert desktop.cleanup_record['desktop_confirmation']['released']
|
||||
|
||||
|
||||
def test_startup_info_always_targets_private_desktop():
|
||||
@@ -195,6 +200,11 @@ def test_native_private_process_has_captured_output_and_real_exit_259():
|
||||
assert process.stderr.readline() == b'private-err\r\n'
|
||||
assert process.wait(timeout=5) == 259
|
||||
assert process.poll() == 259
|
||||
record = desktop.cleanup_record
|
||||
assert record['desktop_handle_closed'] and record['desktop_confirmation']['released']
|
||||
assert record['processes'][0]['exit_code'] == 259
|
||||
assert record['processes'][0]['job_active_processes'] == 0
|
||||
assert record['processes'][0]['unconfirmed_descendant_handles'] == 0
|
||||
|
||||
|
||||
def test_failed_rollback_termination_still_releases_owned_handles():
|
||||
|
||||
Reference in new issue
Block a user