Skip to content

Commit

Permalink
test: Enable various common network tests on windows (#12503)
Browse files Browse the repository at this point in the history
This patch enables the following tests on Windows:

1. //test/common/http:codec_client_test
2. //test/common/network:listener_impl_test
3. //test/common/network:connection_impl_test

To do so we swap the addresses to use `getCanonicalLoopbackAddress` instead of `getAnyAddress` and we add synchronization in `ConnectionImplTest.ReadWatermarks` tests.

Additional Description: N/A
Risk Level: Low, test only
Testing: Updated unit tests
Docs Changes: N/A
Release Notes: N/A

Signed-off-by: Sotiris Nanopoulos <sonanopo@microsoft.com>
  • Loading branch information
Sotiris Nanopoulos authored Aug 5, 2020
1 parent 904cc6b commit dbc0286
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 33 deletions.
2 changes: 0 additions & 2 deletions test/common/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ envoy_cc_test(
envoy_cc_test(
name = "codec_client_test",
srcs = ["codec_client_test.cc"],
# IpVersions/CodecNetworkTest.SendData/IPv4: Test times out on Windows.
tags = ["fails_on_windows"],
deps = [
":common_lib",
"//source/common/buffer:buffer_lib",
Expand Down
2 changes: 1 addition & 1 deletion test/common/http/codec_client_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class CodecNetworkTest : public testing::TestWithParam<Network::Address::IpVersi
CodecNetworkTest() : api_(Api::createApiForTest()), stream_info_(api_->timeSource()) {
dispatcher_ = api_->allocateDispatcher("test_thread");
auto socket = std::make_shared<Network::TcpListenSocket>(
Network::Test::getAnyAddress(GetParam()), nullptr, true);
Network::Test::getCanonicalLoopbackAddress(GetParam()), nullptr, true);
Network::ClientConnectionPtr client_connection = dispatcher_->createClientConnection(
socket->localAddress(), source_address_, Network::Test::createRawBufferSocket(), nullptr);
upstream_listener_ = dispatcher_->createListener(std::move(socket), listener_callbacks_, true);
Expand Down
4 changes: 0 additions & 4 deletions test/common/network/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ envoy_cc_test(
envoy_cc_test(
name = "connection_impl_test",
srcs = ["connection_impl_test.cc"],
# Times out on Windows
tags = ["fails_on_windows"],
deps = [
"//source/common/buffer:buffer_lib",
"//source/common/common:empty_string",
Expand Down Expand Up @@ -181,8 +179,6 @@ envoy_cc_test(
envoy_cc_test(
name = "listener_impl_test",
srcs = ["listener_impl_test.cc"],
# Times out on Windows
tags = ["fails_on_windows"],
deps = [
"//source/common/event:dispatcher_lib",
"//source/common/network:address_lib",
Expand Down
41 changes: 19 additions & 22 deletions test/common/network/connection_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ class ConnectionImplTest : public testing::TestWithParam<Address::IpVersion> {
if (dispatcher_.get() == nullptr) {
dispatcher_ = api_->allocateDispatcher("test_thread");
}
socket_ = std::make_shared<Network::TcpListenSocket>(Network::Test::getAnyAddress(GetParam()),
nullptr, true);
socket_ = std::make_shared<Network::TcpListenSocket>(
Network::Test::getCanonicalLoopbackAddress(GetParam()), nullptr, true);
listener_ = dispatcher_->createListener(socket_, listener_callbacks_, true);
client_connection_ = std::make_unique<Network::TestClientConnectionImpl>(
*dispatcher_, socket_->localAddress(), source_address_,
Expand Down Expand Up @@ -291,8 +291,8 @@ TEST_P(ConnectionImplTest, ImmediateConnectError) {
// Using a broadcast/multicast address as the connection destinations address causes an
// immediate error return from connect().
Address::InstanceConstSharedPtr broadcast_address;
socket_ = std::make_shared<Network::TcpListenSocket>(Network::Test::getAnyAddress(GetParam()),
nullptr, true);
socket_ = std::make_shared<Network::TcpListenSocket>(
Network::Test::getCanonicalLoopbackAddress(GetParam()), nullptr, true);
if (socket_->localAddress()->ip()->version() == Address::IpVersion::v4) {
broadcast_address = std::make_shared<Address::Ipv4Instance>("224.0.0.1", 0);
} else {
Expand Down Expand Up @@ -808,17 +808,18 @@ TEST_P(ConnectionImplTest, ReadWatermarks) {
client_connection_->addReadFilter(client_read_filter);
connect();

auto on_filter_data_exit = [&](Buffer::Instance&, bool) -> FilterStatus {
dispatcher_->exit();
return FilterStatus::StopIteration;
};

EXPECT_FALSE(testClientConnection()->readBuffer().highWatermarkTriggered());
EXPECT_TRUE(client_connection_->readEnabled());
// Add 4 bytes to the buffer and verify the connection becomes read disabled.
{
Buffer::OwnedImpl buffer("data");
server_connection_->write(buffer, false);
EXPECT_CALL(*client_read_filter, onData(_, false))
.WillOnce(Invoke([&](Buffer::Instance&, bool) -> FilterStatus {
dispatcher_->exit();
return FilterStatus::StopIteration;
}));
EXPECT_CALL(*client_read_filter, onData(_, false)).WillOnce(Invoke(on_filter_data_exit));
dispatcher_->run(Event::Dispatcher::RunType::Block);

EXPECT_TRUE(testClientConnection()->readBuffer().highWatermarkTriggered());
Expand All @@ -841,11 +842,7 @@ TEST_P(ConnectionImplTest, ReadWatermarks) {
{
Buffer::OwnedImpl buffer("bye");
server_connection_->write(buffer, false);
EXPECT_CALL(*client_read_filter, onData(_, false))
.WillOnce(Invoke([&](Buffer::Instance&, bool) -> FilterStatus {
dispatcher_->exit();
return FilterStatus::StopIteration;
}));
EXPECT_CALL(*client_read_filter, onData(_, false)).WillOnce(Invoke(on_filter_data_exit));
dispatcher_->run(Event::Dispatcher::RunType::Block);

EXPECT_TRUE(testClientConnection()->readBuffer().highWatermarkTriggered());
Expand Down Expand Up @@ -877,8 +874,8 @@ TEST_P(ConnectionImplTest, ReadWatermarks) {
client_connection_->readDisable(false);
return FilterStatus::StopIteration;
}))
.WillRepeatedly(Return(FilterStatus::StopIteration));
dispatcher_->run(Event::Dispatcher::RunType::NonBlock);
.WillRepeatedly(Invoke(on_filter_data_exit));
dispatcher_->run(Event::Dispatcher::RunType::Block);
}

// Test the same logic for dispatched_buffered_data from the
Expand Down Expand Up @@ -909,8 +906,8 @@ TEST_P(ConnectionImplTest, ReadWatermarks) {
client_connection_->readDisable(false);
return FilterStatus::StopIteration;
}))
.WillRepeatedly(Return(FilterStatus::StopIteration));
dispatcher_->run(Event::Dispatcher::RunType::NonBlock);
.WillRepeatedly(Invoke(on_filter_data_exit));
dispatcher_->run(Event::Dispatcher::RunType::Block);
}

disconnect(true);
Expand Down Expand Up @@ -1133,8 +1130,8 @@ TEST_P(ConnectionImplTest, BindFailureTest) {
new Network::Address::Ipv6Instance(address_string, 0)};
}
dispatcher_ = api_->allocateDispatcher("test_thread");
socket_ = std::make_shared<Network::TcpListenSocket>(Network::Test::getAnyAddress(GetParam()),
nullptr, true);
socket_ = std::make_shared<Network::TcpListenSocket>(
Network::Test::getCanonicalLoopbackAddress(GetParam()), nullptr, true);
listener_ = dispatcher_->createListener(socket_, listener_callbacks_, true);

client_connection_ = dispatcher_->createClientConnection(
Expand Down Expand Up @@ -2239,8 +2236,8 @@ class ReadBufferLimitTest : public ConnectionImplTest {
void readBufferLimitTest(uint32_t read_buffer_limit, uint32_t expected_chunk_size) {
const uint32_t buffer_size = 256 * 1024;
dispatcher_ = api_->allocateDispatcher("test_thread");
socket_ = std::make_shared<Network::TcpListenSocket>(Network::Test::getAnyAddress(GetParam()),
nullptr, true);
socket_ = std::make_shared<Network::TcpListenSocket>(
Network::Test::getCanonicalLoopbackAddress(GetParam()), nullptr, true);
listener_ = dispatcher_->createListener(socket_, listener_callbacks_, true);

client_connection_ = dispatcher_->createClientConnection(
Expand Down
8 changes: 4 additions & 4 deletions test/common/network/listener_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ TEST_P(ListenerImplTest, GlobalConnectionLimitEnforcement) {
}

TEST_P(ListenerImplTest, WildcardListenerUseActualDst) {
auto socket =
std::make_shared<TcpListenSocket>(Network::Test::getAnyAddress(version_), nullptr, true);
auto socket = std::make_shared<TcpListenSocket>(
Network::Test::getCanonicalLoopbackAddress(version_), nullptr, true);
Network::MockListenerCallbacks listener_callbacks;
Network::MockConnectionHandler connection_handler;
// Do not redirect since use_original_dst is false.
Expand Down Expand Up @@ -284,8 +284,8 @@ TEST_P(ListenerImplTest, WildcardListenerIpv4Compat) {
TEST_P(ListenerImplTest, DisableAndEnableListener) {
testing::InSequence s1;

auto socket =
std::make_shared<TcpListenSocket>(Network::Test::getAnyAddress(version_), nullptr, true);
auto socket = std::make_shared<TcpListenSocket>(
Network::Test::getCanonicalLoopbackAddress(version_), nullptr, true);
MockListenerCallbacks listener_callbacks;
MockConnectionCallbacks connection_callbacks;
TestListenerImpl listener(dispatcherImpl(), socket, listener_callbacks, true);
Expand Down

0 comments on commit dbc0286

Please sign in to comment.