Skip to content

test(relay): give group-state Postgres tests a normal acquire timeout - #8564

Merged
loganj merged 2 commits into
mainfrom
larry/group-state-test-pool-timeout
Oct 27, 2026
Merged

loganj merged 2 commits into
mainfrom
larry/group-state-test-pool-timeout

Conversation

@loganj

@loganj loganj commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

🤖

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 is group_state_events_carry_type_then_creator in 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_url keeps 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 to test_state_with_database_pool. The same state() also serves create_with_members_postgres_tests, edit_metadata_postgres_tests, and system_channel_postgres_tests.

Related issue

N/A. I searched open PRs for PoolTimedOut and acquire_timeout and 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:

  • Before this change: group_state_postgres_tests had 13 of 14 tests fail with PoolTimedOut.
  • After this change: all 14 pass. create_with_members_postgres_tests (3), edit_metadata_postgres_tests (7), and system_channel_postgres_tests (9) also pass through the same proxy.
  • Without the proxy, all 14 pass before and after.
  • cargo clippy -p buzz-relay --all-targets -D warnings and just test-unit pass.

chessing234

This comment was marked as resolved.

@loganj
loganj marked this pull request as ready for review October 27, 2026 19:04
@loganj
loganj requested a review from a team as a code owner October 27, 2026 19:04
@loganj
loganj deployed to codex-review October 27, 2026 19:04 — with GitHub Actions Active
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>
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Oct 27, 2026
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

🔐 Codex Security Review

Note: This is an automated, security-focused review generated by Codex.
Use it as a supplement to human review; false positives are possible.

Scope

  • Exact PR diff: 3ce3a2e2df815924f2519e08d5626a8f8bd8587b...0e30c380bdd93672ce95a36b735993af5648abb2
  • Model: gpt-6.1-sol

💡 Click "edited" above to see earlier reviews for this PR.


Review Summary

Overall Risk: NONE

No concrete findings in the authorized PR range. Changes are confined to test helpers, preserve the existing 100 ms timeout for failure-path tests, and use default pool options for group-state Postgres tests.

Findings

No concrete security, correctness, or reliability findings were identified.

Notes

  • Review used read-only source and history inspection. Builds and tests were not executed, as requested.

Generated by Codex Security Review |
Requested by: @loganj |
Workflow run

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>
@loganj
loganj force-pushed the larry/group-state-test-pool-timeout branch from 77dd580 to 0e30c38 Compare October 27, 2026 19:12
@loganj

This comment has been minimized.

@github-actions github-actions Bot removed the codex-security-review-current The posted Codex security review matches its recorded range. label Oct 27, 2026
@loganj
loganj deployed to codex-review October 27, 2026 19:12 — with GitHub Actions Active
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Oct 27, 2026

@jedwards27 jedwards27 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 :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 passes test_support::database_url() into the new URL+pool-options helper and uses PgPoolOptions::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_url and the lazy writer pool from the same database_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, and BUZZ_TEST_DATABASE_URL to 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 --short clean.
  • gh pr view 8564 --repo block/buzz --json headRefOid,baseRefOid,author → head 0e30c380bdd93672ce95a36b735993af5648abb2, base 3ce3a2e2df815924f2519e08d5626a8f8bd8587b, author loganj.
  • gh pr checks 8564 --repo block/buzz --required --json name,state filtered 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.

@loganj
loganj merged commit 403855d into main Oct 27, 2026
84 checks passed
@loganj
loganj deleted the larry/group-state-test-pool-timeout branch October 27, 2026 20:55

This branch was successfully deployed

1 active deployment
codex-review — 0e30c380 Deployed Oct 27, 2026 by loganj via Run Codex Security Review #10081
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex-security-review-current The posted Codex security review matches its recorded range.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants