Intelligence, Advanced Charting & Trading Platform
test(db): ensure revoked oldest pending message cannot starve a consenting user
davoodmehraban89 committed
Oct 22, 2026 at 23:52 UTC
b988907b2b107aed58d25faa6eeadd6c584eecaf
1 file changed
+25
db/tests/alert_runtime_invariants.sql
+25
@@ -147,6 +147,31 @@ BEGIN
147
PERFORM public.notification_outbox_finish(result.outbox_id,result.claim_token,
148
'UNKNOWN',NULL,t+interval '5 minutes 5 seconds');
149
150
+ -- A revoked oldest message must not starve a valid queued notification.
151
+ PERFORM public.notification_outbox_enqueue(v_user,'revoked-oldest',
152
+ 'BALE',v_recipient,3);
153
+ PERFORM public.notification_outbox_enqueue(v_other,'active-after-revoked',
154
+ 'BALE',v_recipient,3);
155
+ UPDATE public.notification_outbox
156
+ SET created_at = t-interval '2 hours'
157
+ WHERE event_key='revoked-oldest';
158
+ UPDATE public.notification_outbox
159
+ SET created_at = t-interval '1 hour'
160
+ WHERE event_key='active-after-revoked';
161
+
162
+ SELECT * INTO result FROM public.alert_notification_claim_consented(
163
+ t+interval '6 minutes',30);
164
+ IF result.event_key <> 'active-after-revoked' THEN
165
+ RAISE EXCEPTION 'revoked queue head starved consenting recipient';
166
+ END IF;
167
+ SELECT status INTO current_status FROM public.notification_outbox
168
+ WHERE event_key='revoked-oldest';
169
+ IF current_status <> 'UNKNOWN' THEN
170
+ RAISE EXCEPTION 'revoked queued message not terminated during scan';
171
+ END IF;
172
+ PERFORM public.notification_outbox_finish(result.outbox_id,result.claim_token,
173
+ 'UNKNOWN',NULL,t+interval '6 minutes 5 seconds');
174
+
175
-- A revoked recipient never qualifies, even when the rule is valid.
176
UPDATE public.alert_notification_consents
177
SET revoked_at = t-interval '1 minute'