Repository navigation
3.x.x: make the probe-window dead-connection test deterministic - #507
Conversation
ledger::connect::acquire::probe_tests::a_dead_idle_connection_inside_the_probe_window_fails_one_statement_then_recovers failed in CI with "a statement on the terminated backend N returned pid M". The test terminates the pool's one backend right after a statement, but sqlx returns a dropped PoolConnection from a spawned task that pings the server before making the connection idle. When the backend is terminated while that ping is in flight, the ping fails, sqlx discards the connection on the spot, and the checkout under test opens a fresh connection instead of receiving the dead socket, so the statement succeeds on a new pid. On a two-core host with the runtime and the server competing for CPU this happened in 21 of 100 runs. Both probe tests now wait, bounded, until the pool reports the connection idle before terminating its backend, and assert it is still idle when the checkout starts, so the dead socket is deterministically the one handed out. The sibling threshold-zero test could pass for the wrong reason in the same race (a connection discarded at release, not by the probe); it gets the same synchronization. No assertion was weakened; the acquire code is untouched. Refs #499 Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Review ledger (head 791f879, CI green) Cause. sqlx returns a dropped Fix. Test-only: a bounded Stress evidence (probe tests, two cores with CPU hogs and PostgreSQL beside them): before 21 failures in 100 runs; after 0 in 300. The full server lib binary also passed on the same cores. Reviews.
Refs #499 |
…-paging Both sides add metric families. Conflicts resolved by hand in the census tests only: `tests/observability/cardinality.rs` re-derived from the merged registry (60 families; 241 startup and 675 populated series: #504's four families and six series plus this branch's three unlabeled gauges), and `tests/observability/contract.rs` keeps both sides' gauge names. #502 and #507 touch no metrics files. The auto-merged registry, metrics, coordinator, ledger, metadata, inventory and gated-test list were checked: every family and constant from both sides is present, the metadata names all resolve in the registry, the inventory is regenerated, and the gated list is byte-sorted with no duplicates. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Makes the two idle-gated checkout probe tests added in #499 deterministic. Test-only; the acquire code is untouched and no assertion is weakened.
Failure.
ledger::connect::acquire::probe_tests::a_dead_idle_connection_inside_the_probe_window_fails_one_statement_then_recoversfailed in PR CI (shard 1, unrelated to that PR's diff) witha statement on the terminated backend 1108 returned pid 1112.Cause. The test runs one statement on the pool's single connection, then terminates that backend from an admin session and expects the next statement to fail on the dead socket. But sqlx returns a dropped
PoolConnectionfrom a task it spawns, and that task pings the server before the connection becomes idle. If the backend is terminated while the release ping is still in flight, the ping fails, sqlx discards the connection immediately, and the checkout under test opens a fresh connection: the statement succeeds on a new pid, which is exactly the message seen. On a two-core host with the runtime and PostgreSQL competing for CPU this reproduced in 21 of 100 runs of the probe tests (two CPU hogs pinned to the same cores, private PostgreSQL 16 with fsync on). The sibling threshold-zero test cannot fail this way, but in the same race it passes for the wrong reason (the connection is discarded at release rather than by the probe).Fix. A
settledhelper waits, with a 5 s bound, until the pool reports its one connection idle (num_idle() == 1,size() == 1) before the backend is terminated, and each test asserts the connection is still idle when the checkout starts. The dead socket is then deterministically the one handed out: inside the window the first statement fails on it and the release-time ping discards it; at threshold zero the probe discards it and the statement runs on a fresh connection.Loop evidence (whole
probe_testsmodule of the server lib binary, pinned to two cores with two CPU hogs and PostgreSQL beside it):returned pid)The whole server lib test binary (544 tests, PostgreSQL-backed ones included) also passed once on the same two cores without hogs, and that run's gate manifest passes the checker against the binary's 134 gated ids.
Checks.
cargo clippy --locked -p qbit-prism-server --all-targets -- -D warningsclean;cargo fmt --all --checkclean; the gate-manifest checker passes for the server lib binary's gated ids on a full run of that binary;test/prism-gated-tests.txtunchanged.Refs #499
🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.