Repository navigation
test(relay): give group-state Postgres tests a normal acquire timeout - #8564
Conversation
group_state_postgres_tests::state() built its pool through test_state_with_database_url, whose 100 ms acquire timeout exists so closed-port tests fail fast. Against the real test database a first connect on a busy CI runner can exceed that, and the tests fail with PoolTimedOut while creating their community. Build the pool with sqlx's default timeout and hand it to test_state_with_database_pool. Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Logan Johnson <loganj@squareup.com>
🔐 Codex Security Review
Review SummaryOverall Risk: NONE
FindingsNo concrete security, correctness, or reliability findings were identified. Notes
Generated by Codex Security Review | |
state() built its pool from test_support::database_url(), but test_state_with_database_pool kept config.database_url from DATABASE_URL. When BUZZ_TEST_DATABASE_URL or TEST_DATABASE_URL is set, the two named different databases. A shared helper now sets both from the same URL and takes the pool options, so state() keeps sqlx's default acquire timeout and test_state_with_database_url keeps its 100 ms one. Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Logan Johnson <loganj@squareup.com>
77dd580 to
0e30c38
Compare
This comment has been minimized.
This comment has been minimized.
jedwards27
left a comment
There was a problem hiding this comment.
🤖 :bot: Jude’s code review agent review
Verdict: APPROVE
Reviewed: PR diff at exact head 0e30c380bdd93672ce95a36b735993af5648abb2 (block/buzz#8564), live base ref 3ce3a2e2df815924f2519e08d5626a8f8bd8587b; local merge-base f167c4c3e10469f4f75b5ecad83af50bb3d5de2c. Authenticated reviewer jedwards27; PR author loganj.
Risk: Low. This is a relay test-fixture-only change: no production path, schema, or user-visible behavior changes. The main tradeoff is that failed group-state Postgres fixture acquisition can now wait for SQLx’s normal finite acquire timeout instead of the previous 100 ms CI-flake window.
Behavior/contracts traced:
group_state_postgres_tests::state()now passestest_support::database_url()into the new URL+pool-options helper and usesPgPoolOptions::new(), so the shared real-Postgres group-state fixture keeps SQLx’s default acquire behavior instead of the artificial 100 ms cap (crates/buzz-relay/src/handlers/group_state_postgres_tests.rs:15-24).- The helper sets both
Config.database_urland the lazy writer pool from the samedatabase_url, fixing the earlier config/pool mismatch concern (crates/buzz-relay/src/state.rs:2984-2999). test_state_with_database_url(...)still applies the 100 ms acquire timeout for explicit failure/closed-port seams (crates/buzz-relay/src/state.rs:2970-2982). Scoped callers are closed-port/fail-closed tests.- The PostgreSQL nextest wrapper isolates tests by exporting
DATABASE_URL,TEST_DATABASE_URL, andBUZZ_TEST_DATABASE_URLto the same per-test database (scripts/postgres-test-wrapper.sh:81-90).
Findings: No blocking or non-blocking code defects found. The older CHANGES_REQUESTED concern about the real DB pool using a different URL than config is resolved by the current head.
Author action: None required. Optional only: refresh the PR body’s implementation detail that still describes the intermediate test_state_with_database_pool shape; current code uses test_state_with_database_url_and_pool_options.
Verification owner: No author-owned blocker. CI covers the full Postgres lane; reviewer/tooling owns the residual local delayed-TCP-proxy repro gap.
Validation at matching head:
git rev-parse HEAD→0e30c380bdd93672ce95a36b735993af5648abb2;git status --shortclean.gh pr view 8564 --repo block/buzz --json headRefOid,baseRefOid,author→ head0e30c380bdd93672ce95a36b735993af5648abb2, base3ce3a2e2df815924f2519e08d5626a8f8bd8587b, authorloganj.gh pr checks 8564 --repo block/buzz --required --json name,statefiltered to non-pass/non-skipped required checks →0.git diff --check origin/main...HEAD— pass.scripts/test-postgres-test-discovery.sh— pass.cargo test -p buzz-relay --no-run— pass.cargo test -p buzz-relay --lib state::tests::bare_community_disconnect_fails_closed_when_the_fence_is_unavailable -- --exact— pass.
Manual/native evidence: Not applicable for a relay test-helper-only change. I did not rerun the ignored Postgres group-state tests or delayed TCP-proxy reproduction locally because no local Docker/Postgres service was available in this session; exact-head CI’s required Postgres gates are green.
Residual risk: If a real group-state test pool starvation occurs, failure can now take up to SQLx’s normal default acquire timeout rather than 100 ms. That is finite and diagnostic, and the closed-port failure tests keep the short timeout.
🤖
Summary
The relay's PostgreSQL CI job sometimes fails in the channel group-state tests with
ensure community: Sqlx(PoolTimedOut). The tests themselves are fine. They connect to the test database through a test helper that waits only 100 ms for a connection, and on a busy CI runner the first connection can take longer than that. One example isgroup_state_events_carry_type_then_creatorin this #8522 run: it failed after 0.57 s, while its other 1110 tests passed.This PR gives these tests a pool with sqlx's normal acquire timeout. No product code changes.
Details
test_state_with_database_urlkeeps its 100 ms timeout on purpose. Its other callers point at a closed port (127.0.0.1:1) to test fail-closed paths, and the short timeout makes them fail fast.group_state_postgres_tests::state()is the only caller that passes it the real test database. It now builds a normal lazy pool and passes it totest_state_with_database_pool. The samestate()also servescreate_with_members_postgres_tests,edit_metadata_postgres_tests, andsystem_channel_postgres_tests.Related issue
N/A. I searched open PRs for
PoolTimedOutandacquire_timeoutand found none for this.Testing
To reproduce a slow first connection, I ran the tests through a local TCP proxy that waits 250 ms before it connects to Postgres:
group_state_postgres_testshad 13 of 14 tests fail withPoolTimedOut.create_with_members_postgres_tests(3),edit_metadata_postgres_tests(7), andsystem_channel_postgres_tests(9) also pass through the same proxy.cargo clippy -p buzz-relay --all-targets -D warningsandjust test-unitpass.