From 0eb4291688028702abe94d72e15689e8010ad48b Mon Sep 17 00:00:00 2001 From: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com> Date: Wed, 9 Sep 2026 12:01:44 +0100 Subject: [PATCH] fix(telemetry): drive the collection lifecycle in the StatsD tests A StatsDCollector polls its metrics only after onCollectionReady(), so neither test flushed anything: the gauge test timed out and the counter test passed for the wrong reason. Call it in both, and drop the two includes whose symbols the file never names. --- src/tests/libxrpl/beast/insight/StatsDCollector.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/tests/libxrpl/beast/insight/StatsDCollector.cpp b/src/tests/libxrpl/beast/insight/StatsDCollector.cpp index 7024318ec8..aaab3e571e 100644 --- a/src/tests/libxrpl/beast/insight/StatsDCollector.cpp +++ b/src/tests/libxrpl/beast/insight/StatsDCollector.cpp @@ -1,7 +1,5 @@ #include -#include -#include #include #include @@ -39,6 +37,7 @@ namespace beast::insight { * "test", * Journal(Journal::getNullSink())); * auto const gauge = collector->makeGauge("g"); + * collector->onCollectionReady(); // Nothing is polled before this. * EXPECT_EQ(server.receive(std::chrono::seconds(10)), "test.g:0|g\n"); * * // Edge case: nothing was sent, so the wait runs out and returns empty. @@ -128,6 +127,10 @@ TEST(StatsDCollector, UntouchedGaugePublishesInitialZero) // Created and then left alone: no set(), no increment(). auto const gauge = collector->makeGauge("untouched"); + // A collector polls its metrics only after this. Without the call no tick + // ever flushes and every assertion below would hold for the wrong reason. + collector->onCollectionReady(); + EXPECT_EQ(server.receive(std::chrono::seconds(10)), std::string("test.untouched:0|g\n")); } @@ -146,6 +149,10 @@ TEST(StatsDCollector, UntouchedCounterPublishesNothing) auto collector = StatsDCollector::make(address, "test", Journal(Journal::getNullSink())); auto const counter = collector->makeCounter("untouched"); + // Same reason as above: polling must be on, or the empty result proves only + // that nothing was polled. + collector->onCollectionReady(); + // Three seconds spans several one-second flush ticks. EXPECT_EQ(server.receive(std::chrono::seconds(3)), std::string()); }