Fix CI unit tests (#5196)

- Add retries for rpc client
- Add dynamic port allocation for rpc servers
This commit is contained in:
Olek
2025-01-28 10:45:59 -05:00
committed by GitHub
parent b6e3453f49
commit 50b8f19cb5
31 changed files with 293 additions and 146 deletions

View File

@@ -326,24 +326,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()));
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);
parsedResult = parseResult(jr);
test.expect(parsedResult.ter, "ter uninitialized!");
ter_ = parsedResult.ter.value_or(telENV_RPC_FAILED);
return jr;
}
else
{
@@ -576,8 +568,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