Repository navigation
test(database): database tests take locks and move expiries instead of sleeping - #692
Open
PiquelChips wants to merge 2 commits into
Open
PiquelChips wants to merge 2 commits into
PiquelChips wants to merge 2 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
PiquelChips
force-pushed
the
test/database-waits
branch
from
November 22, 2026 14:33
56edb82 to
ce614d6
Compare
…5-second lock timeout exclusive and run_migrations now take their session lock through one lock_dedicated method, which lifts the lock limit for the wait and restores it after.
PiquelChips
force-pushed
the
test/database-waits
branch
from
November 22, 2026 14:51
ce614d6 to
37c9fc8
Compare
PiquelChips
marked this pull request as ready for review
November 22, 2026 14:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Five database tests slept so that a lease, a code or a recovery link would expire, or polled until an advisory lock came free. Under load those waits are either too short, which makes the test flaky, or too long, which makes it slow. Each one now acts on the event itself. Expiries are ended in SQL at the exact point the test needs, and a test that needs a lock waits for PostgreSQL to grant it.
Stacked on #691.
Changes
Database::exclusive(key)(test-util): takeskey's advisory lock withpg_advisory_lockand waits its turn, wheretry_exclusivegives up at once. Later PRs in the stack use it for the audit and cleanup locks.exclusivewaits up to 30 seconds for the lock, the old polling helpers' budget, instead of failing at the pool's 5-secondlock_timeout. It andrun_migrationstake their session lock through onelock_dedicatedmethod, which lifts the lock limit for the wait and restores it after.expire_leasehelper in the delivery repository's tests: setsleased_until = clock_timestamp().Tests
locks_exclude_other_sessions_until_their_connection_ends: instead of pollingtry_exclusive, it waits onpg_advisory_lock, which PostgreSQL grants once the dropped holder's session ends. If the session never ends, the 5s limit fails the test as before. Checked: with the holder leaked (mem::forget), the test fails at that limit.an_expired_lease_is_claimed_again_and_the_stale_outcome_discarded: the claim takes a full lease and the test then expires it, where it used to claim a 1ms lease and sleep 20ms. Checked: without the expiry, the test fails at "the expired lease is claimed again".operators_retry_and_cancel_deliveries: the test still checks that the cancelled attempt's lease holds, then expires it, where it used to sleep 300ms. Checked: without the expiry, the retried claim fails.removal_expires_codes_an_earlier_exchange_still_sees_live: the code now expires (clock_timestamp()) after the exchange's transaction begins and before the removal's does. That is the same ordering the 1.2s sleep produced. Checked: withexpire_codeslimited to codes its ownnow()sees as live, the test fails.a_link_that_expires_while_finishing_does_not_complete: the link is expired (Owner::expire) after the finishing transaction has locked the account, instead of a 700ms sleep on a 500ms link. Checked: withcompletecomparing againstnow()instead ofclock_timestamp(), the test fails.I ran all 5 five times against a scratch cluster, and they passed every time.
Council review
Rounds: 3
GPT 6.1 Sol could not take part: its account hit its usage limit.
Note
Written by Claude Opus 5.5 in Claude Code and reviewed by Claude Opus 5.5 and Claude Fable 5.2 (via T3 Code)