Drop the retry around the queue's dedup race, fixed upstream
`_score_after_change` tried three times because `Jobs.enqueue` could re-raise an IntegrityError when the live job finished between its insert and its lookup. The queue now does both in one BEGIN IMMEDIATE transaction (boilerplate a1c6f0d), so the workaround and its test go. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
2e4624cbc4
commit
92466e2cd4
3 files changed
+11
-40
No files matched your search
@@ -5,7 +5,6 @@ worker beyond starting and stopping it with the app."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import sqlite3
|
||||
from collections.abc import Iterator
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from pathlib import Path
|
||||
@@ -547,22 +546,6 @@ def test_a_score_asked_for_during_a_run_is_one_follow_up_after_it(queue: Any) ->
|
||||
assert after.id not in (first.id, follow.id) and after.dedup_key == "score"
|
||||
|
||||
|
||||
def test_score_after_change_retries_the_queues_dedup_race(
|
||||
queue: Any, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""`Jobs.enqueue` re-raises the UNIQUE failure when the live job it
|
||||
collided with finishes before it reads it back."""
|
||||
real, calls = queue.enqueue, []
|
||||
|
||||
def racy(*args: Any, **kwargs: Any) -> Any:
|
||||
calls.append(args)
|
||||
if len(calls) == 1:
|
||||
raise sqlite3.IntegrityError("UNIQUE constraint failed: jobs.dedup_key")
|
||||
return real(*args, **kwargs)
|
||||
|
||||
monkeypatch.setattr(queue, "enqueue", racy)
|
||||
assert _score_after_change(queue) is not None and len(calls) == 2
|
||||
|
||||
|
||||
def test_post_score_answers_with_the_job_to_wait_for(client: TestClient, queue: Any) -> None:
|
||||
res = client.post("/api/score")
|
||||
assert res.status_code == 200
|
||||
|
||||
Reference in new issue
Block a user