test(relay): build group-state test config and pool from one URL

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>
This commit is contained in:
Logan Johnson
2026-10-27 15:11:42 -04:00
parent 3648de1022
commit 0e30c380bd
2 changed files with 22 additions and 5 deletions

View File

@@ -17,9 +17,11 @@ use buzz_auth::Scope;
/// 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<AppState> {
let pool =
sqlx::PgPool::connect_lazy(&crate::test_support::database_url()).expect("lazy pg pool");
crate::state::tests::test_state_with_database_pool(pool).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 {

View File

@@ -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<AppState> {
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<AppState> {
// 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