32 lines
1.4 KiB
Python
32 lines
1.4 KiB
Python
import json
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.mark.parametrize('cancel,gate_present', [(False, False), (True, False), (True, True)])
|
|
def test_worker_waits_for_cold_agent_but_cancellation_never_opens_pcb(tmp_path, monkeypatch, cancel, gate_present):
|
|
from cbb_refresh_verify import mentor_adapter as adapter
|
|
import pythoncom
|
|
gate, stop = tmp_path/'start.signal', tmp_path/'cancel.signal'
|
|
if gate_present: gate.touch()
|
|
if cancel: stop.touch()
|
|
clock, opened = [0.0], []
|
|
def advance(seconds):
|
|
clock[0] += seconds
|
|
if not cancel and clock[0] >= 20: gate.touch()
|
|
monkeypatch.setattr(adapter, 'time', SimpleNamespace(monotonic=lambda: clock[0], sleep=advance,
|
|
strftime=lambda *_: 'test'))
|
|
monkeypatch.setattr(pythoncom, 'CoInitialize', lambda: None)
|
|
monkeypatch.setattr(pythoncom, 'CoUninitialize', lambda: None)
|
|
monkeypatch.setattr(adapter, 'execute_job', lambda *args: opened.append(True) or {'status': 'PASS'})
|
|
job = tmp_path/'request.json'
|
|
job.write_text(json.dumps({'root': str(tmp_path), 'block_name': 'fixture',
|
|
'start_gate': str(gate), 'cancel_signal': str(stop)}), encoding='utf-8')
|
|
result = adapter.worker_main(job)
|
|
assert result == (1 if cancel else 0)
|
|
assert opened == ([] if cancel else [True])
|
|
if cancel:
|
|
outcome = json.loads((tmp_path/'outcome.json').read_text('utf-8'))
|
|
assert 'VERIFY_CANCELLED' in outcome['stderr']
|