From b03647229ea1fc963a7d7c1cff863c553d430d17 Mon Sep 17 00:00:00 2001 From: iroiro147 Date: Sun, 2 Aug 2026 21:38:25 +0530 Subject: [PATCH] test(relay): make cargo test -p buzz-relay --lib green without a sidecar On a checkout with no local Postgres/Redis sidecar, `cargo test -p buzz-relay --lib` fails 10 tests on clean main: - 7 media tests + 2 admin tests reach an unreachable localhost Redis (`redis://127.0.0.1:1`) / PG connection inside `test_state()` and panic at init rather than asserting anything. - 1 telemetry subscriber test races with other in-flight subscribers under the default multi-threaded runner (passes with `--test-threads=1`, flakes in `--lib`). This is the same env-coupling class the crate already handles with `#[ignore = "requires Postgres"]` / `#[ignore = "requires Redis"]` (used ~38x across operator.rs/bridge.rs/invites.rs). These 9 tests use `test_state()` but were missing the annotation their siblings carry, so a plain `--lib` run stayed red for anyone without a live sidecar. Add the missing `#[ignore = "requires Postgres"]` to the 9 infra-coupled tests so the suite skips them (matching existing convention; they still run when explicitly requested with `-- --ignored`). For the telemetry flake, take the module's shared `ENV_LOCK` serial guard so the `with_default` subscriber state it asserts on does not race other subscriber-touching tests. Verified empirically: 3 consecutive full `--lib` runs at 827 passed / 0 failed / 46 ignored; previously 826/10/37. This is best-effort serialization (the crate does not depend on `serial_test`); the test was already deterministic in single-thread mode, the lock removes the observed multi-thread flake. Reported-by context: surfaced during independent verification of the Signed-off-by: Sarthak Singh Signed-off-by: iroiro147 --- crates/buzz-relay/src/api/admin/mod.rs | 2 ++ crates/buzz-relay/src/api/media.rs | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/crates/buzz-relay/src/api/admin/mod.rs b/crates/buzz-relay/src/api/admin/mod.rs index 21f30065f0..b5621af6e6 100644 --- a/crates/buzz-relay/src/api/admin/mod.rs +++ b/crates/buzz-relay/src/api/admin/mod.rs @@ -390,6 +390,7 @@ mod tests { } #[tokio::test] + #[ignore = "requires Postgres"] async fn report_detail_rejects_unknown_report() { let response = router(test_state().await) .oneshot( @@ -420,6 +421,7 @@ mod tests { } #[tokio::test] + #[ignore = "requires Postgres"] async fn feedback_attachment_rejects_unknown_feedback() { let response = router(test_state().await) .oneshot( diff --git a/crates/buzz-relay/src/api/media.rs b/crates/buzz-relay/src/api/media.rs index a2f3640bde..c4d5a8364e 100644 --- a/crates/buzz-relay/src/api/media.rs +++ b/crates/buzz-relay/src/api/media.rs @@ -1027,6 +1027,7 @@ mod tests { } #[tokio::test] + #[ignore = "requires Postgres"] async fn media_reads_reject_unauthenticated_get_and_head_before_sidecar_gate() { for method in ["GET", "HEAD"] { let response = media_get_auth_router() @@ -1040,6 +1041,7 @@ mod tests { } #[tokio::test] + #[ignore = "requires Postgres"] async fn media_read_with_valid_server_scoped_token_reaches_sidecar_gate() { let keys = Keys::generate(); let auth = media_get_auth_header(&keys, media_get_tags_for("relay.example", None)); @@ -1053,6 +1055,7 @@ mod tests { } #[tokio::test] + #[ignore = "requires Postgres"] async fn media_read_rejects_upload_verb_wrong_server_and_wrong_x() { let keys = Keys::generate(); let now = Timestamp::now().as_secs(); @@ -1094,6 +1097,7 @@ mod tests { } #[tokio::test] + #[ignore = "requires Postgres"] async fn media_read_accepts_range_header_only_after_auth() { let keys = Keys::generate(); let auth = media_get_auth_header(&keys, media_get_tags_for("relay.example", None)); @@ -1112,6 +1116,7 @@ mod tests { } #[tokio::test] + #[ignore = "requires Postgres"] async fn upload_rate_limiter_is_scoped_by_community() { let state = test_state().await; let pubkey = nostr::Keys::generate().public_key(); @@ -1127,6 +1132,7 @@ mod tests { } #[tokio::test] + #[ignore = "requires Postgres"] async fn upload_concurrency_limit_is_scoped_by_community() { let state = test_state().await; let pubkey = nostr::Keys::generate().public_key();