@@ -122,6 +122,7 @@ class TestClientConnectionImpl : public Network::ClientConnectionImpl {
122
122
public:
123
123
using ClientConnectionImpl::ClientConnectionImpl;
124
124
Buffer::Instance& readBuffer () { return *read_buffer_; }
125
+ ConnectionSocketPtr& socket () { return socket_; }
125
126
};
126
127
127
128
class ConnectionImplTest : public testing ::TestWithParam<Address::IpVersion> {
@@ -399,11 +400,13 @@ TEST_P(ConnectionImplTest, SetServerTransportSocketTimeout) {
399
400
ConnectionMocks mocks = createConnectionMocks (false );
400
401
MockTransportSocket* transport_socket = mocks.transport_socket_ .get ();
401
402
IoHandlePtr io_handle = std::make_unique<IoSocketHandleImpl>(0 );
403
+ // Avoid setting noDelay on the fake fd of 0.
404
+ auto local_addr = std::make_shared<Network::Address::PipeInstance>(" /pipe/path" );
402
405
403
406
auto * mock_timer = new NiceMock<Event::MockTimer>(mocks.dispatcher_ .get ());
404
407
auto server_connection = std::make_unique<Network::ServerConnectionImpl>(
405
408
*mocks.dispatcher_ ,
406
- std::make_unique<ConnectionSocketImpl>(std::move (io_handle), nullptr , nullptr ),
409
+ std::make_unique<ConnectionSocketImpl>(std::move (io_handle), local_addr , nullptr ),
407
410
std::move (mocks.transport_socket_ ), stream_info_, true );
408
411
409
412
EXPECT_CALL (*mock_timer, enableTimer (std::chrono::milliseconds (3 * 1000 ), _));
@@ -418,10 +421,11 @@ TEST_P(ConnectionImplTest, SetServerTransportSocketTimeoutAfterConnect) {
418
421
ConnectionMocks mocks = createConnectionMocks (false );
419
422
MockTransportSocket* transport_socket = mocks.transport_socket_ .get ();
420
423
IoHandlePtr io_handle = std::make_unique<IoSocketHandleImpl>(0 );
424
+ auto local_addr = std::make_shared<Network::Address::PipeInstance>(" /pipe/path" );
421
425
422
426
auto server_connection = std::make_unique<Network::ServerConnectionImpl>(
423
427
*mocks.dispatcher_ ,
424
- std::make_unique<ConnectionSocketImpl>(std::move (io_handle), nullptr , nullptr ),
428
+ std::make_unique<ConnectionSocketImpl>(std::move (io_handle), local_addr , nullptr ),
425
429
std::move (mocks.transport_socket_ ), stream_info_, true );
426
430
427
431
transport_socket->callbacks_ ->raiseEvent (ConnectionEvent::Connected);
@@ -436,11 +440,12 @@ TEST_P(ConnectionImplTest, ServerTransportSocketTimeoutDisabledOnConnect) {
436
440
ConnectionMocks mocks = createConnectionMocks (false );
437
441
MockTransportSocket* transport_socket = mocks.transport_socket_ .get ();
438
442
IoHandlePtr io_handle = std::make_unique<IoSocketHandleImpl>(0 );
443
+ auto local_addr = std::make_shared<Network::Address::PipeInstance>(" /pipe/path" );
439
444
440
445
auto * mock_timer = new NiceMock<Event::MockTimer>(mocks.dispatcher_ .get ());
441
446
auto server_connection = std::make_unique<Network::ServerConnectionImpl>(
442
447
*mocks.dispatcher_ ,
443
- std::make_unique<ConnectionSocketImpl>(std::move (io_handle), nullptr , nullptr ),
448
+ std::make_unique<ConnectionSocketImpl>(std::move (io_handle), local_addr , nullptr ),
444
449
std::move (mocks.transport_socket_ ), stream_info_, true );
445
450
446
451
bool timer_destroyed = false ;
@@ -598,7 +603,24 @@ TEST_P(ConnectionImplTest, ConnectionStats) {
598
603
MockConnectionStats client_connection_stats;
599
604
client_connection_->setConnectionStats (client_connection_stats.toBufferStats ());
600
605
EXPECT_TRUE (client_connection_->connecting ());
606
+
607
+ // Make sure that NO_DELAY starts out false, so that the check below verifies that it transitions
608
+ // to true actually tests something.
609
+ int initial_value = 0 ;
610
+ socklen_t size = sizeof (int );
611
+ Api::SysCallIntResult result = testClientConnection ()->socket ()->getSocketOption (
612
+ IPPROTO_TCP, TCP_NODELAY, &initial_value, &size);
613
+ ASSERT_EQ (0 , result.rc_ );
614
+ ASSERT_EQ (0 , initial_value);
615
+
601
616
client_connection_->connect ();
617
+
618
+ int new_value = 0 ;
619
+ result = testClientConnection ()->socket ()->getSocketOption (IPPROTO_TCP, TCP_NODELAY,
620
+ &initial_value, &size);
621
+ ASSERT_EQ (0 , result.rc_ );
622
+ ASSERT_EQ (0 , new_value);
623
+
602
624
// The Network::Connection class oddly uses onWrite as its indicator of if
603
625
// it's done connection, rather than the Connected event.
604
626
EXPECT_TRUE (client_connection_->connecting ());
@@ -1877,22 +1899,19 @@ TEST_P(ConnectionImplTest, DelayedCloseTimeoutNullStats) {
1877
1899
}
1878
1900
1879
1901
// Test DumpState methods.
1880
- TEST_P (ConnectionImplTest, NetworkSocketDumpsWithoutAllocatingMemory ) {
1902
+ TEST_P (ConnectionImplTest, NetworkAndPipeSocketDumpsWithoutAllocatingMemory ) {
1881
1903
std::array<char , 1024 > buffer;
1882
1904
OutputBufferStream ostream{buffer.data (), buffer.size ()};
1883
1905
IoHandlePtr io_handle = std::make_unique<IoSocketHandleImpl>(0 );
1906
+ // Avoid setting noDelay on the fake fd of 0.
1907
+ auto local_addr = std::make_shared<Network::Address::PipeInstance>(" /pipe/path" );
1884
1908
Address::InstanceConstSharedPtr server_addr;
1885
- Address::InstanceConstSharedPtr local_addr;
1886
1909
if (GetParam () == Network::Address::IpVersion::v4) {
1887
1910
server_addr = Network::Address::InstanceConstSharedPtr{
1888
1911
new Network::Address::Ipv4Instance (" 1.1.1.1" , 80 , nullptr )};
1889
- local_addr = Network::Address::InstanceConstSharedPtr{
1890
- new Network::Address::Ipv4Instance (" 1.2.3.4" , 56789 , nullptr )};
1891
1912
} else {
1892
1913
server_addr = Network::Address::InstanceConstSharedPtr{
1893
1914
new Network::Address::Ipv6Instance (" ::1" , 80 , nullptr )};
1894
- local_addr = Network::Address::InstanceConstSharedPtr{
1895
- new Network::Address::Ipv6Instance (" ::1:2:3:4" , 56789 , nullptr )};
1896
1915
}
1897
1916
1898
1917
auto connection_socket =
@@ -1914,12 +1933,12 @@ TEST_P(ConnectionImplTest, NetworkSocketDumpsWithoutAllocatingMemory) {
1914
1933
contents,
1915
1934
HasSubstr (
1916
1935
" remote_address_: 1.1.1.1:80, direct_remote_address_: 1.1.1.1:80, local_address_: "
1917
- " 1.2.3.4:56789 " ));
1936
+ " /pipe/path " ));
1918
1937
} else {
1919
1938
EXPECT_THAT (
1920
1939
contents,
1921
1940
HasSubstr (" remote_address_: [::1]:80, direct_remote_address_: [::1]:80, local_address_: "
1922
- " [::1:2:3:4]:56789 " ));
1941
+ " /pipe/path " ));
1923
1942
}
1924
1943
}
1925
1944
@@ -1928,10 +1947,11 @@ TEST_P(ConnectionImplTest, NetworkConnectionDumpsWithoutAllocatingMemory) {
1928
1947
OutputBufferStream ostream{buffer.data (), buffer.size ()};
1929
1948
ConnectionMocks mocks = createConnectionMocks (false );
1930
1949
IoHandlePtr io_handle = std::make_unique<IoSocketHandleImpl>(0 );
1950
+ auto local_addr = std::make_shared<Network::Address::PipeInstance>(" /pipe/path" );
1931
1951
1932
1952
auto server_connection = std::make_unique<Network::ServerConnectionImpl>(
1933
1953
*mocks.dispatcher_ ,
1934
- std::make_unique<ConnectionSocketImpl>(std::move (io_handle), nullptr , nullptr ),
1954
+ std::make_unique<ConnectionSocketImpl>(std::move (io_handle), local_addr , nullptr ),
1935
1955
std::move (mocks.transport_socket_ ), stream_info_, true );
1936
1956
1937
1957
// Start measuring memory and dump state.
0 commit comments