Skip to content

test: Modularize Peerfinder component and migrate Peerfinder tests from Beast to GTest and GMock#7054

Open
marek-foss-neti wants to merge 31 commits into
XRPLF:developfrom
marek-foss-neti:develop-neti-migration-gtest-xrpld-peerfinder
Open

test: Modularize Peerfinder component and migrate Peerfinder tests from Beast to GTest and GMock#7054
marek-foss-neti wants to merge 31 commits into
XRPLF:developfrom
marek-foss-neti:develop-neti-migration-gtest-xrpld-peerfinder

Conversation

@marek-foss-neti

@marek-foss-neti marek-foss-neti commented Apr 30, 2026

Copy link
Copy Markdown
Collaborator

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. This change also migrates the relevant files & headers out of xrpld and into xrpl, libxrpl, with necessary include updates across the peerfinder space.

Context of Change

The goal is to gradually migrate all Beast tests to GTest without any tests depending on xrpld files.

Type of Change

  • test: - This change affects unit tests.

API Impact

No impact.

Test Plan

Verification is done by running the automated unit test suite.

@marek-foss-neti marek-foss-neti marked this pull request as ready for review April 30, 2026 11:10
@codecov

codecov Bot commented Apr 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.28571% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.5%. Comparing base (b6a1ad5) to head (ed01934).

Files with missing lines Patch % Lines
include/xrpl/peerfinder/detail/Logic.h 85.3% 5 Missing ⚠️
src/xrpld/peerfinder/detail/PeerfinderConfig.cpp 75.0% 2 Missing ⚠️
src/libxrpl/peerfinder/Config.cpp 98.3% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #7054     +/-   ##
=========================================
+ Coverage     82.0%   82.5%   +0.6%     
=========================================
  Files         1007    1009      +2     
  Lines        76854   76995    +141     
  Branches      8984    8880    -104     
=========================================
+ Hits         62992   63537    +545     
+ Misses       13853   13449    -404     
  Partials         9       9             
Files with missing lines Coverage Δ
.../beast/container/detail/aged_unordered_container.h 96.5% <ø> (+0.4%) ⬆️
include/xrpl/peerfinder/Config.h 100.0% <100.0%> (ø)
include/xrpl/peerfinder/PeerfinderManager.h 100.0% <100.0%> (ø)
include/xrpl/peerfinder/Types.h 100.0% <100.0%> (ø)
include/xrpl/peerfinder/detail/Bootcache.h 100.0% <ø> (ø)
include/xrpl/peerfinder/detail/Counts.h 100.0% <ø> (ø)
include/xrpl/peerfinder/detail/Fixed.h 100.0% <ø> (ø)
include/xrpl/peerfinder/detail/Handouts.h 97.9% <100.0%> (ø)
include/xrpl/peerfinder/detail/Livecache.h 98.6% <100.0%> (ø)
include/xrpl/peerfinder/detail/SlotImp.h 100.0% <ø> (ø)
... and 16 more

... and 8 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/peerfinder and added src/tests/xrpld to 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>());

Copilot AI May 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
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));

Copilot uses AI. Check for mistakes.
Comment on lines +196 to +203
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);

Copilot AI May 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
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]);
}

Copilot uses AI. Check for mistakes.
Comment thread src/tests/xrpld/CMakeLists.txt Outdated
Comment on lines +35 to +38
target_link_libraries(
${PROJECT_NAME}.test.peerfinder
PRIVATE xrpl.imports.xrpld.test GTest::gmock
)

Copilot AI May 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@github-actions

github-actions Bot commented May 3, 2026

Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

@godexsoft

Copy link
Copy Markdown
Contributor

We recently merged a refactor to develop that enables clang-tidy's readability-identifier-naming. Your branch now has heavy conflicts that are largely mechanical. Below is a workflow that aligns your branch's naming with develop before merging, which should minimize the merge conflicts.

One-time setup

If 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 .clang-tidy from develop without pulling anything else. Sync your fork on GitHub first, then:

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-tidy

2. Reconfigure conan/cmake so compile_commands.json is fresh.

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 called

4. 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/develop

Extra

Run 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

@marek-foss-neti marek-foss-neti force-pushed the develop-neti-migration-gtest-xrpld-peerfinder branch from 5b99810 to 1136e07 Compare May 6, 2026 10:59
@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

@@ -0,0 +1,240 @@
#include <xrpld/peerfinder/detail/Livecache.h>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I just noticed that we're referencing header files in xrpld which we should not because this part is not "modularised" yet.

If we're intended to test something in xrpld, we will need to move it to libxrpl.

@@ -0,0 +1,240 @@
#include <xrpld/peerfinder/detail/Livecache.h>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I just noticed that we're referencing header files in xrpld which we should not because this part is not "modularised" yet.

If we're intended to test somthing in xrpld, we need to move it to libxrpl.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it seems we managed to move it to libxrpl.

Comment thread src/tests/libxrpl/peerfinder/Livecache.cpp
@github-actions

Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

@marek-foss-neti marek-foss-neti force-pushed the develop-neti-migration-gtest-xrpld-peerfinder branch from 6b34d0f to c0f7e76 Compare May 19, 2026 12:31
@github-actions

Copy link
Copy Markdown

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

@marek-foss-neti marek-foss-neti force-pushed the develop-neti-migration-gtest-xrpld-peerfinder branch from c0f7e76 to 0211e91 Compare May 19, 2026 13:47
@github-actions

Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

@github-actions

Copy link
Copy Markdown

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

@marek-foss-neti marek-foss-neti requested a review from a1q123456 May 21, 2026 12:35
@bthomee bthomee requested a review from vvysokikh1 May 26, 2026 14:49
@vvysokikh1

Copy link
Copy Markdown
Contributor

I think this PR is misnamed, since it does the modularization of Peerfinder component AND the tests migration

@marek-foss-neti

Copy link
Copy Markdown
Collaborator Author

I think this PR is misnamed, since it does the modularization of Peerfinder component AND the tests migration

Indeed @vvysokikh1 you're right, let me try update the title. This happened because initially modularization wasn't in the scope of this PR but turned out to be necessary during the migration from Beast to GTest.

@marek-foss-neti marek-foss-neti changed the title test: Migrate xrpld-peerfinder Beast tests to GTest, with GMock test: Modularize Peerfinder component and migrate Peerfinder tests from Beast to GTest and GMock May 27, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module is not fully modularised. I think we need some discussion before moving such a big component.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @a1q123456, I agree. Let's see what more needs to be done here so we have both a successful test migration and a valid peerfinder modularization.

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

@marek-foss-neti marek-foss-neti requested a review from godexsoft June 9, 2026 14:52
…ration-gtest-xrpld-peerfinder

# Conflicts:
#	.github/scripts/levelization/results/ordering.txt
#	src/tests/libxrpl/CMakeLists.txt
#	src/xrpld/app/rdb/detail/PeerFinder.cpp
#	src/xrpld/peerfinder/PeerfinderManager.h
#	src/xrpld/peerfinder/detail/PeerfinderConfig.cpp
#	src/xrpld/peerfinder/detail/PeerfinderManager.cpp
@github-actions

Copy link
Copy Markdown

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 41 out of 41 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

include/xrpl/peerfinder/detail/Logic.h:712

  • preprocess now always drops endpoints failing isValidAddress, which makes the Config::verifyEndpoints flag ineffective (it is still populated from config and exposed via onWrite). If verifyEndpoints is intended to control endpoint validation, this should remain conditional on config_.verifyEndpoints.

Comment on lines +86 to +90
if (limits.inPeers && *limits.inPeers > 1000)
throw std::runtime_error("Inbound peer limit must be less or equal than 1000");

if (limits.outPeers && (*limits.outPeers < 10 || *limits.outPeers > 1000))
throw std::runtime_error("Outbound peer limit must be in range 10-1000");

// if it's a private peer or we are running as standalone
// automatic connections would defeat the purpose.
config.autoConnect = !standalone && !peerPrivate;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants