fix: bound slow CAD startup and retain blocked COM diagnostics
This commit is contained in:
1 parent
29ea67c35e
commit
9b2372e389
2 files changed
+40
-1
No files matched your search
@@ -101,7 +101,7 @@ class IsolatedCadSession:
|
||||
probe = self.desktop.start_process(_helper_command('probe', bootstrap, self.cad.pid), env=_child_environment(environment),
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
try:
|
||||
deadline = time.monotonic() + 75
|
||||
deadline = time.monotonic() + 120
|
||||
while probe.poll() is None:
|
||||
self._check_abort()
|
||||
if time.monotonic() >= deadline:
|
||||
@@ -189,6 +189,20 @@ def run_isolated_process(command, timeout, *, abort_event=None, cooperative_abor
|
||||
|
||||
def native_action(action, evidence, expected_pid):
|
||||
"""Runs in a child created with lpDesktop, never in a Python thread switch."""
|
||||
if action != 'probe':
|
||||
return _native_action(action, evidence, expected_pid)
|
||||
# COM startup can block inside a native call, so keep diagnostics outside
|
||||
# the redirected pipes and retain them when the supervisor ends the child.
|
||||
import faulthandler
|
||||
with Path(str(evidence) + '.fault.txt').open('a', encoding='utf-8') as trace:
|
||||
faulthandler.dump_traceback_later(20, repeat=True, file=trace)
|
||||
try:
|
||||
return _native_action(action, evidence, expected_pid)
|
||||
finally:
|
||||
faulthandler.cancel_dump_traceback_later()
|
||||
|
||||
|
||||
def _native_action(action, evidence, expected_pid):
|
||||
import pythoncom
|
||||
import win32com.client
|
||||
import win32gui
|
||||
|
||||
@@ -107,6 +107,31 @@ def test_success_quits_owned_cad_before_releasing_desktop(monkeypatch, tmp_path)
|
||||
assert record['state'] == 'released' and 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)
|
||||
clock = [0.0]
|
||||
monkeypatch.setattr(runtime.time, 'monotonic', lambda: clock[0])
|
||||
monkeypatch.setattr(runtime.time, 'sleep', lambda seconds: clock.__setitem__(0, clock[0] + seconds))
|
||||
original = runtime.PrivateDesktop.start_process
|
||||
def start(self, command, **kwargs):
|
||||
process = original(self, command, **kwargs)
|
||||
if command[0] == 'probe':
|
||||
process.poll = lambda: 0 if ready_after is not None and clock[0] >= ready_after else None
|
||||
return process
|
||||
monkeypatch.setattr(runtime.PrivateDesktop, 'start_process', start)
|
||||
if ready_after is None:
|
||||
with pytest.raises(runtime.PrivateCadStartupError, match='bootstrap timed out'):
|
||||
with runtime.IsolatedCadSession(tmp_path):
|
||||
pytest.fail('unresponsive startup entered project work')
|
||||
assert 119 <= clock[0] <= 121
|
||||
assert ('release', False) in events
|
||||
else:
|
||||
with runtime.IsolatedCadSession(tmp_path):
|
||||
assert clock[0] >= ready_after
|
||||
assert ('release', False) in events
|
||||
|
||||
|
||||
def test_repeated_session_preserves_prior_release_evidence(monkeypatch, tmp_path):
|
||||
fake_desktop(monkeypatch, tmp_path)
|
||||
with runtime.IsolatedCadSession(tmp_path) as first:
|
||||
|
||||
Reference in new issue
Block a user