Skip to content

Commit 3ce5724

Browse files
author
Sotiris Nanopoulos
committed
test dummy duplication in tests
Signed-off-by: Sotiris Nanopoulos <sonanopo@microsoft.com>
1 parent cdbeb5f commit 3ce5724

File tree

3 files changed

+57
-9
lines changed

3 files changed

+57
-9
lines changed

source/common/api/win32/os_sys_calls_impl.cc

+2-8
Original file line numberDiff line numberDiff line change
@@ -367,14 +367,8 @@ SysCallSizeResult OsSysCallsImpl::write(os_fd_t sockfd, const void* buffer, size
367367
}
368368

369369
SysCallSocketResult OsSysCallsImpl::duplicate(os_fd_t oldfd) {
370-
WSAPROTOCOL_INFO info;
371-
auto currentProcess = ::GetCurrentProcessId();
372-
auto rc = WSADuplicateSocket(oldfd, currentProcess, &info);
373-
if (rc == SOCKET_ERROR) {
374-
return {(SOCKET)-1, ::WSAGetLastError()};
375-
}
376-
auto new_socket = ::WSASocket(info.iAddressFamily, info.iSocketType, info.iProtocol, &info, 0, 0);
377-
return {new_socket, SOCKET_VALID(new_socket) ? 0 : ::WSAGetLastError()};
370+
// Do a swallow copy.
371+
return {oldfd, ::WSAGetLastError()};
378372
}
379373

380374
SysCallSocketResult OsSysCallsImpl::accept(os_fd_t sockfd, sockaddr* addr, socklen_t* addrlen) {

source/server/listener_impl.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,11 @@ void ListenerImpl::buildFilterChains() {
535535
}
536536

537537
void ListenerImpl::buildSocketOptions() {
538+
#ifdef WIN32
539+
// On Windows we use the exact connection balancer in along with reuse_port to
540+
// balance connections between workers.
541+
connection_balancer_ = std::make_shared<Network::ExactConnectionBalancerImpl>();
542+
#else
538543
// TCP specific setup.
539544
if (connection_balancer_ == nullptr) {
540545
// Not in place listener update.
@@ -546,7 +551,7 @@ void ListenerImpl::buildSocketOptions() {
546551
connection_balancer_ = std::make_shared<Network::NopConnectionBalancerImpl>();
547552
}
548553
}
549-
554+
#endif
550555
if (config_.has_tcp_fast_open_queue_length()) {
551556
addListenSocketOptions(Network::SocketOptionFactory::buildTcpFastOpenOptions(
552557
config_.tcp_fast_open_queue_length().value()));

test/integration/integration_test.cc

+49
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,55 @@ TEST_P(IntegrationTest, PerWorkerStatsAndBalancing) {
157157
check_listener_stats(0, 1);
158158
}
159159

160+
// Make sure we have correctly specified per-worker performance stats.
161+
TEST_P(IntegrationTest, AllWorkersAreHandlingLoad) {
162+
concurrency_ = 2;
163+
initialize();
164+
165+
std::string worker0_stat_name, worker1_stat_name;
166+
if (GetParam() == Network::Address::IpVersion::v4) {
167+
worker0_stat_name = "listener.127.0.0.1_0.worker_0.downstream_cx_total";
168+
worker1_stat_name = "listener.127.0.0.1_0.worker_1.downstream_cx_total";
169+
} else {
170+
worker0_stat_name = "listener.[__1]_0.worker_0.downstream_cx_total";
171+
worker1_stat_name = "listener.[__1]_0.worker_1.downstream_cx_total";
172+
}
173+
174+
test_server_->waitForCounterEq(worker0_stat_name, 0);
175+
test_server_->waitForCounterEq(worker1_stat_name, 0);
176+
177+
// We set the counters for the two workers to see how many connections each handles.
178+
uint64_t w0_ctr = 0;
179+
uint64_t w1_ctr = 0;
180+
constexpr int loops = 5;
181+
for (int i = 0; i < loops; i++) {
182+
constexpr int requests_per_loop = 4;
183+
std::array<IntegrationCodecClientPtr, requests_per_loop> connections;
184+
for (int j = 0; j < requests_per_loop; j++) {
185+
connections[j] = makeHttpConnection(lookupPort("http"));
186+
}
187+
188+
auto worker0_ctr = test_server_->counter(worker0_stat_name);
189+
auto worker1_ctr = test_server_->counter(worker1_stat_name);
190+
auto target = w0_ctr + w1_ctr + requests_per_loop;
191+
ENVOY_LOG_MISC(info, "current values are {} {} with target {}", worker0_ctr->value(),
192+
worker1_ctr->value(), target);
193+
while (test_server_->counter(worker0_stat_name)->value() +
194+
test_server_->counter(worker1_stat_name)->value() <
195+
target) {
196+
timeSystem().advanceTimeWait(std::chrono::milliseconds(10));
197+
}
198+
w0_ctr = test_server_->counter(worker0_stat_name)->value();
199+
w1_ctr = test_server_->counter(worker1_stat_name)->value();
200+
for (int j = 0; j < requests_per_loop; j++) {
201+
connections[j]->close();
202+
}
203+
}
204+
205+
EXPECT_TRUE(w0_ctr > 1);
206+
EXPECT_TRUE(w1_ctr > 1);
207+
}
208+
160209
TEST_P(IntegrationTest, RouterDirectResponseWithBody) {
161210
const std::string body = "Response body";
162211
const std::string file_path = TestEnvironment::writeStringToFileForTest("test_envoy", body);

0 commit comments

Comments
 (0)