You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test(database): lock-wait tests share one helper that says why it polls - #691
Tests now wait for events, not time, so a test may only sleep where nothing can be awaited, and it has to say why. Two copies of until_blocked, one in auth-service and one in the database crate, polled pg_locks every 10ms and gave no reason. PostgreSQL really does offer no notification when a transaction starts waiting for a lock, so the poll has to stay. It now lives in one place and says why.
First of a stack that takes the sleeps out of sourceorigin's tests. cargo xtask test-waits, which will enforce the rule, comes in a later PR once it is published in a shared crate.
Changes
DatabaseTransaction::until_blocked(waiters) replaces both copies. It is a test-util fixture in crates/database/src/fixtures.rs with a // wall-clock: comment on its poll. blocked_transactions becomes pub(crate) since only this fixture reads it.
The database crate's own Database::wait_for_lock gets the same // wall-clock: comment.
Every caller changes from until_blocked(&mut holder, n) to holder.until_blocked(n), with no change in behaviour.
docs/dev/testing.md lists the fixture with the others.
Tests
The tests that call until_blocked assert the same things as before, through the same query and the same 10-second limit. I ran all 23 of them (auth-service and sourceorigin-repository) five times against a scratch cluster, and they passed every time.
Council review
Rounds: 3
Delegate
Round 1
Round 2
Round 3
GPT 6.1 Sol
no score
no score
no score
Claude Opus 5.5
8/10
9/10
9/10
Claude Fable 5.2
8/10
8/10
9/10
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)
Scope: database test fixture (crates/database)
Adds DatabaseTransaction::until_blocked(&mut self, waiters: i64) in crates/database/src/fixtures.rs (test-util). It polls blocked_transactions() every 10 ms until at least waiters transactions are blocked.
The helper uses a 10-second timeout. Query failures and timeout expiry panic.
Updates fixture imports. Duration is now imported directly.
Changes DatabaseTransaction::blocked_transactions from pub to pub(crate) in crates/database/src/transaction.rs. The query and return type are unchanged. Its doc comment no longer describes ordering concurrent test work.
Adds a comment in Database::wait_for_lock (crates/database/src/connection/mod.rs). The comment states that lock-wait detection polls PostgreSQL catalog views because PostgreSQL emits no signal when a wait begins. Runtime behavior is unchanged.
Scope: database repository tests
crates/database/src/repositories/announcements/tests.rs: removes the local polling helper. Purge/send tests call DatabaseTransaction::until_blocked with the same wait counts.
Scope: auth-service test helper removal
apps/auth-service/src/tests.rs: removes the free function until_blocked(holder: &mut DatabaseTransaction<'_>, waiters: i64).
Removes the matching imports from the test modules that used it.
Scope: auth-service call sites
Replaces until_blocked(&mut tx, n) with tx.until_blocked(n) in test modules under account, admin, alerts, clients, oidc, passkey, recovery, security, and web/admin.
Blocked-task counts, synchronization points, and assertions are unchanged.
Scope: documentation
docs/dev/testing.md: describes until_blocked as waiting for transactions queued behind a lock held by another transaction. Also clarifies that test_channels! declares channels whose deliveries the test inserts.
Totals: 24 files, +76 / −70 lines. No runtime production behavior change is described. The planned cargo xtask test-waits check is not part of this change.
No actionable comments were generated in the recent review.
Walkthrough
The database test fixture adds DatabaseTransaction::until_blocked, which polls for blocked transactions. Auth-service and announcement concurrency tests use this method instead of standalone helpers. The blocked-transaction query is now crate-visible.
Changes: Transaction lock-wait test synchronization
The database fixture adds DatabaseTransaction::until_blocked, which polls every 10 ms for up to 10 seconds. blocked_transactions becomes crate-visible. The documentation describes the wait method.
Concurrency test migration apps/auth-service/src/**/tests*.rs, crates/database/src/repositories/announcements/tests.rs
Auth-service and announcement tests call until_blocked on their transaction instead of using standalone polling helpers. The existing wait counts and synchronization points remain unchanged.
refactor: repository-wide cleanup pass #544: This PR consolidates duplicated until_blocked helpers into a shared database test fixture, matching the issue’s stated cleanup objective.
Merge Risk: Minimal · up to 9263a
This PR consolidates duplicated lock-wait test helpers into one shared fixture and documents why it polls. It has no production behavior impact, and no merge-blocking risk remains.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the test scope and the shared helper that now documents why it polls. The changeset consolidates two until_blocked helpers into DatabaseTransaction::until_blocked with a wall-clock com…
Description check
The description follows the template's main sections. It explains what changed and why, gives the rationale for keeping the PostgreSQL poll, and describes testing (23 tests run five times against a sc…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the test scope and the shared helper that now documents why it polls. The changeset consolidates two until_blocked helpers into DatabaseTransaction::until_blocked with a wall-clock comment, so the title matches the main change. It is somewhat dense but specific and conventional-commit formatted.
Full details: Description check
Explanation
The description follows the template's main sections. It explains what changed and why, gives the rationale for keeping the PostgreSQL poll, and describes testing (23 tests run five times against a scratch cluster). It has a Council review section and a note that is not in the template. The checklist is absent, and the description does not reference an issue number. Those gaps are non-critical for this check.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit watched the lock waits slow, Then moved the polling where tests go. Each transaction knows the chore, No scattered helpers hop once more. The tests wait, then onward flow.
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 94ff6dce-039e-465e-9c37-1cc5f862e77d
Commits
Reviewing files that changed from the base of the PR and between e99cc0e and 9263ae4.
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
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
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.
Tests now wait for events, not time, so a test may only sleep where nothing can be awaited, and it has to say why. Two copies of
until_blocked, one in auth-service and one in the database crate, polledpg_locksevery 10ms and gave no reason. PostgreSQL really does offer no notification when a transaction starts waiting for a lock, so the poll has to stay. It now lives in one place and says why.First of a stack that takes the sleeps out of sourceorigin's tests.
cargo xtask test-waits, which will enforce the rule, comes in a later PR once it is published in a shared crate.Changes
DatabaseTransaction::until_blocked(waiters)replaces both copies. It is atest-utilfixture incrates/database/src/fixtures.rswith a// wall-clock:comment on its poll.blocked_transactionsbecomespub(crate)since only this fixture reads it.Database::wait_for_lockgets the same// wall-clock:comment.until_blocked(&mut holder, n)toholder.until_blocked(n), with no change in behaviour.docs/dev/testing.mdlists the fixture with the others.Tests
The tests that call
until_blockedassert the same things as before, through the same query and the same 10-second limit. I ran all 23 of them (auth-service and sourceorigin-repository) 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)
Scope: database test fixture (
crates/database)DatabaseTransaction::until_blocked(&mut self, waiters: i64)incrates/database/src/fixtures.rs(test-util). It pollsblocked_transactions()every 10 ms until at leastwaiterstransactions are blocked.Durationis now imported directly.DatabaseTransaction::blocked_transactionsfrompubtopub(crate)incrates/database/src/transaction.rs. The query and return type are unchanged. Its doc comment no longer describes ordering concurrent test work.Database::wait_for_lock(crates/database/src/connection/mod.rs). The comment states that lock-wait detection polls PostgreSQL catalog views because PostgreSQL emits no signal when a wait begins. Runtime behavior is unchanged.Scope: database repository tests
crates/database/src/repositories/announcements/tests.rs: removes the local polling helper. Purge/send tests callDatabaseTransaction::until_blockedwith the same wait counts.Scope: auth-service test helper removal
apps/auth-service/src/tests.rs: removes the free functionuntil_blocked(holder: &mut DatabaseTransaction<'_>, waiters: i64).Scope: auth-service call sites
until_blocked(&mut tx, n)withtx.until_blocked(n)in test modules underaccount,admin,alerts,clients,oidc,passkey,recovery,security, andweb/admin.Scope: documentation
docs/dev/testing.md: describesuntil_blockedas waiting for transactions queued behind a lock held by another transaction. Also clarifies thattest_channels!declares channels whose deliveries the test inserts.Totals: 24 files, +76 / −70 lines. No runtime production behavior change is described. The planned
cargo xtask test-waitscheck is not part of this change.