fix: retry incomplete native window observations within deadlines
This commit is contained in:
1 parent
07206ce0d1
commit
36ff964230
2 files changed
+98
-3
No files matched your search
@@ -127,6 +127,87 @@ def test_success_posts_one_exact_close_and_reports_only_open_check(diagnostic, j
|
||||
assert Session.instances[-1].closed
|
||||
|
||||
|
||||
@pytest.mark.parametrize('incomplete_scan', [1, 2, 3])
|
||||
def test_transient_incomplete_scan_is_retried_without_acting_on_partial_windows(diagnostic, job, monkeypatch, incomplete_scan):
|
||||
job['diagnostic_log_baseline'] = diagnostic.snapshot_diagnostic_logs(job)
|
||||
job['timeout'] = 1
|
||||
write_logs(job)
|
||||
class ClosingSession(Session):
|
||||
closing = False
|
||||
def post(self, hwnd, message):
|
||||
self.posted.append((hwnd, message))
|
||||
self.closing = True
|
||||
monkeypatch.setattr(diagnostic, '_NativeSession', ClosingSession)
|
||||
scans = []
|
||||
def windows(pid):
|
||||
scans.append(True)
|
||||
if len(scans) == incomplete_scan:
|
||||
raise RuntimeError('DIAGNOSTIC_WINDOW_LIMIT: window scan exceeded 0.2s')
|
||||
if Session.instances[-1].closing:
|
||||
Session.instances[-1].alive = False
|
||||
return []
|
||||
return [frame(job)]
|
||||
monkeypatch.setattr(diagnostic, '_windows', windows)
|
||||
events = []
|
||||
result = diagnostic.check_target_window(job, 42, emit=lambda **event:events.append(event), error_reader=lambda:None)
|
||||
assert result['status'] == 'PASS'
|
||||
assert Session.instances[-1].posted == [(10, 0x10)]
|
||||
assert any(e['stage'] == 'diagnostic_window_retry' for e in events)
|
||||
|
||||
|
||||
def test_incomplete_scans_keep_original_open_deadline_and_never_close(diagnostic, job, monkeypatch):
|
||||
job['diagnostic_log_baseline'] = diagnostic.snapshot_diagnostic_logs(job)
|
||||
monkeypatch.setattr(diagnostic, '_NativeSession', Session)
|
||||
calls = []
|
||||
def windows(pid):
|
||||
calls.append(True)
|
||||
raise RuntimeError('DIAGNOSTIC_WINDOW_LIMIT: window scan exceeded 0.2s')
|
||||
monkeypatch.setattr(diagnostic, '_windows', windows)
|
||||
with pytest.raises(RuntimeError, match='DIAGNOSTIC_WINDOW_LIMIT'):
|
||||
diagnostic.check_target_window(job, 42, emit=lambda **event:None, error_reader=lambda:None)
|
||||
assert len(calls) <= 3
|
||||
assert Session.instances[-1].posted == []
|
||||
|
||||
|
||||
def test_cancel_during_incomplete_scan_stops_retry_without_close(diagnostic, job, monkeypatch):
|
||||
job['diagnostic_log_baseline'] = diagnostic.snapshot_diagnostic_logs(job)
|
||||
job['timeout'] = 10
|
||||
cancel = Path(job['root']).parent/'cancel-scan'
|
||||
job['cancel_signal'] = str(cancel)
|
||||
monkeypatch.setattr(diagnostic, '_NativeSession', Session)
|
||||
calls = []
|
||||
def windows(pid):
|
||||
calls.append(True)
|
||||
cancel.touch()
|
||||
raise RuntimeError('DIAGNOSTIC_WINDOW_LIMIT: window scan exceeded 0.2s')
|
||||
monkeypatch.setattr(diagnostic, '_windows', windows)
|
||||
with pytest.raises(RuntimeError, match='VERIFY_CANCELLED'):
|
||||
diagnostic.check_target_window(job, 42, emit=lambda **event:None, error_reader=lambda:None)
|
||||
assert len(calls) == 1 and Session.instances[-1].posted == []
|
||||
|
||||
|
||||
def test_incomplete_close_scan_cannot_extend_thirty_second_deadline(diagnostic, job, monkeypatch):
|
||||
job['diagnostic_log_baseline'] = diagnostic.snapshot_diagnostic_logs(job)
|
||||
write_logs(job)
|
||||
clock, offset = diagnostic.time.monotonic, [0]
|
||||
monkeypatch.setattr(diagnostic.time, 'monotonic', lambda:clock()+offset[0])
|
||||
class ClosingSession(Session):
|
||||
closing = False
|
||||
def post(self, hwnd, message):
|
||||
self.posted.append((hwnd, message))
|
||||
self.closing = True
|
||||
monkeypatch.setattr(diagnostic, '_NativeSession', ClosingSession)
|
||||
def windows(pid):
|
||||
if Session.instances[-1].closing:
|
||||
offset[0] = 31
|
||||
raise RuntimeError('DIAGNOSTIC_WINDOW_LIMIT: window scan exceeded 0.2s')
|
||||
return [frame(job)]
|
||||
monkeypatch.setattr(diagnostic, '_windows', windows)
|
||||
with pytest.raises(RuntimeError, match='DIAGNOSTIC_WINDOW_LIMIT'):
|
||||
diagnostic.check_target_window(job, 42, emit=lambda **event:None, error_reader=lambda:None)
|
||||
assert Session.instances[-1].posted == [(10, 0x10)]
|
||||
|
||||
|
||||
def test_transient_startup_window_cannot_abort_before_target_is_loaded(diagnostic, job, monkeypatch):
|
||||
job['diagnostic_log_baseline'] = diagnostic.snapshot_diagnostic_logs(job)
|
||||
write_logs(job)
|
||||
|
||||
Reference in new issue
Block a user