Skip to content

Commit 2e5febc

Browse files
buzz-db: test the search store's statement bound through connect
The statement-timeout check now builds its pool with SearchStore::connect, so it fails if the production constructor stops installing the hook. Also drop buzz-search's unused buzz-datastore-tracing dependency, remove an orphaned relay doc comment, and name the push gateway as the exception in ARCHITECTURE.md. Signed-off-by: Luke Tornquist <tornquist@squareup.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 41529f2 commit 2e5febc

6 files changed

Lines changed: 34 additions & 28 deletions

File tree

‎ARCHITECTURE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ buzz-admin (operator CLI: relay membership + key generation)
145145
buzz-test-client (integration test harness + manual CLI)
146146
```
147147

148-
**Key architectural principle:** The relay is the single source of truth. `buzz-relay` orchestrates all subsystems by calling them directly — it imports `buzz-db`, `buzz-auth`, `buzz-pubsub`, `buzz-search`, `buzz-audit`, and `buzz-workflow`. However, those subsystems are isolated from each other: `buzz-workflow` never calls `buzz-pubsub`, etc. The one sanctioned exception is `buzz-audit`, which stores its chain through `buzz_db::AuditLog`. `buzz-audit` computes and checks the hashes; `AuditLog` owns the audit pool and the chain's appends and reads. Every crate reaches Postgres only through `buzz-db`. Cross-subsystem coordination happens only through the relay. In multi-community mode, the relay also owns propagation of `TenantContext`; service crates should receive community-scoped inputs rather than independently deriving tenancy from client-controlled event tags.
148+
**Key architectural principle:** The relay is the single source of truth. `buzz-relay` orchestrates all subsystems by calling them directly — it imports `buzz-db`, `buzz-auth`, `buzz-pubsub`, `buzz-search`, `buzz-audit`, and `buzz-workflow`. However, those subsystems are isolated from each other: `buzz-workflow` never calls `buzz-pubsub`, etc. The one sanctioned exception is `buzz-audit`, which stores its chain through `buzz_db::AuditLog`. `buzz-audit` computes and checks the hashes; `AuditLog` owns the audit pool and the chain's appends and reads. Every crate reaches Postgres only through `buzz-db`, except `buzz-push-gateway`, a separate service that builds its own pool. Cross-subsystem coordination happens only through the relay. In multi-community mode, the relay also owns propagation of `TenantContext`; service crates should receive community-scoped inputs rather than independently deriving tenancy from client-controlled event tags.
149149

150150
---
151151

‎Cargo.lock‎

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/buzz-db/src/store/search.rs‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,3 +941,36 @@ mod tests {
941941
assert_eq!(cleaned.chars().count(), SEARCH_TEXT_MAX_CHARS);
942942
}
943943
}
944+
945+
#[cfg(test)]
946+
mod postgres_tests {
947+
use super::*;
948+
949+
/// Every connection the production constructor opens gets the read
950+
/// statement timeout, which bounds a search that a cancel cannot reach.
951+
#[tokio::test]
952+
#[ignore = "requires Postgres"]
953+
async fn search_store_bounds_every_statement() {
954+
let store = SearchStore::connect(&DbConfig {
955+
database_url: crate::test_support::database_url(),
956+
..DbConfig::default()
957+
})
958+
.expect("build search store");
959+
let mut conns = Vec::new();
960+
for _ in 0..2 {
961+
let mut conn = store.pool.acquire().await.expect("search connection");
962+
let timeout: String = sqlx::query_scalar("SHOW statement_timeout")
963+
.fetch_one(&mut *conn)
964+
.await
965+
.expect("read statement_timeout");
966+
assert_eq!(
967+
timeout,
968+
crate::event::READ_STATEMENT_TIMEOUT,
969+
"every search connection is bounded"
970+
);
971+
conns.push(conn);
972+
}
973+
drop(conns);
974+
store.pool.close().await;
975+
}
976+
}

‎crates/buzz-relay/src/main.rs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ async fn sample_search_outbox(db: Db, leading: std::sync::Arc<std::sync::atomic:
5757
}
5858
}
5959

60-
/// The search pool. Search is lag-tolerant, so it prefers the read replica
61-
/// when one is configured. Like the main read pool it is lazy, so a reader
62-
/// that is down at boot fails searches, not startup, and it waits no longer
63-
/// than the writer pool for a connection, so a dead reader fails each search
64-
/// within that bound instead of sqlx's 30s default.
6560
fn relay_keypair_from_config(relay_private_key: Option<&str>) -> anyhow::Result<nostr::Keys> {
6661
let hex = relay_private_key.ok_or_else(|| {
6762
anyhow::anyhow!(

‎crates/buzz-search/Cargo.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ description = "Community-scoped message search for Buzz: Postgres full-text sear
1111
buzz-core = { workspace = true }
1212
buzz-db = { workspace = true }
1313
buzz-feature-flags = { workspace = true }
14-
buzz-datastore-tracing = { workspace = true }
1514
uuid = { workspace = true }
1615
thiserror = { workspace = true }
1716
tracing = { workspace = true }

‎crates/buzz-search/tests/postgres_fts_integration.rs‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -626,26 +626,6 @@ where
626626
.unwrap_or_else(|e| panic!("{name} after cancel: {e}"));
627627
}
628628

629-
#[tokio::test]
630-
#[ignore = "requires Postgres"]
631-
async fn search_pool_bounds_every_statement() {
632-
let (pool, schema) = setup().await;
633-
let search = search_pool().await;
634-
let mut conns = Vec::new();
635-
for _ in 0..2 {
636-
let mut conn = search.acquire().await.expect("search connection");
637-
let timeout: String = sqlx::query_scalar("SHOW statement_timeout")
638-
.fetch_one(&mut *conn)
639-
.await
640-
.expect("read statement_timeout");
641-
assert_eq!(timeout, "20s", "every search connection is bounded");
642-
conns.push(conn);
643-
}
644-
drop(conns);
645-
search.close().await;
646-
teardown(pool, &schema).await;
647-
}
648-
649629
#[tokio::test]
650630
#[ignore = "requires Postgres"]
651631
async fn abandoned_search_cancels_its_statement() {

0 commit comments

Comments
 (0)