bff590a00f
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
from lyra_worker.claim import claim_next
|
|
from tests.conftest import insert_request
|
|
|
|
|
|
def test_claim_returns_none_when_empty(conn):
|
|
assert claim_next(conn) is None
|
|
|
|
|
|
def test_claim_advances_job_to_matching(conn):
|
|
job_id = insert_request(conn)
|
|
claimed = claim_next(conn)
|
|
assert claimed == job_id
|
|
|
|
with conn.cursor() as cur:
|
|
cur.execute('SELECT state, "currentStage", attempts, "claimedAt" FROM "Job" WHERE id = %s', (job_id,))
|
|
state, stage, attempts, claimed_at = cur.fetchone()
|
|
assert state == "matching"
|
|
assert stage == "match"
|
|
assert attempts == 1
|
|
assert claimed_at is not None
|
|
|
|
|
|
def test_claim_does_not_repick_claimed_job(conn):
|
|
insert_request(conn)
|
|
assert claim_next(conn) is not None
|
|
assert claim_next(conn) is None
|
|
|
|
|
|
def test_claim_skips_paused_jobs(conn):
|
|
paused_job = insert_request(conn, album="Paused Album")
|
|
with conn.cursor() as cur:
|
|
cur.execute('UPDATE "Job" SET paused = true WHERE id = %s', (paused_job,))
|
|
conn.commit()
|
|
unpaused_job = insert_request(conn, album="Live Album")
|
|
|
|
claimed = claim_next(conn)
|
|
assert claimed == unpaused_job # the paused one is skipped
|
|
|
|
# With only the paused job left, nothing is claimable.
|
|
assert claim_next(conn) is None
|