Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions test/integration/cx_limit_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ class ConnectionLimitIntegrationTest : public testing::TestWithParam<Network::Ad

void initialize() override { BaseIntegrationTest::initialize(); }

AssertionResult waitForConnections(uint32_t envoy_downstream_connections) {
// The multiplier of 2 is because both Envoy's downstream connections and
// the test server's downstream connections are counted by the global
// counter.
uint32_t expected_connections = envoy_downstream_connections * 2;

for (int i = 0; i < 10; ++i) {
if (Network::AcceptedSocketImpl::acceptedSocketCount() == expected_connections) {
return AssertionSuccess();
}
timeSystem().advanceTimeWait(std::chrono::milliseconds(500));
}
if (Network::AcceptedSocketImpl::acceptedSocketCount() == expected_connections) {
return AssertionSuccess();
}
return AssertionFailure();
}

// Assumes a limit of 2 connections.
void doTest(std::function<void()> init_func, std::string&& check_stat) {
init_func();
Expand Down Expand Up @@ -68,6 +86,8 @@ class ConnectionLimitIntegrationTest : public testing::TestWithParam<Network::Ad
tcp_clients.front()->close();
ASSERT_TRUE(raw_conns.front()->waitForDisconnect());

// Make sure to not try to connect again until the acceptedSocketCount is updated.
ASSERT_TRUE(waitForConnections(1));
tcp_clients.emplace_back(makeTcpConnection(lookupPort("listener_0")));
raw_conns.emplace_back();
ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(raw_conns.back()));
Expand Down