diff --git a/test/extensions/transport_sockets/tls/ssl_socket_test.cc b/test/extensions/transport_sockets/tls/ssl_socket_test.cc index 8aa58b0cdc766..7835520c548b8 100644 --- a/test/extensions/transport_sockets/tls/ssl_socket_test.cc +++ b/test/extensions/transport_sockets/tls/ssl_socket_test.cc @@ -2694,26 +2694,41 @@ TEST_P(SslSocketTest, ShutdownWithoutCloseNotify) { Buffer::OwnedImpl data("hello"); server_connection->write(data, false); EXPECT_EQ(data.length(), 0); - // Close without sending close_notify alert. - const SslHandshakerImpl* ssl_socket = - dynamic_cast(server_connection->ssl().get()); - EXPECT_EQ(ssl_socket->state(), Ssl::SocketState::HandshakeComplete); - SSL_set_quiet_shutdown(ssl_socket->ssl(), 1); - server_connection->close(Network::ConnectionCloseType::NoFlush); + // Calling close(FlushWrite) in onEvent() callback results in PostIoAction::Close, + // after which the connection is closed without write ready event being delivered, + // and with all outstanding data (here, "hello") being lost. })); EXPECT_CALL(*client_read_filter, onNewConnection()) .WillOnce(Return(Network::FilterStatus::Continue)); EXPECT_CALL(client_connection_callbacks, onEvent(Network::ConnectionEvent::Connected)); - EXPECT_CALL(*client_read_filter, onData(BufferStringEqual("hello"), true)) + EXPECT_CALL(*client_read_filter, onData(BufferStringEqual("hello"), false)) .WillOnce(Invoke([&](Buffer::Instance& read_buffer, bool) -> Network::FilterStatus { read_buffer.drain(read_buffer.length()); - client_connection->close(Network::ConnectionCloseType::NoFlush); + // Close without sending close_notify alert. + const SslHandshakerImpl* ssl_socket = + dynamic_cast(client_connection->ssl().get()); + EXPECT_EQ(ssl_socket->state(), Ssl::SocketState::HandshakeComplete); + SSL_set_quiet_shutdown(ssl_socket->ssl(), 1); + client_connection->close(Network::ConnectionCloseType::FlushWrite); return Network::FilterStatus::StopIteration; })); - EXPECT_CALL(server_connection_callbacks, onEvent(Network::ConnectionEvent::LocalClose)); - EXPECT_CALL(client_connection_callbacks, onEvent(Network::ConnectionEvent::LocalClose)) + EXPECT_CALL(*server_read_filter, onNewConnection()) + .WillOnce(Return(Network::FilterStatus::Continue)); + EXPECT_CALL(*server_read_filter, onData(BufferStringEqual(""), true)) + .WillOnce(Invoke([&](Buffer::Instance&, bool) -> Network::FilterStatus { + // Close without sending close_notify alert. + const SslHandshakerImpl* ssl_socket = + dynamic_cast(server_connection->ssl().get()); + EXPECT_EQ(ssl_socket->state(), Ssl::SocketState::HandshakeComplete); + SSL_set_quiet_shutdown(ssl_socket->ssl(), 1); + server_connection->close(Network::ConnectionCloseType::NoFlush); + return Network::FilterStatus::StopIteration; + })); + + EXPECT_CALL(client_connection_callbacks, onEvent(Network::ConnectionEvent::LocalClose)); + EXPECT_CALL(server_connection_callbacks, onEvent(Network::ConnectionEvent::LocalClose)) .WillOnce(Invoke([&](Network::ConnectionEvent) -> void { dispatcher_->exit(); })); dispatcher_->run(Event::Dispatcher::RunType::Block);