test: Migrate xrpld-peerfinder Beast tests to GTest, with GMock#7054
test: Migrate xrpld-peerfinder Beast tests to GTest, with GMock#7054marek-foss-neti wants to merge 5 commits intoXRPLF:developfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #7054 +/- ##
=========================================
+ Coverage 81.9% 82.1% +0.1%
=========================================
Files 1010 1010
Lines 76304 76048 -256
Branches 7483 7380 -103
=========================================
- Hits 62527 62406 -121
+ Misses 13777 13642 -135 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Migrates xrpld/peerfinder unit tests from the Beast unit test framework to GoogleTest, introducing a small framework-neutral TestContext abstraction (and a GMock store) to support ongoing migration work, while wiring a new src/tests/xrpld test subtree into the CMake build.
Changes:
- Added new GTest-based xrpld smoke and peerfinder test executables (peerfinder uses GMock).
- Introduced framework-neutral test scaffolding (
TestContext,GTestContext,BeastTestContext) for migrated helpers. - Removed legacy Beast-based peerfinder tests from
src/test/peerfinderand addedsrc/tests/xrpldto the top-level test build.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| CMakeLists.txt | Adds src/tests/xrpld subdirectory under the tests option. |
| src/tests/xrpld/CMakeLists.txt | Defines xrpld test targets (smoke, peerfinder) and common includes/libs. |
| src/tests/xrpld/smoke/main.cpp | Provides a GTest main() for the xrpld smoke test binary. |
| src/tests/xrpld/smoke/TestContext.cpp | Adds smoke tests for TestContext + header-compilation checks against selected xrpld headers. |
| src/tests/xrpld/peerfinder/main.cpp | Provides a GMock-enabled main() for the peerfinder test binary. |
| src/tests/xrpld/peerfinder/PeerFinder_test.cpp | Migrated PeerFinder logic/config tests to GTest and uses a GMock Store. |
| src/tests/xrpld/peerfinder/Livecache_test.cpp | Migrated Livecache tests to GTest and replaced random endpoints with deterministic generation. |
| src/tests/helpers/TestContext.h | Introduces framework-neutral test context and a journal sink that writes via the context. |
| src/tests/helpers/TestContext.cpp | Compile-time aggregation TU for the new context headers. |
| src/tests/helpers/GTestContext.h | Implements TestContext for GTest (failures via ADD_FAILURE_AT, scoped traces). |
| src/tests/helpers/BeastTestContext.h | Implements TestContext adapter for existing Beast test suites. |
| src/test/peerfinder/PeerFinder_test.cpp | Removes the legacy Beast-based PeerFinder tests. |
| src/test/peerfinder/Livecache_test.cpp | Removes the legacy Beast-based Livecache tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Livecache<> c(clock_, journal_); | ||
|
|
||
| for (auto i = 0; i < numEndpoints; ++i) | ||
| add(endpoint(i), c, xrpl::rand_int<std::uint32_t>()); |
There was a problem hiding this comment.
Livecache::insert asserts that Endpoint::hops <= Tuning::maxHops + 1, but this test passes xrpl::rand_int<std::uint32_t>() (full uint32_t range) as hops. If assertions are enabled, the test can abort; even when asserts are off, it violates the component’s stated precondition. Generate hops in the valid range (e.g. clamp/bound to Tuning::maxHops + 1).
| add(endpoint(i), c, xrpl::rand_int<std::uint32_t>()); | |
| add( | |
| endpoint(i), | |
| c, | |
| xrpl::rand_int<std::uint32_t>() % | |
| static_cast<std::uint32_t>(Tuning::maxHops + 2)); |
| bool allMatch = true; | ||
| for (std::size_t i = 0; i < before.size(); ++i) | ||
| { | ||
| EXPECT_EQ(before[i].size(), after[i].size()); | ||
| allMatch = allMatch && before[i] == after[i]; | ||
| EXPECT_EQ(beforeSorted[i], afterSorted[i]); | ||
| } | ||
| EXPECT_FALSE(allMatch); |
There was a problem hiding this comment.
This assertion (EXPECT_FALSE(allMatch)) makes the test probabilistic: shuffle() can legally return the same ordering, which will sporadically fail CI. Consider making the shuffle deterministic for the test (e.g. seed xrpl::default_prng() to a known value and ensure at least one hop bucket has >1 element), or relax the assertion to only verify it remains a permutation (which you already do via beforeSorted == afterSorted).
| bool allMatch = true; | |
| for (std::size_t i = 0; i < before.size(); ++i) | |
| { | |
| EXPECT_EQ(before[i].size(), after[i].size()); | |
| allMatch = allMatch && before[i] == after[i]; | |
| EXPECT_EQ(beforeSorted[i], afterSorted[i]); | |
| } | |
| EXPECT_FALSE(allMatch); | |
| for (std::size_t i = 0; i < before.size(); ++i) | |
| { | |
| EXPECT_EQ(before[i].size(), after[i].size()); | |
| EXPECT_EQ(beforeSorted[i], afterSorted[i]); | |
| } |
| target_link_libraries( | ||
| ${PROJECT_NAME}.test.peerfinder | ||
| PRIVATE xrpl.imports.xrpld.test GTest::gmock | ||
| ) |
There was a problem hiding this comment.
This target links GTest::gmock, but the existing test CMake uses the gtest:: target namespace (e.g. gtest::gtest in src/tests/libxrpl/CMakeLists.txt). Mixing namespaces can break depending on how GoogleTest is provided (Config package vs Find module). Prefer using the same namespace consistently (e.g. gtest::gmock if available, or add an alias) to match the established convention and avoid configuration-specific build failures.
|
This PR has conflicts, please resolve them in order for the PR to be reviewed. |
|
We recently merged a refactor to One-time setupIf you don't already have clang-tidy working in your env, on macOS: brew install llvm@21
# Follow brew's hint to put $(brew --prefix llvm@21)/bin on PATH so run-clang-tidy is found.Workflow on your branch (before merging develop)1. Grab the new git remote -v # should show 'upstream' among others; if not:
# git remote set-url upstream git@github.com:XRPLF/rippled.git
git fetch upstream
git checkout upstream/develop -- .clang-tidy2. Reconfigure conan/cmake so 3. Apply renames for the files modified in your PR: git diff --name-only $(git merge-base HEAD upstream/develop) HEAD \
| grep -E '\.(cpp|h|hpp|ipp)$' \
| xargs run-clang-tidy -p build -fix -allow-no-checks
# or -p .build, or whatever your build dir is called4. Build + test, then commit as a single dedicated commit: cmake --build build -j8
git commit -am "refactor: Align identifier naming with develop"5. Now merge develop: git merge upstream/developExtraRun clang-tidy once more after the merge to catch any stragglers introduced from develop's side: run-clang-tidy -p build -fix -allow-no-checks src tests
# or -p .build, or whatever your build dir is called |
High Level Overview of Change
This change migrates all peerfinder unit tests from Beast framework to GTest, as well as introduces GMock MockStore in PeerFinder tests, and deterministic random IP generator in Livecache tests. The assumption of this change was no to touch any code outside GTest, and especially not outside the unit tests source code. With future GTest migrations in mind, this change also introduces scaffolding helpers also used in #7046 .
Context of Change
The goal is to gradually migrate all Beast tests to GTest.
Type of Change
test:- This change only affects unit tests.API Impact
No impact.
Test Plan
Verification is done by running the automated unit test suite.