Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions source/server/connection_handler_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ void ConnectionHandlerImpl::ActiveTcpSocket::newConnection() {
socket_->setDetectedTransportProtocol(
Extensions::TransportSockets::TransportProtocolNames::get().RawBuffer);
}
// TODO(lambdai): add test cases
Comment thread
lambdai marked this conversation as resolved.
Outdated
// TODO: Address issues in wider scope. See https://github.com/envoyproxy/envoy/issues/8925
// Erase accept filter states because accept filters may not get the opportunity to clean up.
Comment thread
mattklein123 marked this conversation as resolved.
// Particularly the assigned events need to reset before assigning new events in the follow up.
accept_filters_.clear();
// Create a new connection on this listener.
listener_.newConnection(std::move(socket_));
}
Expand Down
6 changes: 4 additions & 2 deletions test/mocks/network/mocks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ MockUdpListenerCallbacks::~MockUdpListenerCallbacks() = default;
MockDrainDecision::MockDrainDecision() = default;
MockDrainDecision::~MockDrainDecision() = default;

MockListenerFilter::MockListenerFilter() = default;
MockListenerFilter::~MockListenerFilter() = default;
MockListenerFilter::MockListenerFilter() {
// ON_CALL(*this, die_()).WillByDefault(testing::Invoke([](){}));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know why ON_CALL + NiceMock reports uninterested call.
I add explicit EXPECT_CALL in each usage. That's a tech debt.
I will investigate later

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't work in the destructor of a mock. We do this all over the place. Please delete this comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sad...During the constructor or destructor of MockFoo, the mock object is not nice or strict

}
MockListenerFilter::~MockListenerFilter() { die_(); }

MockListenerFilterCallbacks::MockListenerFilterCallbacks() {
ON_CALL(*this, socket()).WillByDefault(ReturnRef(socket_));
Expand Down
1 change: 1 addition & 0 deletions test/mocks/network/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class MockListenerFilter : public ListenerFilter {
MockListenerFilter();
~MockListenerFilter() override;

MOCK_METHOD0(die_, void());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/die_/destroy which is what we typically name this method

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating...
Looks like destroy_ w/ underscore is preferred since it is added in MockClass

MOCK_METHOD1(onAccept, Network::FilterStatus(ListenerFilterCallbacks&));
};

Expand Down
20 changes: 14 additions & 6 deletions test/server/connection_handler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ TEST_F(ConnectionHandlerTest, NormalRedirect) {
EXPECT_CALL(test_listener2->socket_, localAddress()).WillRepeatedly(ReturnRef(alt_address));
handler_->addListener(*test_listener2);

Network::MockListenerFilter* test_filter = new Network::MockListenerFilter();
auto* test_filter = new NiceMock<Network::MockListenerFilter>();
EXPECT_CALL(*test_filter, die_()).Times(1);
Comment thread
lambdai marked this conversation as resolved.
Outdated
Network::MockConnectionSocket* accepted_socket = new NiceMock<Network::MockConnectionSocket>();
bool redirected = false;
EXPECT_CALL(factory_, createListenerFilterChain(_))
Expand Down Expand Up @@ -432,6 +433,7 @@ TEST_F(ConnectionHandlerTest, FallbackToWildcardListener) {
handler_->addListener(*test_listener2);

Network::MockListenerFilter* test_filter = new Network::MockListenerFilter();
EXPECT_CALL(*test_filter, die_()).Times(1);
Network::MockConnectionSocket* accepted_socket = new NiceMock<Network::MockConnectionSocket>();
bool redirected = false;
EXPECT_CALL(factory_, createListenerFilterChain(_))
Expand Down Expand Up @@ -498,6 +500,7 @@ TEST_F(ConnectionHandlerTest, WildcardListenerWithOriginalDst) {
cb.socket().restoreLocalAddress(original_dst_address);
return Network::FilterStatus::Continue;
}));
EXPECT_CALL(*test_filter, die_()).Times(1);
EXPECT_CALL(*accepted_socket, restoreLocalAddress(original_dst_address));
EXPECT_CALL(*accepted_socket, localAddressRestored()).WillOnce(Return(true));
EXPECT_CALL(*accepted_socket, localAddress()).WillRepeatedly(ReturnRef(original_dst_address));
Expand Down Expand Up @@ -529,6 +532,7 @@ TEST_F(ConnectionHandlerTest, WildcardListenerWithNoOriginalDst) {
handler_->addListener(*test_listener1);

Network::MockListenerFilter* test_filter = new Network::MockListenerFilter();
EXPECT_CALL(*test_filter, die_()).Times(1);
Network::MockConnectionSocket* accepted_socket = new NiceMock<Network::MockConnectionSocket>();
EXPECT_CALL(factory_, createListenerFilterChain(_))
.WillRepeatedly(Invoke([&](Network::ListenerFilterManager& manager) -> bool {
Expand Down Expand Up @@ -586,6 +590,7 @@ TEST_F(ConnectionHandlerTest, TransportProtocolCustom) {
handler_->addListener(*test_listener);

Network::MockListenerFilter* test_filter = new Network::MockListenerFilter();
EXPECT_CALL(*test_filter, die_()).Times(1);
EXPECT_CALL(factory_, createListenerFilterChain(_))
.WillRepeatedly(Invoke([&](Network::ListenerFilterManager& manager) -> bool {
manager.addAcceptFilter(Network::ListenerFilterPtr{test_filter});
Expand Down Expand Up @@ -644,6 +649,7 @@ TEST_F(ConnectionHandlerTest, ListenerFilterTimeout) {

EXPECT_CALL(*timeout, disableTimer());
timeout->invokeCallback();
EXPECT_CALL(*test_filter, die_()).Times(1);
dispatcher_.clearDeferredDeleteList();
EXPECT_EQ(0UL, downstream_pre_cx_active.value());
EXPECT_EQ(1UL, stats_store_.counter("downstream_pre_cx_timeout").value());
Expand Down Expand Up @@ -672,7 +678,7 @@ TEST_F(ConnectionHandlerTest, ContinueOnListenerFilterTimeout) {
EXPECT_CALL(test_listener->socket_, localAddress());
handler_->addListener(*test_listener);

Network::MockListenerFilter* test_filter = new Network::MockListenerFilter();
Network::MockListenerFilter* test_filter = new NiceMock<Network::MockListenerFilter>();
EXPECT_CALL(factory_, createListenerFilterChain(_))
.WillRepeatedly(Invoke([&](Network::ListenerFilterManager& manager) -> bool {
manager.addAcceptFilter(Network::ListenerFilterPtr{test_filter});
Expand All @@ -691,7 +697,8 @@ TEST_F(ConnectionHandlerTest, ContinueOnListenerFilterTimeout) {
Stats::Gauge& downstream_pre_cx_active =
stats_store_.gauge("downstream_pre_cx_active", Stats::Gauge::ImportMode::Accumulate);
EXPECT_EQ(1UL, downstream_pre_cx_active.value());

EXPECT_CALL(*test_filter, die_()).Times(1).RetiresOnSaturation();
// Barrier: test_filter must be destructed before findFilterChain
EXPECT_CALL(manager_, findFilterChain(_)).WillOnce(Return(nullptr));
EXPECT_CALL(*timeout, disableTimer());
timeout->invokeCallback();
Expand All @@ -708,7 +715,6 @@ TEST_F(ConnectionHandlerTest, ContinueOnListenerFilterTimeout) {
// Timeout is disabled once the listener filters complete.
TEST_F(ConnectionHandlerTest, ListenerFilterTimeoutResetOnSuccess) {
InSequence s;

TestListener* test_listener = addListener(1, true, false, "test_listener");
Network::MockListener* listener = new Network::MockListener();
Network::ListenerCallbacks* listener_callbacks;
Expand Down Expand Up @@ -740,7 +746,7 @@ TEST_F(ConnectionHandlerTest, ListenerFilterTimeoutResetOnSuccess) {
Event::MockTimer* timeout = new Event::MockTimer(&dispatcher_);
EXPECT_CALL(*timeout, enableTimer(std::chrono::milliseconds(15000), _));
listener_callbacks->onAccept(Network::ConnectionSocketPtr{accepted_socket});

EXPECT_CALL(*test_filter, die_());
EXPECT_CALL(manager_, findFilterChain(_)).WillOnce(Return(nullptr));
EXPECT_CALL(*timeout, disableTimer());
listener_filter_cb->continueFilterChain(true);
Expand Down Expand Up @@ -777,6 +783,7 @@ TEST_F(ConnectionHandlerTest, ListenerFilterDisabledTimeout) {
return Network::FilterStatus::StopIteration;
}));
EXPECT_CALL(dispatcher_, createTimer_(_)).Times(0);
EXPECT_CALL(*test_filter, die_());
Network::MockConnectionSocket* accepted_socket = new NiceMock<Network::MockConnectionSocket>();
listener_callbacks->onAccept(Network::ConnectionSocketPtr{accepted_socket});

Expand All @@ -801,7 +808,6 @@ TEST_F(ConnectionHandlerTest, ListenerFilterReportError) {

Network::MockListenerFilter* first_filter = new Network::MockListenerFilter();
Network::MockListenerFilter* last_filter = new Network::MockListenerFilter();

EXPECT_CALL(factory_, createListenerFilterChain(_))
.WillRepeatedly(Invoke([&](Network::ListenerFilterManager& manager) -> bool {
manager.addAcceptFilter(Network::ListenerFilterPtr{first_filter});
Expand All @@ -816,6 +822,8 @@ TEST_F(ConnectionHandlerTest, ListenerFilterReportError) {
}));
// The last filter won't be invoked
EXPECT_CALL(*last_filter, onAccept(_)).Times(0);
EXPECT_CALL(*first_filter, die_()).Times(1);
EXPECT_CALL(*last_filter, die_()).Times(1);
Network::MockConnectionSocket* accepted_socket = new NiceMock<Network::MockConnectionSocket>();
listener_callbacks->onAccept(Network::ConnectionSocketPtr{accepted_socket});

Expand Down