Skip to content

test: Migrate xrpld-peerfinder Beast tests to GTest, with GMock#7054

Open
marek-foss-neti wants to merge 5 commits intoXRPLF:developfrom
marek-foss-neti:develop-neti-migration-gtest-xrpld-peerfinder
Open

test: Migrate xrpld-peerfinder Beast tests to GTest, with GMock#7054
marek-foss-neti wants to merge 5 commits intoXRPLF:developfrom
marek-foss-neti:develop-neti-migration-gtest-xrpld-peerfinder

Conversation

@marek-foss-neti
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. 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.

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

codecov Bot commented Apr 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.1%. Comparing base (7cfa5d4) to head (5b99810).
⚠️ Report is 19 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

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

see 217 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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>());
Copy link

Copilot AI May 1, 2026

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);
Copy link

Copilot AI May 1, 2026

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 on lines +35 to +38
target_link_libraries(
${PROJECT_NAME}.test.peerfinder
PRIVATE xrpl.imports.xrpld.test GTest::gmock
)
Copy link

Copilot AI May 1, 2026

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
Copy link
Copy Markdown

github-actions Bot commented May 3, 2026

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants