@@ -519,6 +519,54 @@ async def test_reap_stale_leaves_fresh_claims_alone(jobs):
519519 assert refreshed .status is JobStatus .CLAIMED
520520
521521
522+ # --- prune_dead ---
523+
524+
525+ @pytest .mark .asyncio
526+ async def test_prune_dead_removes_matching_dead_rows (jobs ):
527+ """A dead UPSERT becomes stale once a sibling DELETE has resolved the URI;
528+ prune_dead() removes it so the DLQ stops showing resolved entries."""
529+ job = await jobs .enqueue ("s" , "u" , JobOp .UPSERT )
530+ assert job is not None
531+ claimed = await jobs .claim_next ("w" )
532+ assert claimed is not None
533+ await jobs .mark_dead (claimed .id , "boom" , "w" )
534+
535+ pruned = await jobs .prune_dead ("s" , "u" )
536+ assert pruned == 1
537+ assert await jobs .get_job (job .id ) is None
538+
539+
540+ @pytest .mark .asyncio
541+ async def test_prune_dead_leaves_non_dead_rows_alone (jobs ):
542+ """Queued/claimed/succeeded rows for the same (source, uri) are not
543+ touched — only `dead` is purged."""
544+ queued = await jobs .enqueue ("s" , "u" , JobOp .UPSERT )
545+ assert queued is not None
546+
547+ pruned = await jobs .prune_dead ("s" , "u" )
548+ assert pruned == 0
549+ refreshed = await jobs .get_job (queued .id )
550+ assert refreshed is not None and refreshed .status is JobStatus .QUEUED
551+
552+
553+ @pytest .mark .asyncio
554+ async def test_prune_dead_scoped_to_matching_uri (jobs ):
555+ """Dead rows for other URIs (and other sources) survive."""
556+ j1 = await jobs .enqueue ("s" , "u1" , JobOp .UPSERT )
557+ assert j1 is not None
558+ await jobs .mark_dead ((await jobs .claim_next ("w" )).id , "err" , "w" )
559+
560+ j2 = await jobs .enqueue ("s" , "u2" , JobOp .UPSERT )
561+ assert j2 is not None
562+ await jobs .mark_dead ((await jobs .claim_next ("w" )).id , "err" , "w" )
563+
564+ pruned = await jobs .prune_dead ("s" , "u1" )
565+ assert pruned == 1
566+ assert await jobs .get_job (j1 .id ) is None
567+ assert await jobs .get_job (j2 .id ) is not None
568+
569+
522570# --- release_if_claimed ---
523571
524572
0 commit comments