diff --git a/crates/buzz-relay/src/handlers/group_state_postgres_tests.rs b/crates/buzz-relay/src/handlers/group_state_postgres_tests.rs index 89c38355ea..f0586181d9 100644 --- a/crates/buzz-relay/src/handlers/group_state_postgres_tests.rs +++ b/crates/buzz-relay/src/handlers/group_state_postgres_tests.rs @@ -12,8 +12,16 @@ use crate::handlers::ingest::{ingest_event, HttpAuthMethod, IngestAuth}; use crate::state::AppState; use buzz_auth::Scope; +/// Test state on the shared test database. The pool keeps sqlx's default +/// acquire timeout: `test_state_with_database_url` waits only 100 ms so +/// closed-port tests fail fast, and a first connect to a busy CI database can +/// take longer than that (`PoolTimedOut`). pub(crate) async fn state() -> Arc { - crate::state::tests::test_state_with_database_url(&crate::test_support::database_url()).await + crate::state::tests::test_state_with_database_url_and_pool_options( + &crate::test_support::database_url(), + sqlx::postgres::PgPoolOptions::new(), + ) + .await } pub(crate) async fn community(state: &AppState, label: &str) -> TenantContext { diff --git a/crates/buzz-relay/src/state.rs b/crates/buzz-relay/src/state.rs index b4bdd62108..369a57a801 100644 --- a/crates/buzz-relay/src/state.rs +++ b/crates/buzz-relay/src/state.rs @@ -2970,15 +2970,30 @@ pub(crate) mod tests { /// The same test state with an explicit database target. This lets handler /// tests deterministically exercise fail-closed database seams without /// depending on whether a developer has the normal test database running. + /// Its pool waits only 100 ms for a connection, so closed-port targets + /// fail fast. pub(crate) async fn test_state_with_database_url(database_url: &str) -> Arc { + test_state_with_database_url_and_pool_options( + database_url, + sqlx::postgres::PgPoolOptions::new() + .acquire_timeout(std::time::Duration::from_millis(100)), + ) + .await + } + + /// Test state whose config and writer pool both target `database_url`, + /// with the caller's pool options. + pub(crate) async fn test_state_with_database_url_and_pool_options( + database_url: &str, + options: sqlx::postgres::PgPoolOptions, + ) -> Arc { // Fix 5: use Config::for_test() which holds NIP_FI_ENV_LOCK internally. [FI-TRACE-ENV-RACE] let mut config = crate::config::Config::for_test(); config.require_relay_membership = false; config.redis_url = "redis://127.0.0.1:1".to_string(); config.database_url = database_url.to_owned(); config.read_database_url = None; - let pool = sqlx::postgres::PgPoolOptions::new() - .acquire_timeout(std::time::Duration::from_millis(100)) + let pool = options .connect_lazy(&config.database_url) .expect("lazy pg pool"); build_test_state(config, pool).await