Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to fix macos unit tests #5192

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@ jobs:
- name: install Ninja
if: matrix.generator == 'Ninja'
run: brew install ninja
name: install nproc
run: |
brew install coreutils
- name: check environment
run: |
env | sort
echo ${PATH} | tr ':' '\n'
python --version
conan --version
cmake --version
nproc --version
echo -n "nproc returns: "
nproc
- name: configure Conan
run : |
conan profile new default --detect || true
Expand All @@ -66,6 +72,13 @@ jobs:
with:
generator: ${{ matrix.generator }}
configuration: ${{ matrix.configuration }}
cmake-args: ${{ matrix.cmake-args }}
- name: test
run: |
${build_dir}/rippled --unittest
n=$(nproc)
if [[ $n -gt 2 ]]
then
: $[ n/=2 ]
fi
echo "Using $n test jobs"
${build_dir}/rippled --unittest --unittest-jobs $n
15 changes: 15 additions & 0 deletions src/test/jtx/Env.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,20 @@ class Env
app().checkSigs(false);
}

// set rpc retries
void
set_retries(unsigned r = 5)
{
retries_ = r;
}

// get rpc retries
unsigned
retries() const
{
return retries_;
}

/** Associate AccountID with account. */
void
memoize(Account const& account);
Expand Down Expand Up @@ -693,6 +707,7 @@ class Env
TestStopwatch stopwatch_;
uint256 txid_;
TER ter_ = tesSUCCESS;
unsigned retries_ = 5;

Json::Value
do_rpc(
Expand Down
45 changes: 25 additions & 20 deletions src/test/jtx/impl/Env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,24 +317,16 @@ Env::submit(JTx const& jt)
auto const jr = [&]() {
if (jt.stx)
{
// We shouldn't need to retry, but it fixes the test on macOS for
// the moment.
int retries = 3;
do
{
txid_ = jt.stx->getTransactionID();
Serializer s;
jt.stx->add(s);
auto const jr = rpc("submit", strHex(s.slice()));

parsedResult = parseResult(jr);
test.expect(parsedResult.ter, "ter uninitialized!");
ter_ = parsedResult.ter.value_or(telENV_RPC_FAILED);
if (ter_ != telENV_RPC_FAILED ||
parsedResult.rpcCode != rpcINTERNAL ||
jt.ter == telENV_RPC_FAILED || --retries <= 0)
return jr;
} while (true);
txid_ = jt.stx->getTransactionID();
Serializer s;
jt.stx->add(s);
auto const jr = rpc("submit", strHex(s.slice()));

parsedResult = parseResult(jr);
test.expect(parsedResult.ter, "ter uninitialized!");
ter_ = parsedResult.ter.value_or(telENV_RPC_FAILED);

return jr;
}
else
{
Expand Down Expand Up @@ -566,8 +558,21 @@ Env::do_rpc(
std::vector<std::string> const& args,
std::unordered_map<std::string, std::string> const& headers)
{
return rpcClient(args, app().config(), app().logs(), apiVersion, headers)
.second;
auto response =
rpcClient(args, app().config(), app().logs(), apiVersion, headers);

for (unsigned ctr = 0; (ctr < retries_) and (response.first == rpcINTERNAL);
++ctr)
{
JLOG(journal.error())
<< "Env::do_rpc error, retrying, attempt #" << ctr + 1 << " ...";
std::this_thread::sleep_for(std::chrono::milliseconds(500));

response =
rpcClient(args, app().config(), app().logs(), apiVersion, headers);
}

return response.second;
}

void
Expand Down
1 change: 1 addition & 0 deletions src/test/rpc/LedgerRequestRPC_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ class LedgerRequestRPC_test : public beast::unit_test::suite
auto const USD = gw["USD"];
env.fund(XRP(100000), gw);

env.set_retries(0);
auto const result = env.rpc("ledger_request", "1")[jss::result];
// The current HTTP/S ServerHandler returns an HTTP 403 error code here
// rather than a noPermission JSON error. The JSONRPCClient just eats
Expand Down
1 change: 1 addition & 0 deletions src/test/rpc/ValidatorInfo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ValidatorInfo_test : public beast::unit_test::suite
{
using namespace test::jtx;
Env env{*this, envconfig(no_admin)};
env.set_retries(0);
auto const info = env.rpc("validator_info")[jss::result];
BEAST_EXPECT(info.isNull());
}
Expand Down
1 change: 1 addition & 0 deletions src/test/rpc/ValidatorRPC_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ValidatorRPC_test : public beast::unit_test::suite
for (std::string cmd : {"validators", "validator_list_sites"})
{
Env env{*this, isAdmin ? envconfig() : envconfig(no_admin)};
env.set_retries(isAdmin ? 5 : 0);
auto const jrr = env.rpc(cmd)[jss::result];
if (isAdmin)
{
Expand Down
Loading