Files
cbb-refresh-verify-795/tests/test_late_release_continuation.py
T

61 lines
2.9 KiB
Python

import json
from dataclasses import asdict
from pathlib import Path
import pytest
from cbb_refresh_verify.verify_runner import VerifyRequest,VerifyResult,run_batch
@pytest.mark.parametrize('released',[True,False])
def test_batch_rechecks_owned_failure_before_skipping_next_item(tmp_path,monkeypatch,released):
from cbb_refresh_verify import library_lock,session_record
library=tmp_path/'lib.lmc';library.touch()
root=tmp_path/'failure';root.mkdir()
session_record.write_session_record(root/'session.json',dict(operation_id='test',library=str(library),block='A'))
outcome=VerifyResult('FAIL',stderr='original failure',safe_to_continue=False,
evidence_path=root/'result.json',session_record_path=root/'session.json')
calls=[]
monkeypatch.setattr(session_record,'inspect_session_record',lambda *a,**k:dict(status='UNCONFIRMED'))
def proof(*a,**k):
if not released:raise library_lock.LibraryBusy('shared database still occupied')
return dict(status='RELEASE_CONFIRMED',library=str(library),data_recovery_confirmed=False,
lease_state='RELEASED',blocked_resources=[],
resource_scope=dict(scope_state='OBSERVED',library=str(library)))
monkeypatch.setattr(library_lock,'release_retained_library',proof)
def verify(req):
calls.append(req.block_name)
return outcome if req.block_name=='A' else VerifyResult('PASS')
results=run_batch([VerifyRequest(library,n,tmp_path/'evidence') for n in ('A','B')],verifier=verify)
assert results[0].status=='FAIL' and results[0].stderr=='original failure'
assert results[0].safe_to_continue is released
assert calls==(['A','B'] if released else ['A'])
def test_batch_rechecks_admission_after_timeout_and_real_release(tmp_path, monkeypatch):
from cbb_refresh_verify import session_record
from cbb_refresh_verify.operation_queue import QueueUnavailable
library = tmp_path/'first/lib.lmc'
independent = tmp_path/'second/lib.lmc'
occupied = True
admission_calls = []
def available(path):
return Path(path) != library or not occupied
def admit(request, action):
nonlocal occupied
admission_calls.append(request.block_name)
if not available(request.lmc_file):
raise QueueUnavailable(request.lmc_file, timed_out=True)
if request.block_name == 'B':
occupied = False
return action()
monkeypatch.setattr(session_record, '_live_library_available', available)
requests = [VerifyRequest(lmc, name, tmp_path/'evidence')
for name, lmc in [('A', library), ('A2', library), ('B', independent), ('C', library)]]
results = run_batch(requests, verifier=lambda _: VerifyResult('PASS'), item_executor=admit)
assert admission_calls == ['A', 'B', 'C']
assert [result.status for result in results] == ['SKIPPED', 'SKIPPED', 'PASS', 'PASS']
assert results[0].error_category == 'NATIVE_SESSION_PENDING'