Create generate free port class to avoid conflicting ports (#1439)

Fixes #1317
This commit is contained in:
Peter Chen
2024-06-18 06:29:05 -04:00
committed by GitHub
parent 5ba08b1d26
commit e135aa49d5
14 changed files with 313 additions and 149 deletions

View File

@@ -82,7 +82,7 @@ struct WithMockXrpLedgerAPIService : virtual ::testing::Test {
WithMockXrpLedgerAPIService(std::string serverAddress)
{
grpc::ServerBuilder builder;
builder.AddListeningPort(serverAddress, grpc::InsecureServerCredentials());
builder.AddListeningPort(serverAddress, grpc::InsecureServerCredentials(), &port_);
builder.RegisterService(&mockXrpLedgerAPIService);
server_ = builder.BuildAndStart();
serverThread_ = std::thread([this] { server_->Wait(); });
@@ -94,11 +94,17 @@ struct WithMockXrpLedgerAPIService : virtual ::testing::Test {
serverThread_.join();
}
int
getXRPLMockPort() const
{
return port_;
}
MockXrpLedgerAPIService mockXrpLedgerAPIService;
private:
std::unique_ptr<grpc::Server> server_;
std::thread serverThread_;
int port_{};
};
} // namespace tests::util