fix: preserve a queued retry while an identified Mentor save runs
This commit is contained in:
1 parent
6aed02d26b
commit
2722d09b59
3 files changed
+32
-3
No files matched your search
@@ -322,6 +322,7 @@ def _reconcile(path, root, handles, stack, *, release=True, stop=None):
|
||||
from .residual_sessions import _handle_identity, _force_ownership
|
||||
session, state, processes = _session(path, root)
|
||||
active = False
|
||||
active_helper = False
|
||||
for identity in processes:
|
||||
if identity.get('role') == 'supervisor':
|
||||
continue
|
||||
@@ -352,8 +353,11 @@ def _reconcile(path, root, handles, stack, *, release=True, stop=None):
|
||||
handle = handles[key]
|
||||
if handle is not None and win32event.WaitForSingleObject(handle, 0) != win32con.WAIT_OBJECT_0:
|
||||
active = True
|
||||
active_helper |= identity.get('role') == 'helper'
|
||||
if active:
|
||||
return _result('ACTIVE', '原生调用尚未确认返回', session=session, state=state)
|
||||
saving = active_helper and session.get('operation') == 'verify' and state.get('phase') == 'NATIVE_CALL'
|
||||
detail = 'Mentor 正在保存,结束后自动复核释放。' if saving else '原生调用尚未确认返回'
|
||||
return {**_result('ACTIVE', detail, session=session, state=state), 'active_save': saving}
|
||||
if not release:
|
||||
return {**_result('UNCONFIRMED', '记录中的进程已退出,需确认库占用已释放',
|
||||
session=session, state=state), 'processes_exited': True}
|
||||
|
||||
@@ -1598,7 +1598,8 @@ def wait_for_batch_release(request, context, *, progress=None, timeout_seconds=1
|
||||
library = request.lmc_file
|
||||
if not Path(library).is_file():
|
||||
return
|
||||
deadline = time.monotonic() + timeout_seconds
|
||||
started = time.monotonic()
|
||||
deadline = started + timeout_seconds
|
||||
previous = None
|
||||
while True:
|
||||
context.check_active()
|
||||
@@ -1612,7 +1613,12 @@ def wait_for_batch_release(request, context, *, progress=None, timeout_seconds=1
|
||||
context.check_active()
|
||||
return
|
||||
else:
|
||||
detail = library_wait_reason(library)
|
||||
sessions = retained_session_states(library)
|
||||
if any(value.get('active_save') is True for value in sessions):
|
||||
deadline = max(deadline, started + request.timeout_seconds)
|
||||
detail = 'Mentor 正在保存,结束后自动复核释放。'
|
||||
else:
|
||||
detail = library_wait_reason(library)
|
||||
if detail != previous:
|
||||
_notify_progress(progress, {'stage': 'waiting_native_slot', 'library': str(library),
|
||||
'retained': True, 'detail': detail})
|
||||
|
||||
@@ -27,3 +27,22 @@ def test_batch_admission_reports_resource_at_entry(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr('cbb_refresh_verify.library_lock.recheck_previous_release', busy)
|
||||
with pytest.raises(QueueUnavailable, match='共享符号库 icdb.dat 仍在使用'):
|
||||
verify_runner.wait_for_batch_release(request, BatchTaskContext(str(library)), timeout_seconds=0)
|
||||
|
||||
|
||||
|
||||
def test_batch_waits_for_recorded_save_past_ordinary_release_deadline(tmp_path, monkeypatch):
|
||||
from cbb_refresh_verify import verify_runner
|
||||
from cbb_refresh_verify import session_record
|
||||
library = tmp_path/'library.lmc'
|
||||
library.touch()
|
||||
request = VerifyRequest(library, 'Next', tmp_path/'evidence')
|
||||
context = BatchTaskContext(str(library))
|
||||
waiting = []
|
||||
monkeypatch.setattr(session_record, 'library_available', lambda *a, **k: bool(waiting))
|
||||
monkeypatch.setattr(session_record, 'retained_session_states', lambda *_: [
|
||||
{'status': 'ACTIVE', 'phase': 'NATIVE_CALL', 'block': 'Previous',
|
||||
'active_save': True}])
|
||||
monkeypatch.setattr('cbb_refresh_verify.library_lock.recheck_previous_release', lambda *a, **k: None)
|
||||
monkeypatch.setattr(context.stop, 'wait', lambda interval: waiting.append(interval))
|
||||
verify_runner.wait_for_batch_release(request, context, timeout_seconds=0)
|
||||
assert len(waiting) == 1
|
||||
Reference in new issue
Block a user