92 lines
4.7 KiB
Python
92 lines
4.7 KiB
Python
import time
|
|
from threading import Event
|
|
from test_independent_verification_intake import service
|
|
from test_independent_verification_runner import imported
|
|
from test_native_cli_netlist import graph
|
|
|
|
|
|
def wait_idle(service):
|
|
deadline=time.monotonic()+5
|
|
while service.busy and time.monotonic()<deadline:time.sleep(.01)
|
|
assert not service.busy
|
|
|
|
|
|
def test_start_idempotency_and_frozen_members_do_not_swallow_new_version(service,tmp_path,monkeypatch):
|
|
from dx_productivity.trial_task_center import netlist_verification
|
|
entered=Event();release=Event();calls=[]
|
|
def export(capture,output,*,stop_event):
|
|
calls.append(str(output));entered.set();release.wait(3);output.mkdir(parents=True,exist_ok=True)
|
|
return {'status':'success','complete':True,'graph':graph(output),'outputs':{}}
|
|
monkeypatch.setattr(netlist_verification,'_export_saved_capture',export)
|
|
task,item=imported(service,tmp_path)
|
|
first=service.start(task,selection=None,request_id='run')
|
|
assert entered.wait(2)
|
|
assert service.start(task,selection=None,request_id='run')==first
|
|
payload=service.repo.revision(item,1)['payload']
|
|
newer={k:v for k,v in payload.items() if k not in {'input_state','payload_digest'}};newer['input_version']=2
|
|
service.publish_inputs(task,(newer,),submission_id='new')
|
|
release.set();wait_idle(service)
|
|
assert len(calls)==2 and service.read_item(item)['status']=='waiting'
|
|
assert service.read_item(item,version=1)['status']=='consistent'
|
|
|
|
|
|
def test_stop_during_export_is_cancelled_and_rerun_is_new_generation(service,tmp_path,monkeypatch):
|
|
from dx_productivity.trial_task_center import netlist_verification
|
|
entered=Event()
|
|
def slow(capture,output,*,stop_event):
|
|
entered.set();stop_event.wait(3)
|
|
return {'status':'cancelled','complete':False,'reason':'stopped'}
|
|
monkeypatch.setattr(netlist_verification,'_export_saved_capture',slow)
|
|
task,item=imported(service,tmp_path)
|
|
run=service.start(task,selection=None,request_id='start');assert entered.wait(2)
|
|
service.stop(run['run_id'],request_id='stop');wait_idle(service)
|
|
assert service.read_item(item)['status']=='stopped'
|
|
def normal(capture,output,*,stop_event):
|
|
output.mkdir(parents=True,exist_ok=True)
|
|
return {'status':'success','complete':True,'graph':graph(output),'outputs':{}}
|
|
monkeypatch.setattr(netlist_verification,'_export_saved_capture',normal)
|
|
service.rerun(item,1,request_id='again');wait_idle(service)
|
|
assert service.read_item(item)['attempt']['generation']==2
|
|
|
|
|
|
def test_recovery_never_automatically_runs_and_unknown_owner_blocks(service,tmp_path):
|
|
task,item=imported(service,tmp_path)
|
|
attempt=service.repo.create_attempt(item,1,request_id='lost')
|
|
service.repo.claim(attempt['attempt_id'],owner_id='lost-owner')
|
|
result=service.recover()
|
|
assert result['blocked']==1 and not service.busy
|
|
assert service.repo.attempt(attempt['attempt_id'])['state']=='stopping'
|
|
assert service.read_item(item)['verdict'] is None
|
|
|
|
|
|
def test_durable_stop_wins_race_with_final_result_commit(service,tmp_path,monkeypatch):
|
|
from dx_productivity.trial_task_center import netlist_verification
|
|
task,item=imported(service,tmp_path)
|
|
def native(capture,output,*,stop_event):
|
|
output.mkdir(parents=True,exist_ok=True)
|
|
return {'status':'success','complete':True,'graph':graph(output),'outputs':{}}
|
|
monkeypatch.setattr(netlist_verification,'_export_saved_capture',native)
|
|
finish=service.repo.finish
|
|
def stop_before_commit(attempt_id,*,generation,result):
|
|
if result.get('attempt_state')=='succeeded':
|
|
attempt=service.repo.attempt(attempt_id)
|
|
service.stop(attempt['run_id'],request_id='race-stop')
|
|
return finish(attempt_id,generation=generation,result=result)
|
|
monkeypatch.setattr(service.repo,'finish',stop_before_commit)
|
|
service.start(task,request_id='run');wait_idle(service)
|
|
assert service.read_item(item)['status']=='stopped'
|
|
|
|
|
|
def test_storage_failure_pauses_dispatcher_without_replaying_forever(service,tmp_path,monkeypatch):
|
|
from dx_productivity.trial_task_center import netlist_verification
|
|
task,item=imported(service,tmp_path);calls=[]
|
|
def native(capture,output,*,stop_event):
|
|
output.mkdir(parents=True,exist_ok=True)
|
|
return {'status':'success','complete':True,'graph':graph(output),'outputs':{}}
|
|
def unavailable(*args,**kwargs):calls.append(1);raise OSError('storage unavailable')
|
|
monkeypatch.setattr(netlist_verification,'_export_saved_capture',native)
|
|
monkeypatch.setattr(service.repo,'finish',unavailable)
|
|
service.start(task,request_id='run');wait_idle(service)
|
|
assert service.control.closing and len(calls)<=2
|
|
assert (service.data_root/'verification/engine-paused.json').is_file()
|