{"record":{"id":"a4d3e30143ee0cfe","repo":"block/buzz","slug":"routed-query-gate-on","errorCode":null,"errorMessage":"routed query, gate on","messagePattern":"routed query, gate on","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/buzz-db/src/runtime/tests.rs","lineNumber":1570,"sourceCode":"    let rows = db\n        .query_events_routed(\"test_routed\", &q)\n        .await\n        .expect(\"routed query, gate off\");\n    assert!(\n        contents(&rows).contains(\"writer-only\"),\n        \"budget unset must serve the writer\"\n    );\n    assert!(\n        !contents(&rows).contains(\"replica-only\"),\n        \"budget unset must not reach the replica via the covered arm\"\n    );\n\n    // Budget set ⇒ the covered arm serves it from the replica.\n    db.set_replica_read_max_age_for_tests(Some(std::time::Duration::from_secs(5)));\n    let rows = db\n        .query_events_routed(\"test_routed\", &q)\n        .await\n        .expect(\"routed query, gate on\");\n    assert!(\n        contents(&rows).contains(\"replica-only\"),\n        \"budget set + covered-eligible must route to the replica\"\n    );\n    assert!(!contents(&rows).contains(\"writer-only\"));\n\n    drop_scratch_db(&admin, replica, &rname).await;\n    drop_scratch_db(&admin, writer, &wname).await;\n}\n\n/// COUNT is bounded-only (rev 5 deletion-visibility rule): a\n/// covered-eligible shape must NOT let a count take the covered arm.\n/// With the budget unset the count reads the WRITER even with an open\n/// fence; with the budget set and a fresh entry it reads the replica\n/// under the bounded arm. Divergent row counts prove the serving pool.\n#[tokio::test]\n#[ignore = \"requires Postgres\"]\nasync fn count_events_routed_is_bounded_only() {","sourceCodeStart":1552,"sourceCodeEnd":1588,"githubUrl":"https://github.com/block/buzz/blob/dad5a33865fc81a2e55b3b60746632f615ec1e3a/crates/buzz-db/src/runtime/tests.rs#L1552-L1588","documentation":"This is an `.expect(\"routed query, gate on\")` panic on the `query_events_routed` future in buzz-db's runtime routing tests. `query_events_routed` returns a `Result`, and the expect unwraps it, panicking with the message \"routed query, gate on\" if the query fails after the replica-read budget has been enabled (the replica-served arm). The library surfaces DB-level failures this way in tests so a routing regression manifests as a loud panic naming the exact routing arm under test.","triggerScenarios":"Calling `db.query_events_routed(\"test_routed\", &q)` in the `query_events_routed_defaults_dark_and_routes_covered_when_enabled` test after `set_replica_read_max_age_for_tests(Some(5s))` when the underlying sqlx query against the replica pool returns Err (connection failure, missing table/schema in the scratch replica DB, query error).","commonSituations":"Running the `#[ignore = \"requires Postgres\"]` integration tests without a reachable Postgres admin server; scratch replica DB created but not migrated (missing events tables); the replica pool pointing at a dropped or locked scratch database; invalid `until`/channel parameters in the EventQuery causing a SQL error.","solutions":["Start Postgres and confirm the admin URL (from `admin_url()`) is reachable before running the test (test is normally skipped via #[ignore]).","Run pending migrations against the scratch writer and replica databases so events tables exist.","Check the inner sqlx error by temporarily replacing `.expect` with `.unwrap_err()` or match to see the real DB failure.","Verify `set_replica_read_max_age_for_tests(Some(Duration::from_secs(5)))` was applied and the fence is open before the query.","Ensure no firewall/timeout kills the replica pool connection mid-test; reuse the same Db instance as the test constructs."],"exampleFix":"// before\nlet rows = db.query_events_routed(\"test_routed\", &q).await.expect(\"routed query, gate on\");\n// after\nlet rows = db.query_events_routed(\"test_routed\", &q).await\n    .unwrap_or_else(|e| panic!(\"routed query (gate on) failed: {e}\"));","handlingStrategy":"validation","validationCode":"// Pre-flight before routed queries in tests\nasync fn assert_replica_ready(db: &Db) -> Result<(), sqlx::Error> {\n    sqlx::query(\"SELECT 1\").execute(db.replica()).await.map(|_| ())\n}\n// call before query_events_routed","typeGuard":"fn routed_ok<T>(r: &Result<T, sqlx::Error>) -> bool { r.is_ok() }","tryCatchPattern":"match db.query_events_routed(\"test_routed\", &q).await {\n    Ok(rows) => rows,\n    Err(e) => panic!(\"routed query failed: {e}\"),\n}","preventionTips":["Run ignored tests only with a verified Postgres admin URL","Always apply migrations to scratch DBs before routed queries","Set the replica budget and open the fence before the query","Replace bare .expect labels with panics that print the inner sqlx error"],"tags":["postgres","database","test-panic","replica-routing"],"backgroundTag":"postgres-query-failed","analyzedSha":"dad5a33865fc81a2e55b3b60746632f615ec1e3a","analyzedAt":"2026-08-30T13:49:18.474Z","contentChangedAt":"2026-08-30T13:49:18.474Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}