Skip to content

deliveries_rpc test: stamp claim setups by the wall clock - #275

Merged
sonyccd merged 2 commits into
mainfrom
deliveries-test-clock
Oct 27, 2026
Merged

sonyccd merged 2 commits into
mainfrom
deliveries-test-clock

Conversation

@sonyccd

@sonyccd sonyccd commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Fixes the deliveries_rpc.test.sql flake that has turned main red (the merge of #273, and earlier the 00:00Z run on 2026-10-27) and failed #274's CI.

Cause. claim_deliveries reads clock_timestamp() for everything: row age, bucket refill, the batch hold and throttles. The test's queue helper inserted deliveries with created_at defaulting to the transaction's now(), and the refill, hold, throttle and expiry setups used now() too. The file usually takes 2 s, but three CI runs took 82 to 215 s to get through it. Once more than about 30 s had passed by the "Refill" section, fresh rows looked older than the 30-second hold and refills looked bigger than intended, so tests 64 to 108 failed, 19 in all.

Fix (test only). The queue helper stamps created_at with clock_timestamp(), and every setup a claim reads is stamped by the wall clock. Assertions about throttle_destination, mark_deliveries_sent and delivery_queue_stats keep now(), since those functions read now().

Checked. A 100 s pg_sleep after plan() fails the old file in exactly CI's 19 tests and passes the new one, 145/145. The full pgTAP suite passes locally.

Not fixed: why the file sometimes runs slow. Locally, one run in about a hundred spent 2.4 s in a single claim_deliveries call, against the usual 100 ms, shortly after a db reset. That points to plans made while autovacuum was still analyzing the freshly seeded tables, which a hosted database with settled statistics doesn't hit. I could not reproduce it on demand.

🤖 Generated with Claude Code

claim_deliveries ages rows, refills buckets and lifts throttles by
clock_timestamp(), but the queue helper and the refill, batch hold,
throttle and expiry setups stamped rows with the transaction's now().
When a runner is slow to reach those tests (three CI runs on 2026-10-27
took 82 to 215 s for the file; it usually takes 2), a fresh row looked
older than the batch hold and 19 tests failed. Stamp them with
clock_timestamp() so the file passes however long it runs; checked with
a 100 s pg_sleep after plan(), which fails the old file the same 19 ways.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
longlines Ready Ready Preview Oct 27, 2026 3:08pm UTC

@supabase

supabase Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Updates to Preview Branch (deliveries-test-clock) ↗︎

Deployments Status Updated
Database ✅ Tue, 27 Oct 2026 15:08:44 UTC
Services ✅ Tue, 27 Oct 2026 15:08:44 UTC
APIs ✅ Tue, 27 Oct 2026 15:08:44 UTC

Tasks are run on every commit but only new migration files are pushed.
Close and reopen this PR if you want to apply changes from existing seed or migration files.

Tasks Status Updated
Configurations ✅ Tue, 27 Oct 2026 15:08:45 UTC
Migrations ✅ Tue, 27 Oct 2026 15:08:45 UTC
Seeding ✅ Tue, 27 Oct 2026 15:08:45 UTC
Edge Functions ✅ Tue, 27 Oct 2026 15:09:05 UTC

View logs for this Workflow Run ↗︎.
Learn more about Supabase for Git ↗︎.

@sonyccd
sonyccd merged commit 3a04bb3 into main Oct 27, 2026
10 checks passed
@sonyccd
sonyccd deleted the deliveries-test-clock branch October 27, 2026 15:12

This branch was successfully deployed

1 active deployment
Preview — 25337d7f Deployed Oct 27, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant