mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Fix CI unit tests (#5196)
- Add retries for rpc client - Add dynamic port allocation for rpc servers
This commit is contained in:
@@ -25,22 +25,11 @@
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
|
||||
int port_base = 8000;
|
||||
void
|
||||
incPorts(int times)
|
||||
{
|
||||
port_base += (4 * times);
|
||||
}
|
||||
|
||||
std::atomic<bool> envUseIPv4{false};
|
||||
|
||||
void
|
||||
setupConfigForUnitTests(Config& cfg)
|
||||
{
|
||||
std::string const port_peer = std::to_string(port_base);
|
||||
std::string port_rpc = std::to_string(port_base + 1);
|
||||
std::string port_ws = std::to_string(port_base + 2);
|
||||
|
||||
using namespace jtx;
|
||||
// Default fees to old values, so tests don't have to worry about changes in
|
||||
// Config.h
|
||||
@@ -58,19 +47,25 @@ setupConfigForUnitTests(Config& cfg)
|
||||
cfg.setupControl(true, true, true);
|
||||
cfg["server"].append(PORT_PEER);
|
||||
cfg[PORT_PEER].set("ip", getEnvLocalhostAddr());
|
||||
cfg[PORT_PEER].set("port", port_peer);
|
||||
|
||||
// Using port 0 asks the operating system to allocate an unused port, which
|
||||
// can be obtained after a "bind" call.
|
||||
// Works for all system (Linux, Windows, Unix, Mac).
|
||||
// Check https://man7.org/linux/man-pages/man7/ip.7.html
|
||||
// "ip_local_port_range" section for more info
|
||||
cfg[PORT_PEER].set("port", "0");
|
||||
cfg[PORT_PEER].set("protocol", "peer");
|
||||
|
||||
cfg["server"].append(PORT_RPC);
|
||||
cfg[PORT_RPC].set("ip", getEnvLocalhostAddr());
|
||||
cfg[PORT_RPC].set("admin", getEnvLocalhostAddr());
|
||||
cfg[PORT_RPC].set("port", port_rpc);
|
||||
cfg[PORT_RPC].set("port", "0");
|
||||
cfg[PORT_RPC].set("protocol", "http,ws2");
|
||||
|
||||
cfg["server"].append(PORT_WS);
|
||||
cfg[PORT_WS].set("ip", getEnvLocalhostAddr());
|
||||
cfg[PORT_WS].set("admin", getEnvLocalhostAddr());
|
||||
cfg[PORT_WS].set("port", port_ws);
|
||||
cfg[PORT_WS].set("port", "0");
|
||||
cfg[PORT_WS].set("protocol", "ws");
|
||||
cfg.SSL_VERIFY = false;
|
||||
}
|
||||
@@ -123,27 +118,11 @@ validator(std::unique_ptr<Config> cfg, std::string const& seed)
|
||||
return cfg;
|
||||
}
|
||||
|
||||
std::unique_ptr<Config>
|
||||
port_increment(std::unique_ptr<Config> cfg, int increment)
|
||||
{
|
||||
for (auto const sectionName : {PORT_PEER, PORT_RPC, PORT_WS})
|
||||
{
|
||||
Section& s = (*cfg)[sectionName];
|
||||
auto const port = s.get<std::int32_t>("port");
|
||||
if (port)
|
||||
{
|
||||
s.set("port", std::to_string(*port + increment));
|
||||
}
|
||||
}
|
||||
return cfg;
|
||||
}
|
||||
|
||||
std::unique_ptr<Config>
|
||||
addGrpcConfig(std::unique_ptr<Config> cfg)
|
||||
{
|
||||
std::string port_grpc = std::to_string(port_base + 3);
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", port_grpc);
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@@ -152,9 +131,11 @@ addGrpcConfigWithSecureGateway(
|
||||
std::unique_ptr<Config> cfg,
|
||||
std::string const& secureGateway)
|
||||
{
|
||||
std::string port_grpc = std::to_string(port_base + 3);
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", port_grpc);
|
||||
|
||||
// Check https://man7.org/linux/man-pages/man7/ip.7.html
|
||||
// "ip_local_port_range" section for using 0 ports
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("secure_gateway", secureGateway);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user