Skip to content

armgit / xerj

Public Imported from GitHub
0

AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.

fix(test): read bytes_written via installed handle so #804 metric test is OnceLock-order-robust (#828) (#829)

xerj-org1a740da0bb14
diff --git a/engine/crates/xerj-engine/src/index.rs b/engine/crates/xerj-engine/src/index.rs
index aa7600c63..5feb3de5b 100644
--- a/engine/crates/xerj-engine/src/index.rs
+++ b/engine/crates/xerj-engine/src/index.rs
@@ -1500,13 +1500,18 @@ mod flush_publication_recovery_tests {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn flush_increments_the_bytes_written_metric() {
// #804: `xerj_bytes_written_total` was registered but nothing ever
- // incremented it, so it stayed 0 regardless of write volume. This is
- // the one call site in the whole binary that installs a `Metrics`
- // instance (`OnceLock`, set-once-per-process) — assert `after >
- // before` rather than an exact delta, since other tests' concurrent
- // flushes may also land on this now-shared counter once installed.
- let metrics = std::sync::Arc::new(xerj_common::metrics::Metrics::new().unwrap());
- crate::set_engine_metrics(metrics.clone());
+ // incremented it, so it stayed 0 regardless of write volume. The
+ // handle is a process-wide `OnceLock` (set-once) and MORE THAN ONE
+ // test installs one (`bytes_written_metric_increments_on_flush`), so
+ // whichever runs first wins the race and a locally-constructed
+ // `Metrics` may never be the one `engine_metrics()` (and thus flush)
+ // increments — reading it gave a flat 0 under high-core parallelism.
+ // Read the INSTALLED handle instead, and assert `after > before`
+ // rather than an exact delta since concurrent flushes share it.
+ crate::set_engine_metrics(std::sync::Arc::new(
+ xerj_common::metrics::Metrics::new().unwrap(),
+ ));
+ let metrics = crate::engine_metrics().expect("engine metrics installed");
let before = metrics.bytes_written.get();
let _fault_test = FLUSH_FAULT_TEST_LOCK.lock().await;