Repository navigation
3.x.x: make the landing_metrics lost-commit deadline and api_database migration tests deterministic (#528, #532) - #537
Merged
Conversation
… migration tests deterministic (#528, #532) landing_metrics (#528): lost_commit_reply_timeouts_are_not_revision_work_failures and its sibling actual_build_deadline_counts_once_and_later_notify_is_degraded hold a session's initial-job build at admission until its 0.05 s deadline, then release the admission permit and wait for that session's notify. The listener closes a session that still has no job on its first one-second timer tick past initial_job_timeout_seconds, so the release, the retried build and its persist (each bounded by the same 0.05 s) had to finish within about a second of connecting. On a loaded 2-vCPU runner they did not, and the test read "Stratum closed before a response". The later delivery now comes from deliver(), a listener with the default deadlines, on the same frontend; every metric assertion is unchanged. api_database (#532): both tests migrate their own schema in one shared database. Ledger::connect(.., true) takes the migration advisory lock, whose key (0x505249534d000001) is database-wide, under the 5 s lock timeout, so the second migration waited for the whole of the first and a loaded runner pushed that past 5 s. The tests now run their Ledger::connect calls one at a time behind a static tokio mutex. The production lock timeout is unchanged. Test-only. Closes #528. Closes #532. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Member
Author
Review ledger (#528, #532)This PR changes tests only, so under the current policy it got a proportionate check rather than a full deep review: one Review findings
The review also checked the following and found them sound:
Bots: Evidence summary (details in the PR body)
CIAll required checks green on the PR head. |
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.
Makes two recurring
prism-native-postgresflakes deterministic. Test-only: no production code, setting or lock timeout changes, and no assertion is removed or weakened.#528
landing_metrics::lost_commit_reply_timeouts_are_not_revision_work_failuresSymptom.
Error: Stratum closed before a response(CI run 36449857065, shard 0, on #524, which does not touch this binary).Root cause. The test holds a session's initial-job build at admission (a zero-permit semaphore) until its
initial_job_timeout_secondsof 0.05 s. It then adds a permit, sendsmining.get_healthand waits on the same session for amining.notify. The listener's session loop closes a session that still has no job on the first one-second timer tick afterinitial_job_timeout_secondshas passed (stratum.rs, thetimer.tick()arm). This is intended product behaviour: a session that got no work by its deadline is dropped. So the permit, the health reply, the retried build and its persist all had to finish within about one second of connecting. The build and the persist are each bounded by the same 0.05 s, too. Unloaded, the notify arrives about 70 ms after connecting. On a busy 2-vCPU runner it sometimes arrives after the tick, and the test reads EOF.The sibling
actual_build_deadline_counts_once_and_later_notify_is_degradedhas the same shape and fails the same way (below). A retried build that overruns 0.05 s also turns itsTIMEOUTS == 1check into a flake. Both are fixed here.Fix. The delivery that follows the deadline now comes from
deliver(&f.a): the file's existing helper, a listener with the default deadlines on the same frontend. The deadline itself is still a real initial-job build held at admission on the 0.05 s listener. The landing metrics under test (PENDING,UNKNOWN,TIMEOUTSand the published/degraded/superseded results) are frontend-wide, not per session, so every assertion after the delivery still checks the same state.deliveralso asserts that each delivered job carries the ledger's current payout revision. What the tests no longer show is that the held session itself receives work after its deadline. The listener closes that session by design. A session held at admission that gets its job once released is covered bystratum_protocol::delivery_stats_follow_admission_progress_generation_and_disconnect.Evidence (every run pins the test binary and the private PostgreSQL 16 (fsync on) to the same two cores):
lost_commit…alone, beforeStratum closed before a response(4lost_commit…, 2actual_build…)Stratum closed before a response)deliver, afterThe tests still bite. They were run against two product mutants in
metrics/landing.rs:deadline_hitalways attributes.lost_commit…fails witha deadline hit while only unknown tracking remained was counted as a revision-work failure.actual_build…fails atcount(&f.a.metrics, "degraded") == 1.(0.0 vs 1.0), the check after the new delivery.#532
api_database: concurrent schema migrations hit the 5 s lock timeoutSymptom.
canceling statement due to lock timeoutat theLedger::connect(.., true)unwrap in one test, when the file's two tests run concurrently (PR #531 run 36454542958, and a 3.x.x push, run 36167606027).Contended object. Both tests share one database, each in its own schema. A
pg_lockspoller recorded ungranted locks with their holders while the two tests overlapped. Three database-wide waits showed up:lock_timeout?migrate_schema'spg_advisory_xact_lock($1)MIGRATION_LOCK0x505249534d000001, a single database-wide key001_share_ledger.sqlhashtext('qbit_audit_publication_sequence_migration')CREATE INDEX CONCURRENTLYlock_timeout0)Only the first can time out. The second test's migration waits for the whole of the first. With two CPU burners on the two cores, that wait was 1.65–2.75 s (median 2.17 s; 26 waits over 25 measured runs). A full shard on a 2-vCPU runner pushes it past 5 s.
Fix. A static
tokio::sync::Mutexin the test file serialises the two tests'Ledger::connect(.., true)calls, and only those. The productionPRISM_DATABASE_LOCK_TIMEOUT_MSdefault is unchanged. (CI runs test binaries one at a time, so no other binary migrates into this database concurrently.)Evidence:
MIGRATION_LOCKwaits seenPRISM_DATABASE_LOCK_TIMEOUT_MS=300(amplifier, test process only)canceling statement due to lock timeoutCI runtime
No measurable change. Both binaries were run whole, pinned to two cores, twice before and twice after the fix:
landing_metrics(41 tests)api_database(2 tests)The serialised migration costs nothing, because the second migration already waited for the first.
Checks
cargo clippy --locked -p qbit-prism-server --test landing_metrics --test api_database -- -D warnings: clean.cargo fmt --all --check: clean.test/prism-gated-tests.txtis unchanged, because no test id changed.Closes #528
Closes #532
🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.