Core regression / Python core, intervention UI and release configuration (push) Successful in 12m44s
Core regression / JavaScript syntax (push) Successful in 10s
Core regression / Python core, intervention UI and release configuration (pull_request) Failing after 24m33s
Core regression / JavaScript syntax (pull_request) Successful in 10s
170 lines
9.1 KiB
Python
170 lines
9.1 KiB
Python
import time
|
|
from threading import Event
|
|
import pytest
|
|
from dx_productivity.trial_task_center.errors import TaskCenterError
|
|
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')
|
|
try:
|
|
assert service.start(task,selection=((item,1),),request_id='same-member')==first
|
|
with pytest.raises(TaskCenterError,match='当前校验'):
|
|
service.rerun(item,2,request_id='start-new-version')
|
|
finally:
|
|
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()
|
|
|
|
|
|
def test_other_window_recovery_and_close_do_not_interrupt_live_owner(service,tmp_path,monkeypatch):
|
|
from dx_productivity.trial_task_center.store import TaskStore
|
|
from dx_productivity.trial_task_center.verification.service import VerificationService
|
|
from dx_productivity.trial_task_center import netlist_verification
|
|
entered=Event();release=Event()
|
|
def native(capture,output,*,stop_event):
|
|
entered.set();release.wait(5);output.mkdir(parents=True,exist_ok=True)
|
|
return {'status':'success','complete':True,'graph':graph(output),'outputs':{}}
|
|
monkeypatch.setattr(netlist_verification,'_export_saved_capture',native)
|
|
task,item=imported(service,tmp_path);run=service.start(task,request_id='owner');assert entered.wait(3)
|
|
other_store=TaskStore(service.repo.store.path);other=VerificationService(other_store,service.data_root)
|
|
try:
|
|
recovered=other.recover()
|
|
assert recovered.get('live_owners')==1
|
|
assert service.repo.latest_attempt(item,1)['state']=='running'
|
|
other.start(task,request_id='observe')
|
|
assert not other.busy
|
|
other.begin_shutdown()
|
|
assert not service.repo._one('verification_runs','run_id',run['run_id'])['stop_requested']
|
|
finally:release.set();wait_idle(service);other.begin_shutdown();other_store.close()
|
|
assert service.read_item(item)['status']=='consistent'
|
|
|
|
|
|
def test_stop_from_another_window_is_observed_during_native_export(service,tmp_path,monkeypatch):
|
|
from dx_productivity.trial_task_center.store import TaskStore
|
|
from dx_productivity.trial_task_center.verification.service import VerificationService
|
|
from dx_productivity.trial_task_center import netlist_verification
|
|
entered=Event()
|
|
def native(capture,output,*,stop_event):
|
|
entered.set();stop_event.wait(2)
|
|
return {'status':'cancelled','complete':False}
|
|
monkeypatch.setattr(netlist_verification,'_export_saved_capture',native)
|
|
task,item=imported(service,tmp_path);run=service.start(task,request_id='owner');assert entered.wait(3)
|
|
other_store=TaskStore(service.repo.store.path);other=VerificationService(other_store,service.data_root)
|
|
try:
|
|
other.stop(run['run_id'],request_id='foreign-stop');wait_idle(service)
|
|
assert service.read_item(item)['status']=='stopped'
|
|
finally:other.begin_shutdown();other_store.close()
|
|
|
|
|
|
def test_owner_exit_without_cli_exit_proof_remains_unknown(service,tmp_path,monkeypatch):
|
|
from dx_productivity.trial_task_center.verification import ownership
|
|
task,item=imported(service,tmp_path)
|
|
attempt=service.repo.create_attempt(item,1,request_id='lost')
|
|
service.repo.claim(attempt['attempt_id'],owner_id=service.control.owner_id)
|
|
ownership.write_owner(service,'attempts',attempt['attempt_id'],service.control.owner_id)
|
|
# This includes a reused PID: the original creation identity is gone.
|
|
monkeypatch.setattr(ownership,'_process_gone',lambda identity:True)
|
|
recovered=service.recover()
|
|
assert recovered['blocked']==1 and recovered['published']==0
|
|
assert service.repo.attempt(attempt['attempt_id'])['resource_state']=='unknown'
|
|
|
|
|
|
def test_recovery_publishes_intact_staged_result_without_reexport(service,tmp_path,monkeypatch):
|
|
from dx_productivity.trial_task_center import netlist_verification
|
|
from dx_productivity.trial_task_center.verification.runner import run_attempt
|
|
calls=[]
|
|
def native(capture,output,*,stop_event):
|
|
calls.append(1);output.mkdir(parents=True,exist_ok=True)
|
|
return {'status':'success','complete':True,'graph':graph(output),'outputs':{}}
|
|
monkeypatch.setattr(netlist_verification,'_export_saved_capture',native)
|
|
_,item=imported(service,tmp_path);attempt=service.repo.create_attempt(item,1,request_id='staged')
|
|
with monkeypatch.context() as patch:
|
|
patch.setattr(service.repo,'finish',lambda *args,**kwargs:False)
|
|
assert not run_attempt(service,attempt['attempt_id'],stop_event=Event())['published']
|
|
recovered=service.recover()
|
|
assert recovered['published']==1 and len(calls)==2
|
|
assert service.read_item(item)['status']=='consistent' and not service.busy
|