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

@@ -37,8 +37,13 @@
using namespace etl::impl;
struct ForwardingSourceTests : SyncAsioContextTest {
TestWsServer server_{ctx, "0.0.0.0", 11114};
ForwardingSource forwardingSource{"127.0.0.1", "11114", std::chrono::milliseconds{1}, std::chrono::milliseconds{1}};
TestWsServer server_{ctx, "0.0.0.0"};
ForwardingSource forwardingSource{
"127.0.0.1",
server_.port(),
std::chrono::milliseconds{1},
std::chrono::milliseconds{1}
};
};
TEST_F(ForwardingSourceTests, ConnectionFailed)

View File

@@ -42,9 +42,9 @@ using namespace etl::impl;
struct GrpcSourceTests : NoLoggerFixture, util::prometheus::WithPrometheus, tests::util::WithMockXrpLedgerAPIService {
GrpcSourceTests()
: WithMockXrpLedgerAPIService("localhost:55051")
: WithMockXrpLedgerAPIService("localhost:0")
, mockBackend_(std::make_shared<testing::StrictMock<MockBackend>>(util::Config{}))
, grpcSource_("127.0.0.1", "55051", mockBackend_)
, grpcSource_("127.0.0.1", std::to_string(getXRPLMockPort()), mockBackend_)
{
}

View File

@@ -18,6 +18,7 @@
//==============================================================================
#include "etl/impl/SubscriptionSource.hpp"
#include "util/AssignRandomPort.hpp"
#include "util/Fixtures.hpp"
#include "util/MockNetworkValidatedLedgers.hpp"
#include "util/MockSubscriptionManager.hpp"
@@ -31,6 +32,7 @@
#include <gtest/gtest.h>
#include <chrono>
#include <cstdint>
#include <optional>
#include <string>
#include <utility>
@@ -46,8 +48,7 @@ struct SubscriptionSourceConnectionTests : public NoLoggerFixture {
}
boost::asio::io_context ioContext_;
TestWsServer wsServer_{ioContext_, "0.0.0.0", 11113};
TestWsServer wsServer_{ioContext_, "0.0.0.0"};
StrictMockNetworkValidatedLedgersPtr networkValidatedLedgers_;
StrictMockSubscriptionManagerSharedPtr subscriptionManager_;
@@ -59,7 +60,7 @@ struct SubscriptionSourceConnectionTests : public NoLoggerFixture {
SubscriptionSource subscriptionSource_{
ioContext_,
"127.0.0.1",
"11113",
wsServer_.port(),
networkValidatedLedgers_,
subscriptionManager_,
onConnectHook_.AsStdFunction(),