Files

101 lines
4.4 KiB
Python

from threading import Event,Thread
def test_normal_verify_batch_yields_after_complete_item(qtbot,tmp_path,monkeypatch):
from test_ui_filters import load_window
from cbb_refresh_verify.verify_runner import VerifyResult
started,release,waiting=Event(),Event(),Event()
order=[]
def verify(request):
order.append(request.block_name)
if request.block_name=='Beta':started.set();release.wait(5)
return VerifyResult('FAIL',stderr='independent failed item',safe_to_continue=True)
window=load_window(qtbot,tmp_path,monkeypatch,verifier=verify)
window._run(['Beta','Gamma'])
qtbot.waitUntil(started.is_set)
other=Thread(target=lambda:window.native_queue.run(lambda:order.append('other'),waiting=waiting.set))
other.start()
try:
assert waiting.wait(1)
release.set()
qtbot.waitUntil(lambda:not window.busy,timeout=10000)
other.join(2)
assert order==['Beta','other','Gamma']
finally:release.set();other.join(5)
def test_management_cancel_between_items_keeps_completed_results(tmp_path,monkeypatch):
from cbb_refresh_verify import management
from cbb_refresh_verify.operation_queue import QueueCancelled
from dataclasses import replace
request=management.ManagementRequest('remove',tmp_path/'lib.lmc','A')
def run(req,**kwargs):
return management.ManagementResult(req.operation,req.library,req.name,req.partition,None,False,
'complete','REMOVED',True)
monkeypatch.setattr(management,'run_management',run)
def execute(req,action):
if req.name=='B':raise QueueCancelled('cancelled waiting for native slot')
return action()
results=management.run_management_batch([request,replace(request,name='B')],item_executor=execute)
assert [r.status for r in results]==['REMOVED','CANCELLED']
assert all(r.safe_to_continue for r in results)
def test_cancelled_verify_keeps_summary_without_queueing_cancelled_refresh(qtbot,tmp_path,monkeypatch):
from test_ui_filters import load_window
from cbb_refresh_verify.verify_runner import VerifyResult
calls=[]
def verify(req):
calls.append(req.block_name)
window.stop.set()
return VerifyResult('CANCELLED',safe_to_continue=True)
window=load_window(qtbot,tmp_path,monkeypatch,verifier=verify)
window._run(['Beta','Gamma'])
qtbot.waitUntil(lambda:not window.busy,timeout=5000)
assert calls==['Beta']
assert window.summary is not None
assert '队列未执行 1' in window.summary.detailedText()
def test_verify_failure_recheck_finishes_before_yielding_native_queue(qtbot,tmp_path,monkeypatch):
from test_ui_filters import load_window
from cbb_refresh_verify.verify_runner import VerifyResult
from cbb_refresh_verify import operation_lifecycle
from dataclasses import replace
window=load_window(qtbot,tmp_path,monkeypatch,
verifier=lambda req:VerifyResult('FAIL',safe_to_continue=False))
active=[];seen=[]
def queued(action, **kwargs):
def run():
active.append(True)
try:return action()
finally:active.pop()
return run
def recheck(library,block,result,**kwargs):
seen.append(bool(active))
return replace(result,safe_to_continue=True)
monkeypatch.setattr(window,'_queued_action',queued)
monkeypatch.setattr(operation_lifecycle,'recheck_failed_release',recheck)
window._run(['Beta'])
qtbot.waitUntil(lambda:not window.busy,timeout=5000)
assert seen==[True]
def test_management_failure_recheck_finishes_before_yielding_native_queue(tmp_path,monkeypatch):
from cbb_refresh_verify import management,operation_lifecycle
from dataclasses import replace
request=management.ManagementRequest('remove',tmp_path/'lib.lmc','A')
monkeypatch.setattr(management,'run_management',lambda req,**kw:management.ManagementResult(
req.operation,req.library,req.name,req.partition,None,False,'complete','BLOCKED',False))
active=[];seen=[]
def item(req,action):
active.append(True)
try:return action()
finally:active.pop()
def recheck(library,block,result,**kwargs):
seen.append(bool(active))
return replace(result,safe_to_continue=True)
monkeypatch.setattr(operation_lifecycle,'recheck_failed_release',recheck)
management.run_management_batch([request],item_executor=item)
assert seen==[True]