Fix queue review findings Refs #6
This commit is contained in:
@@ -230,6 +230,90 @@ def test_worker_claimed_failure_retries_item(tmp_path, monkeypatch):
|
||||
assert imported == 0
|
||||
assert updated["state"] == "retrying"
|
||||
assert updated["attempt_count"] == 1
|
||||
assert updated["next_retry_at"] is not None
|
||||
|
||||
|
||||
def test_startup_releases_stale_claims_from_previous_worker(tmp_path, monkeypatch):
|
||||
main, _download, _movies, _tv = configure_main(tmp_path, monkeypatch)
|
||||
row = main.state.upsert_queue_item(source_type="manual", source_id="a", name="A.mkv", state="ready")
|
||||
main.state.claim_queue_item(row["id"], "old-worker", {"ready"})
|
||||
|
||||
main.ensure_worker_running()
|
||||
updated = main.state.get_queue_item(row["id"])
|
||||
main.stop_worker()
|
||||
|
||||
assert updated["state"] == "retrying"
|
||||
assert updated["claimed_by"] is None
|
||||
|
||||
|
||||
def test_run_now_conflicts_when_item_is_claimed(tmp_path, monkeypatch):
|
||||
main, _download, _movies, _tv = configure_main(tmp_path, monkeypatch)
|
||||
row = main.state.upsert_queue_item(source_type="manual", source_id="a", name="A.mkv", state="ready")
|
||||
main.state.claim_queue_item(row["id"], "other-worker", {"ready"})
|
||||
|
||||
try:
|
||||
main.queue_item_action(row["id"], main.QueueItemActionRequest(action="run-now"))
|
||||
except main.HTTPException as exc:
|
||||
assert exc.status_code == 409
|
||||
else:
|
||||
raise AssertionError("expected HTTPException")
|
||||
|
||||
|
||||
def test_remove_conflicts_when_item_is_claimed(tmp_path, monkeypatch):
|
||||
main, _download, _movies, _tv = configure_main(tmp_path, monkeypatch)
|
||||
row = main.state.upsert_queue_item(source_type="manual", source_id="a", name="A.mkv", state="ready")
|
||||
main.state.claim_queue_item(row["id"], "other-worker", {"ready"})
|
||||
|
||||
try:
|
||||
main.queue_item_action(row["id"], main.QueueItemActionRequest(action="remove"))
|
||||
except main.HTTPException as exc:
|
||||
assert exc.status_code == 409
|
||||
else:
|
||||
raise AssertionError("expected HTTPException")
|
||||
|
||||
|
||||
def test_manual_import_completion_persists_completed_row_and_batch_completion(tmp_path, monkeypatch):
|
||||
main, download, movies, tv = configure_main(tmp_path, monkeypatch)
|
||||
batch = download / "Release"
|
||||
batch.mkdir(parents=True)
|
||||
source = batch / "Done.mkv"
|
||||
source.write_bytes(b"done")
|
||||
created_batch = main.state.add_manual_batch(batch)
|
||||
|
||||
imported = main._import_manual_batches(main.Importer(movies, tv))
|
||||
main.sync_manual_queue()
|
||||
|
||||
assert imported == 1
|
||||
rows = {row["name"]: row for row in main.state.list_queue_items(active_only=False)}
|
||||
assert rows["Done.mkv"]["state"] == "imported"
|
||||
assert main.state.get_queue_item(rows["Done.mkv"]["id"])["state"] == "imported"
|
||||
batch_row = next(batch for batch in main.state.list_manual_batches() if batch["id"] == created_batch["id"])
|
||||
assert batch_row["status"] == "completed"
|
||||
|
||||
|
||||
def test_worker_failure_stops_retrying_after_limit(tmp_path, monkeypatch):
|
||||
main, download, _movies, _tv = configure_main(tmp_path, monkeypatch)
|
||||
batch = download / "Release"
|
||||
batch.mkdir(parents=True)
|
||||
source = batch / "A.mkv"
|
||||
source.write_bytes(b"a")
|
||||
row = main.state.upsert_queue_item(source_type="manual", source_id=str(source), source_path=source, name=source.name, state="ready")
|
||||
|
||||
class BrokenImporter:
|
||||
def import_file(self, *args, **kwargs):
|
||||
raise RuntimeError("boom")
|
||||
|
||||
for _ in range(main.MAX_RETRY_ATTEMPTS):
|
||||
claimed = main.state.claim_queue_item(row["id"], main.WORKER_ID, {"ready", "retrying"})
|
||||
assert claimed is not None
|
||||
main._import_queue_item(claimed, BrokenImporter(), from_worker=True)
|
||||
current = main.state.get_queue_item(row["id"])
|
||||
if current["state"] == "retrying":
|
||||
main.state.mark_queue_item("manual", current["source_id"], "ready", "retry window elapsed")
|
||||
|
||||
updated = main.state.get_queue_item(row["id"])
|
||||
assert updated["state"] == "failed"
|
||||
assert updated["attempt_count"] == main.MAX_RETRY_ATTEMPTS
|
||||
|
||||
|
||||
def test_control_update_runs_configured_command(tmp_path, monkeypatch):
|
||||
|
||||
Reference in New Issue
Block a user