// TestConnectionCount //------------------------------------------------------------------------------ void TestTestTCPConnectionPool::TestConnectionCount() const { const uint16_t testPort( TEST_PORT ); for ( uint32_t i=0; i<NUM_TEST_PASSES; ++i ) { // multiple servers TCPConnectionPool serverA; TEST_ASSERT( serverA.Listen( testPort ) ); TEST_ASSERT( serverA.GetNumConnections() == 0 ); TCPConnectionPool serverB; TEST_ASSERT( serverB.Listen( testPort + 1 ) ); TEST_ASSERT( serverB.GetNumConnections() == 0 ); // connect client to multiple servers { TCPConnectionPool clientA; TEST_ASSERT( clientA.Connect( AStackString<>( "127.0.0.1" ), testPort ) ); TEST_ASSERT( clientA.Connect( AStackString<>( "127.0.0.1" ), testPort + 1 ) ); WAIT_UNTIL_WITH_TIMEOUT( serverA.GetNumConnections() == 1 ); WAIT_UNTIL_WITH_TIMEOUT( serverB.GetNumConnections() == 1 ); WAIT_UNTIL_WITH_TIMEOUT( clientA.GetNumConnections() == 2 ); } WAIT_UNTIL_WITH_TIMEOUT( serverA.GetNumConnections() == 0 ); WAIT_UNTIL_WITH_TIMEOUT( serverB.GetNumConnections() == 0 ); } }
REGISTER_TESTS_END // TestOneServerMultipleClients //------------------------------------------------------------------------------ void TestTestTCPConnectionPool::TestOneServerMultipleClients() const { const uint16_t testPort( TEST_PORT ); for ( uint32_t i=0; i<NUM_TEST_PASSES; ++i ) { // listen like a server TCPConnectionPool server; TEST_ASSERT( server.Listen( testPort ) ); // connect like a client TCPConnectionPool clientA; TEST_ASSERT( clientA.Connect( AStackString<>( "127.0.0.1" ), testPort ) ); // connect like a client TCPConnectionPool clientB; TEST_ASSERT( clientB.Connect( AStackString<>( "127.0.0.1" ), testPort ) ); // connect like a client TCPConnectionPool clientC; TEST_ASSERT( clientC.Connect( AStackString<>( "127.0.0.1" ), testPort ) ); // connect like a client TCPConnectionPool clientD; TEST_ASSERT( clientD.Connect( AStackString<>( "127.0.0.1" ), testPort ) ); } }
// TestMultipleServersOneClient //------------------------------------------------------------------------------ void TestTestTCPConnectionPool::TestMultipleServersOneClient() const { const uint16_t testPort( TEST_PORT ); for ( uint32_t i=0; i<NUM_TEST_PASSES; ++i ) { // multiple servers TCPConnectionPool serverA; TEST_ASSERT( serverA.Listen( testPort ) ); TCPConnectionPool serverB; TEST_ASSERT( serverB.Listen( testPort + 1 ) ); TCPConnectionPool serverC; TEST_ASSERT( serverC.Listen( testPort + 2 ) ); TCPConnectionPool serverD; TEST_ASSERT( serverD.Listen( testPort + 3 ) ); // connect client to multiple servers TCPConnectionPool clientA; TEST_ASSERT( clientA.Connect( AStackString<>( "127.0.0.1" ), testPort ) ); TEST_ASSERT( clientA.Connect( AStackString<>( "127.0.0.1" ), testPort + 1 ) ); TEST_ASSERT( clientA.Connect( AStackString<>( "127.0.0.1" ), testPort + 2 ) ); TEST_ASSERT( clientA.Connect( AStackString<>( "127.0.0.1" ), testPort + 3 ) ); } }