fix: retry catalog when the blocking process exits

This commit is contained in:
阿白叔 committed 2026-11-25 12:03:05 +08:00
1 parent 75612cd4da
commit b015827e97
2 files changed
+37 -5

No files matched your search

+4 -5
View File
@@ -1543,7 +1543,7 @@ class MainWindow(QWidget):
def scan():
from cbb_refresh_verify.native_management import NativeOperationError
from cbb_refresh_verify.owner_probe import query_owners
from cbb_refresh_verify.owner_probe import snapshot_process_ids
try:
return attempt(root)
@@ -1556,13 +1556,12 @@ class MainWindow(QWidget):
while time.monotonic() < deadline:
context.check_active()
try:
owners = query_owners(('LibraryManager.exe',),
timeout_seconds=min(2, max(.1, deadline - time.monotonic())))
except (OSError, RuntimeError):
owners = snapshot_process_ids('LibraryManager.exe')
except OSError:
context.stop.wait(1)
continue
context.check_active()
if not owners or blockers and blockers.isdisjoint(owner['pid'] for owner in owners):
if not owners or blockers and blockers.isdisjoint(owners):
return attempt(root/'retry')
context.stop.wait(1)
context.check_active()
+33
View File
@@ -223,6 +223,39 @@ def test_catalog_progress_and_pending_preview_are_visible(qtbot, tmp_path, monke
window.pool.waitForDone(6000)
def test_catalog_retries_when_exact_manager_pid_exits(qtbot, tmp_path, monkeypatch):
from cbb_refresh_verify import owner_probe
from cbb_refresh_verify.management import Catalog, CatalogEntry
from cbb_refresh_verify.models import CbbRecord, LibraryReadResult
from test_issue15_ui_integration import load, window_for
calls = []
def catalog(library, evidence):
calls.append(evidence)
if len(calls) == 1:
raise native.NativeOperationError('LIBRARY_MANAGER_BUSY: PID 123', safe_to_continue=True,
blocking_manager_pids=(123,))
return Catalog(library, 1, (CatalogEntry('A', 'Logical-Physical'),))
monkeypatch.setattr(owner_probe, 'snapshot_process_ids', lambda _: [456])
def unavailable(*args, **kwargs):
raise RuntimeError('OWNER_QUERY_TIMEOUT')
monkeypatch.setattr(owner_probe, 'query_owners', unavailable)
window = window_for(qtbot, tmp_path, monkeypatch,
reader=lambda _: LibraryReadResult((CbbRecord('A', 'LP'),), directory_count=1),
catalog_reader=catalog, status_refresher=lambda names, _: dict.fromkeys(names, 'READY'))
try:
load(window, qtbot)
qtbot.waitUntil(lambda: window.ready_names == {'A'}, timeout=1500)
assert calls == [calls[0], calls[0] / 'retry']
finally:
window._cancel_catalog_read()
window.pool.waitForDone(6000)
def test_timed_out_catalog_can_refresh_already_registered_status_only(qtbot, tmp_path, monkeypatch):
from cbb_refresh_verify.management import Catalog, CatalogEntry
from cbb_refresh_verify.models import CbbRecord, LibraryReadResult