fix: recheck private desktop release with writer exit proof
Core regression / Python core, intervention UI and release configuration (push) Successful in 5m4s
Core regression / JavaScript syntax (push) Successful in 8s
Core regression / Python core, intervention UI and release configuration (pull_request) Successful in 5m25s
Core regression / JavaScript syntax (pull_request) Successful in 11s
Core regression / Python core, intervention UI and release configuration (push) Successful in 5m4s
Core regression / JavaScript syntax (push) Successful in 8s
Core regression / Python core, intervention UI and release configuration (pull_request) Successful in 5m25s
Core regression / JavaScript syntax (pull_request) Successful in 11s
This commit is contained in:
1 parent
c114db9f31
commit
4fb715507e
16 files changed
+537
-21
No files matched your search
@@ -4,6 +4,8 @@ import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
from threading import Timer
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -14,6 +16,43 @@ from dx_productivity.trial_task_center.isolated_desktop import _Win32Api, build_
|
||||
from dx_productivity.trial_task_center.logging_setup import configure_logging
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.name != 'nt', reason='Windows desktop object lifetime')
|
||||
def test_a_late_owned_job_exit_releases_the_live_lease_without_second_quit(tmp_path):
|
||||
runtime = BatchCadRuntime(tmp_path, 'execution')
|
||||
desktop = runtime._ensure_desktop()
|
||||
exit_file = tmp_path / 'exit'
|
||||
process = desktop.start_process((sys.executable, '-u', '-c',
|
||||
'import pathlib,sys,time; marker=pathlib.Path(sys.argv[1]); print("ready",flush=True); '
|
||||
'exec("while not marker.exists(): time.sleep(.02)")', str(exit_file)),
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
runtime._track(process)
|
||||
quit_attempts = []
|
||||
signal = Timer(.8, exit_file.touch)
|
||||
|
||||
def interrupted_quit(*args):
|
||||
quit_attempts.append(process.pid)
|
||||
signal.start()
|
||||
raise OSError('injected delayed root exit')
|
||||
|
||||
try:
|
||||
assert process.stdout.readline() == b'ready\r\n'
|
||||
runtime.cad = SimpleNamespace(cad=process, record={'forced_termination': True}, __exit__=interrupted_quit)
|
||||
with pytest.raises(BatchResourceCleanupError, match='injected delayed root exit'):
|
||||
runtime.close()
|
||||
assert len(quit_attempts) == 1
|
||||
assert runtime.record['state'] == 'released'
|
||||
assert runtime.record['release_proof']['method'] == 'owned_cleanup'
|
||||
assert runtime.record['release_proof']['processes_exited'] is True
|
||||
assert desktop.cleanup_record['desktop_lease']['returned'] is True
|
||||
assert runtime.record['cad_shutdown']['forced_termination'] is True
|
||||
assert len(runtime.record['release_rechecks']) in {2, 3}
|
||||
guard_pending_resources(tmp_path)
|
||||
finally:
|
||||
exit_file.touch()
|
||||
signal.cancel()
|
||||
desktop.close()
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.name != 'nt', reason='Windows desktop object lifetime')
|
||||
def test_external_reference_preserves_completed_result_until_resource_only_cleanup(tmp_path):
|
||||
before = current_desktop_name()
|
||||
|
||||
@@ -10,6 +10,102 @@ from dx_productivity.trial_task_center.batch_resources import LIVE_RESOURCES, cl
|
||||
from dx_productivity.trial_task_center.errors import TaskCenterError
|
||||
|
||||
|
||||
@pytest.mark.parametrize('exits_after_retry', [True, False])
|
||||
def test_batch_close_rechecks_owned_exit_three_times_without_repeating_quit(tmp_path, monkeypatch, exits_after_retry):
|
||||
from dx_productivity.trial_task_center import batch_runtime
|
||||
calls, delays = [], []
|
||||
runtime = BatchCadRuntime(tmp_path, 'execution', desktop_factory=Desktop)
|
||||
runtime._ensure_desktop()
|
||||
process = SimpleNamespace(returncode=None, poll=lambda: process.returncode)
|
||||
|
||||
def close_mentor(*args):
|
||||
calls.append('quit')
|
||||
raise OSError('root exit still pending after forced job stop')
|
||||
|
||||
def advance(seconds):
|
||||
delays.append(seconds)
|
||||
if exits_after_retry and len(delays) == 2:
|
||||
process.returncode = 1
|
||||
|
||||
monkeypatch.setattr(batch_runtime.time, 'sleep', advance)
|
||||
runtime.cad = SimpleNamespace(cad=process, record={'forced_termination': True}, __exit__=close_mentor)
|
||||
runtime.result = 'saved and independently verified'
|
||||
try:
|
||||
with pytest.raises(TaskCenterError, match='root exit still pending'):
|
||||
runtime.close()
|
||||
if exits_after_retry:
|
||||
assert runtime.record['state'] == 'released'
|
||||
assert runtime.record['cad_shutdown']['forced_termination'] is True
|
||||
assert delays == [0.5, 1]
|
||||
else:
|
||||
assert runtime.record['state'] == 'blocked'
|
||||
assert not runtime.desktop.released
|
||||
assert delays == [0.5, 1, 2]
|
||||
assert calls == ['quit']
|
||||
assert runtime.result == 'saved and independently verified'
|
||||
finally:
|
||||
LIVE_RESOURCES.pop(str(runtime.path), None)
|
||||
|
||||
|
||||
def test_restart_rechecks_physical_disappearance_without_replaying_owned_actions(tmp_path, monkeypatch):
|
||||
from dx_productivity.trial_task_center import batch_resources, isolated_desktop
|
||||
runtime = BatchCadRuntime(tmp_path, 'execution', desktop_factory=Desktop)
|
||||
runtime._ensure_desktop()
|
||||
LIVE_RESOURCES.pop(str(runtime.path), None)
|
||||
runtime._save(state='blocked')
|
||||
observed, delays = [], []
|
||||
work = tmp_path / 'uncertain.flag'
|
||||
work.write_bytes(b'original business protection')
|
||||
|
||||
def confirm(name):
|
||||
observed.append(name)
|
||||
if len(observed) < 3:
|
||||
raise OSError('desktop still exists')
|
||||
|
||||
monkeypatch.setattr(isolated_desktop, '_Win32Api', lambda: SimpleNamespace(confirm_desktop_released=confirm))
|
||||
monkeypatch.setattr(batch_resources.time, 'sleep', delays.append)
|
||||
assert cleanup_pending_resources(tmp_path) == ()
|
||||
assert observed == [runtime.desktop.name] * 3
|
||||
assert delays == [0.5, 1]
|
||||
assert work.read_bytes() == b'original business protection'
|
||||
|
||||
|
||||
def test_resource_only_observation_never_closes_a_ready_live_owner(tmp_path):
|
||||
runtime = BatchCadRuntime(tmp_path, 'execution', desktop_factory=Desktop)
|
||||
runtime._ensure_desktop()
|
||||
try:
|
||||
assert cleanup_pending_resources(tmp_path)[0]['state'] == 'ready'
|
||||
assert not runtime.desktop.released
|
||||
finally:
|
||||
runtime.close()
|
||||
|
||||
|
||||
def test_missing_historical_job_exit_blocks_even_when_the_desktop_is_gone(tmp_path, monkeypatch):
|
||||
from dx_productivity.trial_task_center import batch_resources, isolated_desktop
|
||||
|
||||
runtime = BatchCadRuntime(tmp_path, 'execution', desktop_factory=Desktop)
|
||||
runtime._ensure_desktop()
|
||||
LIVE_RESOURCES.pop(str(runtime.path), None)
|
||||
identity = {'pid': 1400, 'creation_time': 'exact'}
|
||||
runtime._save(state='blocked', cad_pid=1400, cad_process=identity, processes=[identity])
|
||||
monkeypatch.setattr(batch_resources, '_process_gone', lambda _: True)
|
||||
monkeypatch.setattr(isolated_desktop, '_Win32Api', lambda: pytest.fail('insufficient Job proof'))
|
||||
assert cleanup_pending_resources(tmp_path)[0]['state'] == 'blocked'
|
||||
|
||||
|
||||
def test_supervised_cleanup_carries_automatic_mode_to_worker(tmp_path):
|
||||
from dx_productivity.trial_task_center.service import TaskCenterService
|
||||
|
||||
service = TaskCenterService.__new__(TaskCenterService)
|
||||
service._supervised = True
|
||||
service._logging = SimpleNamespace(root=tmp_path)
|
||||
calls = []
|
||||
service._supervise = lambda operation, arguments: calls.append((operation, arguments))
|
||||
service.pending_batch_resources = lambda: ()
|
||||
assert service.cleanup_batch_resources(automatic=True) == ()
|
||||
assert calls == [('cleanup_batch_resources', {'automatic': True})]
|
||||
|
||||
|
||||
def test_closed_desktop_rechecks_only_observe_until_external_reference_disappears(tmp_path, monkeypatch):
|
||||
from dx_productivity.trial_task_center.isolated_desktop import PrivateDesktop
|
||||
from dx_productivity.trial_task_center import isolated_desktop, batch_resources
|
||||
|
||||
@@ -7,6 +7,23 @@ import pytest
|
||||
from test_ui_remediation import window
|
||||
|
||||
|
||||
def test_startup_rechecks_isolation_without_using_the_manual_button(window, qtbot, monkeypatch):
|
||||
qtbot.waitUntil(lambda: not window._workers and not window._resource_status.busy)
|
||||
pending = ({'state': 'isolated', 'blocking': False},)
|
||||
monkeypatch.setattr(window.service, 'pending_batch_resources', lambda: pending)
|
||||
modes = []
|
||||
monkeypatch.setattr(window.service, 'cleanup_batch_resources',
|
||||
lambda *, automatic=False: (modes.append(automatic) or ()))
|
||||
monkeypatch.setattr(QMessageBox, 'question', lambda *args, **kwargs: pytest.fail('automatic force prompt'))
|
||||
window._resource_status.records = pending
|
||||
window._resource_status.known = True
|
||||
window._update_gates()
|
||||
assert not window.run_panel.cleanup_resources_button.isEnabled()
|
||||
window._startup_resource_recheck()
|
||||
qtbot.waitUntil(lambda: len(modes) == 1 and not window._workers)
|
||||
assert modes == [True]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('finish_order', ['normal', 'after_confirmation', 'during_confirmation'])
|
||||
@pytest.mark.parametrize('confirmed', [False, True])
|
||||
def test_confirmed_force_runs_after_cleanup_worker_finishes(window, qtbot, monkeypatch, finish_order, confirmed):
|
||||
|
||||
Reference in new issue
Block a user