Skip to content

Commit

Permalink
Attempt 3
Browse files Browse the repository at this point in the history
  • Loading branch information
oleks-rip committed Nov 14, 2024
1 parent 406f23d commit 17f8ee5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
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
26 changes: 9 additions & 17 deletions src/test/jtx/impl/Env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,29 +558,21 @@ Env::do_rpc(
std::vector<std::string> const& args,
std::unordered_map<std::string, std::string> const& headers)
{
Json::Value ret;
auto response =
rpcClient(args, app().config(), app().logs(), apiVersion, headers);

static unsigned call_id = 0; // counter to check max retries from one call

// Retry 2 - This comment just to make push to ci and retrigger the tests.
// It will be removed.
++call_id;
for (unsigned ctr = 0; ctr < 10; ++ctr)
for (unsigned ctr = 0; (ctr < retries_) and (response.first == rpcINTERNAL);
++ctr)
{
auto response =
rpcClient(args, app().config(), app().logs(), apiVersion, headers);
if (response.first != rpcINTERNAL)
{
ret = std::move(response.second);
break;
}

JLOG(journal.error())
<< "Env::do_rpc error, call_Id: " << call_id << ", retrying...";
<< "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 ret;
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

0 comments on commit 17f8ee5

Please sign in to comment.