Skip to content

test: Migrate resource, shamap Beast tests to GTest#7133

Open
marek-foss-neti wants to merge 33 commits into
XRPLF:developfrom
marek-foss-neti:develop-neti-migration-gtest-resource-shamap
Open

test: Migrate resource, shamap Beast tests to GTest#7133
marek-foss-neti wants to merge 33 commits into
XRPLF:developfrom
marek-foss-neti:develop-neti-migration-gtest-resource-shamap

Conversation

@marek-foss-neti

Copy link
Copy Markdown
Collaborator

High Level Overview of Change

This change migrates all resource and shamap unit tests from Beast framework to GTest, including the use of the common TestSink from helpers.

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 May 13, 2026 10:32
@codecov

codecov Bot commented May 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.9%. Comparing base (b6a1ad5) to head (63ec925).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #7133     +/-   ##
=========================================
- Coverage     82.0%   81.9%   -0.0%     
=========================================
  Files         1007    1007             
  Lines        76854   76854             
  Branches      8984    8983      -1     
=========================================
- Hits         62992   62980     -12     
- Misses       13853   13865     +12     
  Partials         9       9             

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

@marek-foss-neti marek-foss-neti requested a review from a1q123456 May 13, 2026 13:35
Comment thread src/tests/libxrpl/shamap/SHAMap.cpp Outdated
Comment thread src/tests/libxrpl/shamap/FetchPack.cpp Outdated
Comment thread src/tests/libxrpl/shamap/FetchPack.cpp Outdated
Comment thread src/tests/libxrpl/shamap/SHAMap.cpp Outdated
@github-actions

Copy link
Copy Markdown

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

Comment thread src/tests/libxrpl/shamap/SHAMap.cpp Outdated
BEAST_EXPECT(delta.begin()->first == kH1);
BEAST_EXPECT(delta.begin()->second.first == nullptr);
BEAST_EXPECT(delta.begin()->second.second->key() == kH1);
ASSERT_TRUE(sMap.compare(*map2, delta, 100));

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.

I'd like to know your opinion @a1q123456 on using assertions (ASSERTs) in tests, like for example in this case if delta compare fails then the ASSERT guards that consecutive EXPECTs would not run as they might give misleading results.

In GTests, I see that protocol_autogen uses ASSERTs extensively, but they are also used in basics/mulDiv and json. Do you have a preference of EXPECTs over ASSERTs?

This also relates to that task we talked about, of improving asserts exception handling.

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.

In my opinion, if the rest of the code needs a condition to be true to make sense (e.g. file.is_opened(); file.read_byte() == 1), then we should use ASSERT_*

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, then it is done this way.

@marek-foss-neti marek-foss-neti force-pushed the develop-neti-migration-gtest-resource-shamap branch from 65facf7 to f6c22cb Compare May 18, 2026 10:55
@github-actions

Copy link
Copy Markdown

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

Comment thread src/tests/libxrpl/shamap/SHAMap.cpp Outdated

void
run() override
run(bool backed)

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.

Let's get rid of all run functions. If it requires a parameter like this, we can use testing::WithParamInterface<T> and a parameter generator. See: https://google.github.io/googletest/reference/testing.html#WithParamInterface

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.

Done, and I tried to make it readable as imho the run functions were more readable.

@a1q123456 a1q123456 May 26, 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.

Why do you think this is more readable? I don't think I'm able to tell what this method tests from the function name. Also, we're putting test code in a Fixture.

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.

I agree the fixtures are pointless here. Anyway, the latest changes use TEST_P with a predefined constexpr to make it easier to read and see with the backed/unbacked param. Please check if it looks good to you.

@marek-foss-neti marek-foss-neti requested a review from a1q123456 May 25, 2026 18:17
Comment thread src/tests/libxrpl/shamap/SHAMap.cpp

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

lgtm

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

…ration-gtest-resource-shamap

# Conflicts:
#	src/tests/libxrpl/CMakeLists.txt
@github-actions

github-actions Bot commented Jun 8, 2026

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 godexsoft June 9, 2026 14:52
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

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

…ration-gtest-resource-shamap

# Conflicts:
#	.github/scripts/levelization/results/ordering.txt
#	src/tests/libxrpl/shamap/common.h
@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 11 out of 11 changed files in this pull request and generated 2 comments.


do
{
f.clock().advance(std::chrono::seconds(1));

sMap.dump();
{
constexpr std::array kEYS{

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

Leaving some improvement ideas. Overall it looks good as a migration 👍

#include <cstdint>
#include <string>

namespace xrpl::Resource {

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.

Same question about renaming CamelCase namespaces if that's not too much work. If it is then we can follow up with clang-tidy PR for all of them at once later on.

Consumer c(logic.newInboundEndpoint(addr));

// Create load until we get a warning
int n = 10000;

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.

We try to use auto more. These could definitely be auto and get the exact same types for free.

bool readmitted = false;
{
using namespace std::chrono_literals;
// Give Consumer time to become readmitted. Should never

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.

These comments could probably fit one line now? Or split each sentence per line

Charge const fee(1000);
JLOG(j_.info()) << "Charging " << c.toString() << " " << fee << " per second";
c.charge(fee);
for (int i = 0; i < 128; ++i)

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.

Let's try to use std::size_t when we do loops as a rule of thumb.


namespace xrpl::tests {

#ifndef __INTELLISENSE__

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.

I wonder why this is needed? Is it some old hack required long ago that got migrated over or is this still an issue today?

{
constexpr std::array kEYS{
uint256(
"b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"

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 yikes. Do you think we can somehow make them fit on one line each? Possibly by specifying std::array above or something? not a huge deal but could be better 🥇

"5a772c6ca8"),
uint256(
"292891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
"5a772c6ca8")};

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.

We also usually add a trailing comma to init lists.

map.invariants();
}

int h = 7;

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.

Would be good to know what this magic number is.. or compute it from map perhaps.

uint256 rootHash;
std::vector<Blob> goodPath;

for (unsigned char c = 1; c < 100; ++c)

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.

Can we extract 100 magic number and use it here and to compute 99 and 1 below?

for (int i = 0; i < items; ++i)
{
source.addItem(SHAMapNodeType::TnAccountState, makeRandomAS());
if (i % 100 == 0)

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.

More magic numbers here and below that could be extracted to make things clearer.

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