From 030951ed0b7d741b156de0025509cbb6f9e0afce Mon Sep 17 00:00:00 2001 From: OceanLi <122793010+ohdearquant@users.noreply.github.com> Date: Mon, 3 Aug 2026 13:37:51 -0400 Subject: [PATCH] test(metrics): register a metric before asserting the gather output `test_gather_metrics` asserts that `gather_metrics()` contains "ruvector", but the metrics are `lazy_static` and only register with the default Prometheus registry when first dereferenced. The test touches none of them, so it passes only when another test in the same process registered them first. Under `cargo test` that happens by luck: all tests share one process and `test_record_search` touches two metrics. Under a per-test-process runner it fails deterministically, which is what CI uses: cargo test -p ruvector-metrics 15 passed cargo nextest run -p ruvector-metrics 14 passed, 1 failed cargo nextest run -p ruvector-metrics -E 'test(test_gather_metrics)' 0 passed, 1 failed The test now touches a metric itself and asserts on that metric's name rather than the "ruvector" substring, so it no longer depends on execution order or on sharing a process with another test. --- crates/ruvector-metrics/src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/ruvector-metrics/src/lib.rs b/crates/ruvector-metrics/src/lib.rs index 154f0d4af7..9748182443 100644 --- a/crates/ruvector-metrics/src/lib.rs +++ b/crates/ruvector-metrics/src/lib.rs @@ -88,8 +88,15 @@ mod tests { #[test] fn test_gather_metrics() { + // The metrics are `lazy_static`, so they register with the default + // Prometheus registry on first use. Touch one here rather than relying + // on another test in the same process having done it: each test gets + // its own process under a per-test runner, and this assertion then has + // an empty registry to read. + COLLECTIONS_TOTAL.set(0.0); + let metrics = gather_metrics(); - assert!(metrics.contains("ruvector")); + assert!(metrics.contains("ruvector_collections_total")); } #[test]