From 0773fc802fa4e0796cba3f1b3233d76a2cf6d2ad Mon Sep 17 00:00:00 2001 From: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com> Date: Wed, 11 Mar 2026 15:35:44 +0000 Subject: [PATCH] Fix CI: guard MetricsRegistry GTest for telemetry=OFF only When telemetry=ON, XRPL_ENABLE_TELEMETRY is globally defined, causing MetricsRegistry.cpp to compile its full OTel path which references xrpld symbols (LedgerMaster, TxQ, OpenLedger) that cannot be linked into the standalone GTest binary. Guard the test with #ifndef and only add MetricsRegistry.cpp as a source when telemetry is OFF. Co-Authored-By: Claude Opus 4.6 --- src/tests/libxrpl/CMakeLists.txt | 16 ++++++++++------ src/tests/libxrpl/telemetry/MetricsRegistry.cpp | 13 ++++++++++--- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/tests/libxrpl/CMakeLists.txt b/src/tests/libxrpl/CMakeLists.txt index cd223d59e3..be337c22e5 100644 --- a/src/tests/libxrpl/CMakeLists.txt +++ b/src/tests/libxrpl/CMakeLists.txt @@ -39,12 +39,7 @@ if(NOT WIN32) add_dependencies(xrpl.tests xrpl.test.net) endif() -xrpl_add_test( - telemetry - # MetricsRegistry lives in xrpld; compile its .cpp directly into the test - # target so the no-op path can be tested without linking all of xrpld. - ${CMAKE_SOURCE_DIR}/src/xrpld/telemetry/MetricsRegistry.cpp -) +xrpl_add_test(telemetry) target_link_libraries(xrpl.test.telemetry PRIVATE xrpl.imports.test) target_include_directories(xrpl.test.telemetry PRIVATE ${CMAKE_SOURCE_DIR}/src) if(telemetry) @@ -52,5 +47,14 @@ if(telemetry) xrpl.test.telemetry PRIVATE opentelemetry-cpp::opentelemetry-cpp ) +else() + # MetricsRegistry lives in xrpld; compile its .cpp directly into the test + # target so the no-op path can be tested without linking all of xrpld. + # When telemetry=ON, XRPL_ENABLE_TELEMETRY is globally defined and the + # .cpp pulls in xrpld symbols we cannot satisfy here. + target_sources( + xrpl.test.telemetry + PRIVATE ${CMAKE_SOURCE_DIR}/src/xrpld/telemetry/MetricsRegistry.cpp + ) endif() add_dependencies(xrpl.tests xrpl.test.telemetry) diff --git a/src/tests/libxrpl/telemetry/MetricsRegistry.cpp b/src/tests/libxrpl/telemetry/MetricsRegistry.cpp index 7d2623c244..2e11d37819 100644 --- a/src/tests/libxrpl/telemetry/MetricsRegistry.cpp +++ b/src/tests/libxrpl/telemetry/MetricsRegistry.cpp @@ -7,11 +7,16 @@ * - Double stop() is safe. * - Destructor handles cleanup without crash. * - * NOTE: Tests that exercise the OTel SDK path require XRPL_ENABLE_TELEMETRY - * to be defined at build time (telemetry=ON). The no-op path tests run - * unconditionally. + * NOTE: These tests only exercise the no-op path (telemetry disabled). + * When XRPL_ENABLE_TELEMETRY is defined, MetricsRegistry.cpp pulls in + * xrpld symbols that cannot be linked into this standalone test binary, + * so the tests are compiled out. */ +// When telemetry is globally enabled, MetricsRegistry.cpp requires xrpld +// link dependencies we cannot satisfy in a standalone GTest binary. +#ifndef XRPL_ENABLE_TELEMETRY + #include #include @@ -337,3 +342,5 @@ TEST_F(MetricsRegistryTest, destructor_calls_stop) } // If we get here without crash, the destructor handled stop. } + +#endif // !XRPL_ENABLE_TELEMETRY