Files
buzz/crates/buzz-relay/src
Matt Toohey 008d72a133 test(relay): stop bridge cancel_fixture tests timing out on the first replica connect (#9691)
## Problem

All seven tests that share `cancel_fixture` in
`crates/buzz-relay/src/api/bridge.rs` got a replica pool with a 1 s
`acquire_timeout`. Only
`shed_history_read_maps_to_503_on_every_bridge_branch` needs that
budget: it holds the replica full and measures how fast a read sheds.
sqlx applies `acquire_timeout` to opening connections as well as to
waiting for a free one, so the budget also governed the fixture's
initial connect and every later acquire that had to open a connection.

A transient Postgres stall on the shared CI server therefore failed
tests that never hold the replica full. CI showed `connect scratch:
PoolTimedOut` at `bridge.rs:10309` in
`aborted_history_read_logs_events_already_queued` and
`failed_history_read_closes_and_reconnect_replays_the_history` (run
44205074529 shows eight tests finishing together after a ~3 s gap, which
is the stall). Pools with sqlx's 30 s default waited the stall out; the
1 s replica did not. No connection leaked and the pool was not too
small.

The replica's 300 ms database-level `statement_timeout` had the same
flaw: migrations and seeding ran under it, so a stall during setup
failed `seed community` with 57014.

## Fix (test code only)

- The six non-shed tests now use default pool budgets.
- Only the shed test asks for the short budget, via `budgeted_reader`.
That helper pre-opens all of the reader pool's connections under the 30
s default, and does not ping on acquire, so the 1 s budget covers only
the wait for a free connection.
- sqlx still pings each connection on release and closes it if the ping
fails, so `budgeted_reader` waits until `num_idle()` equals
`max_connections` before returning. A fill-and-drain loop (acquire to
`max_connections`, drop, re-check) reopens any connection a failed
release ping closed, under one 30 s deadline, and panics with the `N of
M idle` count if the deadline passes.
- The replica's `statement_timeout` is applied after migrations and
seeding, and the replica is reopened so new sessions pick it up.
- The shed test asserts each shed `/query` case completes in under 10 s,
so a silent fallback to the 30 s default fails instead of passing
slowly.

## Verification

Reproduced locally by pausing the Postgres container for 2 s at random
intervals while running `api::bridge::postgres_tests` at CI's 8 threads:
`connect scratch: PoolTimedOut` appeared in 1 of 4 runs before the fix
and in 0 of 8 after. With the fix, the 62 bridge postgres tests passed
at 8 threads against a local Postgres (`--ignored`, including the shed,
statement-cancel, and both history-read tests). `cargo fmt` is clean.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: mtoohey <mtoohey@squareup.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 14:00:02 +11:00
..
…
…
…