Repository navigation
3.x.x: give each rollups test fixture its own database so sibling migrations cannot time out its setup (#603) - #641
Conversation
…rations cannot time out its setup (#603) The rollups::tests fixture created a schema in the shared test database and ran Ledger::connect(.., true) there. Migration takes MIGRATION_LOCK (0x505249534d000001) with pg_advisory_xact_lock, and advisory locks are scoped to the database, not the schema, so every fixture in the lib binary that migrates into that database queues on one key under the ledger pool's 5 s lock_timeout. On a loaded host the queue passed 5 s and setup failed with a bare "canceling statement due to lock timeout", which is what #603 recorded. The server log of a reproduction showed the timed-out statement was the rollup fixture's SELECT pg_advisory_xact_lock($1), sixth in a queue of other fixtures' migrations. The fixture now opens a per-case database with the shared FixtureDatabase helper (#410's fix for the same class of contention), keeps its schema name as the application_name the cases look up in pg_stat_activity, and attaches setup context to the connect/migrate step. The test error now keeps any cleanup failure as context instead of dropping it. No assertion, timeout or production lock_timeout changes. Holding MIGRATION_LOCK in the gate database from a second session, the base fails both #603 cases 3/3 with that error; with this change they pass 20/20 and all 11 rollups::tests pass 5/5. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Re-running CI: the shard 1 failure was the known |
|
Re-running CI: shard 0 was cancelled at its 30-minute timeout with no failing test. That's pre-existing variance; 3.x.x's own run on 8dbdb57 was cancelled the same way. |
|
Re-running CI: the previous re-run started while GitHub was still recomputing this PR's merge ref after #648 merged, so it used the old 30-minute cap and shard layout (shard 1 was cancelled at 30 min, with every test passing). The merge ref is current now. |
Closes #603.
This makes the two
rollups::testslock-timeout flakes from #603 deterministic. The change is test-only. No assertion, timeout or productionlock_timeoutchanges.Problem
rollups::tests::with_databasemade a fresh schema in the shared test database and ranLedger::connect(.., true)there. Migration takesMIGRATION_LOCK(0x505249534d000001,ledger.rs) withpg_advisory_xact_lock(ledger/migration.rs,migrate_schema). That call runs under the ledger pool's 5 slock_timeout.Advisory locks belong to a database, not a schema. So every lib-test fixture that migrates into the shared database waits on that one key. Once that queue is longer than 5 s, the rollup fixture's setup fails with the bare
canceling statement due to lock timeoutthat #603 recorded. The error had no context, so it looked as though the test's ownLOCK TABLEbarrier had timed out.A private PostgreSQL 16 server log (
log_lock_waits=on, application names in the prefix) shows which statement it was. A failing rollup fixture'sSELECT pg_advisory_xact_lock($1)was waiting on advisory lock[1347570003,1291845633], which isMIGRATION_LOCK. Six other fixtures' migrations were ahead of it in the queue. It was cancelled at 5.0 s. All 11 rollups cases set up this way, so whichever case was late in the queue failed. #603 saw two of them.This is the same class as #410 (database-scoped advisory locks across per-fixture schemas) and #532/#537 (concurrent migrations against the 5 s lock timeout).
Change
crates/qbit-prism-server/src/rollups/tests.rsonly:with_databaseopens a database for each case with the existingFixtureDatabasehelper (tests/support/ledger_database.rs, 3.x.x: Give each integration fixture its own database #410's fix). That helper sets the schema'ssearch_pathin the fixture URL and drops the database however the case ends: success, error, panic or cancellation. No case can queue on another fixture's migration any more.pg_stat_activitybyapplication_name. That name is still the fixture's unique generated schema name (53 bytes).connecting and migrating the rollup fixture ledger, so a setup failure no longer looks like a failure of the case's own SQL.FixtureDatabase::close) instead of dropping it. After a panic, the cleanup error is printed and the panic re-raised, as before.Tests
On a private PostgreSQL 16 (fsync on) with
PRISM_TEST_REQUIRE_INTEGRATION=1, one test binary at a time.Deterministic reproduction. A second session holds
MIGRATION_LOCKin the gate database for the whole run (SELECT pg_advisory_lock(x'505249534D000001'::bigint)), as a sibling fixture's migration does. The script checks that the lock is granted before the binary starts and is still held when it exits.--exactcanceling statement due to lock timeout, after 5.01 s--exactrollups::testsrollups::testsNo fixture databases or holder sessions were left behind afterwards.
Checks:
cargo fmt --all -- --check: clean.cargo clippy --locked -p qbit-prism-server --all-targets -- -D warnings: clean.cargo test --locked -p qbit-prism-server --libat the PR head: 599 passed, 0 failed, 2 ignored, in 127.6 s on an unloaded host. No fixture databases were left behind.test/prism-gated-tests.txtis unchanged, because no test ID changed.Not run here and why
The build host has no qbitd and no Docker, so
live_regtestand the other real-node suites were not run. This PR does not touch them.Merge notes
3.x.xat 4f4b218.3.x.xhas since moved by two commits, neither of which touches these files, and the branch merges cleanly.CREATEDB. That is not new: the other lib suites that already useFixtureDatabase(partitions::acquire_tests,payout_state_tests,snapshot_delta,miner_submit_acquire_tests) need it, and CI has it.Follow-up candidates (not fixed here)
While reproducing this, other lib tests failed with the same bare
canceling statement due to lock timeoutsignature:ledger::candidates::park_tests(3 cases),ledger::connect::acquire::tests::postgres_checkout_boundaries_and_callers,ledger::connect::acquire::job_tests::postgres_job_sql_wait_errors_and_cancellation_do_not_change_checkout_samples,coordinator::window_switch_tests(3 cases),coordinator::window_ref_tests::a_refresh_publishes_the_reference_for_the_window_it_capturedandcoordinator::same_tip_republish_tests::a_build_overtaken_by_a_revision_or_fee_change_is_discarded. Their files also migrate into the shared gate database withoutFixtureDatabase, so they are probably the sameMIGRATION_LOCKqueue. I have not checked which statement timed out for each. They are candidates for the same conversion.Separate note: the four CI flakes from the #626 handover
The four intermittent CI failures that the #626 handover listed as "re-run, not filed" are now tracked:
TimeoutError: 3.x.x: flaky L6 shipped-images lane: the lane's createwallet RPC hits its 30 s client timeout ("TimeoutError: timed out") #637.real_node_smoke"own block did not land": 3.x.x: flaky real_node_smoke: the one scheduled own block does not land (pool_blocks 0) because it races the third external tip #638.migration_rollback"Address already in use": 3.x.x: migration_rollback's cutover rehearsal can fail with 'bind audit HTTP listener: Address already in use', because its frontend ports are released long before the frontend binds them #639.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.