feat(supabase): verification retry by effective cause
resource_limit (intrinsic to the frozen input: frame, input or output cap, SIGXCPU, SIGABRT, SIGSYS) and verdict_refused close the round at the first occurrence; timeout, unavailable (now also an external SIGKILL) and lease_expired keep the 2/5/10/20 s retries up to five attempts. pgTAP 021: 89; sandbox case k closes at attempt 1.
This commit is contained in:
1 parent
c98a9c8f82
commit
a5844b9d56
8 files changed
+156
-46
No files matched your search
@@ -4,7 +4,7 @@
|
||||
-- nothing), technical failures up to the attempt limit with their progressive
|
||||
-- delay (`not_before`), dead leases.
|
||||
begin;
|
||||
select plan(72);
|
||||
select plan(89);
|
||||
|
||||
insert into auth.users (id, email, email_confirmed_at) values
|
||||
('f0000000-0000-0000-0000-000000000001', 'own@vj.local', now()),
|
||||
@@ -239,17 +239,19 @@ update public.anatomical_sheet_reviews set locked_at = now() - interval '11 minu
|
||||
set local role service_role; select pg_temp.worker();
|
||||
select is((select attempts from public.claim_sheet_verifications(1)), 4, 'a dead lease is claimed again');
|
||||
select is(pg_temp.status('r3'), 'verifying/-/verification.worker.lease_expired', 'the interruption is recorded');
|
||||
select is(public.fail_sheet_verification(pg_temp.id('r3'), pg_temp.token('r3'), 'verification.worker.resource_limit'), 'retry', 'a fourth failure is retried');
|
||||
select is(public.fail_sheet_verification(pg_temp.id('r3'), pg_temp.token('r3'), 'verification.worker.timeout'), 'retry', 'a fourth failure is retried');
|
||||
select ok(pg_temp.delayed('r3', interval '20 seconds'), 'after attempt 4 the retry waits 20 s');
|
||||
select pg_temp.set_not_before('r3', interval '-1 second');
|
||||
select is((select attempts from public.claim_sheet_verifications(1)), 5, 'claimed after 20 s: fifth attempt');
|
||||
-- At the limit, a technical failure closes the round unavailable, delay cleared.
|
||||
select pg_temp.set_not_before('r3', interval '1 hour');
|
||||
select is(public.fail_sheet_verification(pg_temp.id('r3'), pg_temp.token('r3'), 'verification.worker.resource_limit'), 'unavailable', 'the last attempt closes the round');
|
||||
select is(pg_temp.status('r3'), 'verification_failed/unavailable/verification.worker.resource_limit', 'round closed unavailable with the last code');
|
||||
select is(public.fail_sheet_verification(pg_temp.id('r3'), pg_temp.token('r3'), 'verification.worker.unavailable'), 'unavailable', 'the last attempt closes the round');
|
||||
select is(pg_temp.status('r3'), 'verification_failed/unavailable/verification.worker.unavailable', 'round closed unavailable with the last code');
|
||||
select ok(pg_temp.not_before_is_null('r3'), 'the fifth failure clears the delay');
|
||||
reset role;
|
||||
select ok(exists (select 1 from audit.audit_logs where action = 'anatomical_sheet_review.verification_attempt_failed' and resource_id = pg_temp.id('r3')), 'attempt failure audited');
|
||||
select ok(exists (select 1 from audit.audit_logs where action = 'anatomical_sheet_review.verification_failed' and resource_id = pg_temp.id('r3')
|
||||
and metadata ->> 'closed_by' = 'attempt_limit'), 'a transient code closes at the limit: closed_by attempt_limit');
|
||||
|
||||
-- 8. A dead lease at the limit is closed by the next claim.
|
||||
set local role authenticated;
|
||||
@@ -262,5 +264,46 @@ set local role service_role; select pg_temp.worker();
|
||||
select is((select count(*)::int from public.claim_sheet_verifications(5)), 0, 'a round at the limit is not claimed');
|
||||
select is(pg_temp.status('r4'), 'verification_failed/unavailable/verification.worker.lease_expired', 'its dead lease closes it unavailable');
|
||||
|
||||
-- 9. Definitive codes close the round at the first occurrence; transient
|
||||
-- codes keep their retry. Rounds are sequential: each follows a closed one.
|
||||
set local role authenticated;
|
||||
select pg_temp.act('f0000000-0000-0000-0000-00000000000e','f1000000-0000-0000-0000-00000000000e');
|
||||
select public.save_sheet_draft(pg_temp.id('v1'), 4, pg_temp.doc(pg_temp.id('asset'),'VJ5'), 'five');
|
||||
insert into pg_temp.k select 'r5', public.submit_sheet_review(pg_temp.id('v1'), 5, 'five');
|
||||
reset role;
|
||||
set local role service_role; select pg_temp.worker();
|
||||
select is((select count(*)::int from public.claim_sheet_verifications(1)), 1, 'fifth round claimed');
|
||||
select is(public.fail_sheet_verification(pg_temp.id('r5'), pg_temp.token('r5'), 'verification.worker.resource_limit'), 'unavailable', 'resource_limit at attempt 1 closes the round');
|
||||
select is(pg_temp.status('r5'), 'verification_failed/unavailable/verification.worker.resource_limit', 'closed unavailable, code kept');
|
||||
select ok(pg_temp.not_before_is_null('r5'), 'a definitive closure sets no delay');
|
||||
select is((select count(*)::int from public.claim_sheet_verifications(10)), 0, 'a definitively closed round is never claimed again');
|
||||
reset role;
|
||||
select ok(exists (select 1 from audit.audit_logs where action = 'anatomical_sheet_review.verification_failed' and resource_id = pg_temp.id('r5')
|
||||
and metadata ->> 'closed_by' = 'definitive' and metadata ->> 'attempts' = '1'), 'closure audited as definitive at attempt 1');
|
||||
|
||||
set local role authenticated;
|
||||
select pg_temp.act('f0000000-0000-0000-0000-00000000000e','f1000000-0000-0000-0000-00000000000e');
|
||||
select public.save_sheet_draft(pg_temp.id('v1'), 5, pg_temp.doc(pg_temp.id('asset'),'VJ6'), 'six');
|
||||
insert into pg_temp.k select 'r6', public.submit_sheet_review(pg_temp.id('v1'), 6, 'six');
|
||||
reset role;
|
||||
set local role service_role; select pg_temp.worker();
|
||||
select is((select count(*)::int from public.claim_sheet_verifications(1)), 1, 'sixth round claimed');
|
||||
select is(public.fail_sheet_verification(pg_temp.id('r6'), pg_temp.token('r6'), 'verification.worker.verdict_refused'), 'unavailable', 'verdict_refused at attempt 1 closes the round');
|
||||
select is(pg_temp.status('r6'), 'verification_failed/unavailable/verification.worker.verdict_refused', 'closed unavailable, code kept');
|
||||
select is((select count(*)::int from public.claim_sheet_verifications(10)), 0, 'a refused verdict is never claimed again');
|
||||
|
||||
set local role authenticated;
|
||||
select pg_temp.act('f0000000-0000-0000-0000-00000000000e','f1000000-0000-0000-0000-00000000000e');
|
||||
select public.save_sheet_draft(pg_temp.id('v1'), 6, pg_temp.doc(pg_temp.id('asset'),'VJ7'), 'seven');
|
||||
insert into pg_temp.k select 'r7', public.submit_sheet_review(pg_temp.id('v1'), 7, 'seven');
|
||||
reset role;
|
||||
set local role service_role; select pg_temp.worker();
|
||||
select is((select count(*)::int from public.claim_sheet_verifications(1)), 1, 'seventh round claimed');
|
||||
select is(public.fail_sheet_verification(pg_temp.id('r7'), gen_random_uuid(), 'verification.worker.resource_limit'), 'stale', 'a definitive code with another token is stale');
|
||||
select is(public.fail_sheet_verification(pg_temp.id('r7'), null, 'verification.worker.verdict_refused'), 'stale', 'a definitive code with a null token is stale');
|
||||
select is(pg_temp.status('r7'), 'verifying/-/-', 'a stale definitive failure writes nothing');
|
||||
select is(public.fail_sheet_verification(pg_temp.id('r7'), pg_temp.token('r7'), 'verification.worker.unavailable'), 'retry', 'unavailable at attempt 1 is retried');
|
||||
select ok(pg_temp.delayed('r7', interval '2 seconds'), 'after attempt 1 the retry waits 2 s');
|
||||
|
||||
select * from finish();
|
||||
rollback;
|
||||
Reference in new issue
Block a user