src/net/socket/transport_connect_job_unittest.cc
// Test the case of the IPv6 address being slow, thus falling back to trying to
// connect to the IPv4 address, but having the connect to the IPv6 address
// finish first.
Test the case of the IPv6 address being slow, thus falling back to trying to
connect to the IPv4 address, but having the connect to the IPv6 address
finish first.
Test the case of the IPv6 address being slow thus falling back to trying to connect to the IPv4 address but having the connect to the IPv6 address finish first .
TEST_F(TransportConnectJobTest, IPv6FallbackSocketIPv6FinishesFirst) {
  MockTransportClientSocketFactory::ClientSocketType case_types[] = {
      MockTransportClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET,
      MockTransportClientSocketFactory::MOCK_STALLED_FAILING_CLIENT_SOCKET};
  client_socket_factory_.set_client_socket_types(case_types, 2);
  client_socket_factory_.set_delay(base::TimeDelta::FromMilliseconds(
      TransportConnectJob::kIPv6FallbackTimerInMs + 50));
  host_resolver_.rules()->AddIPLiteralRule(kHostName, "2:abcd::3:4:ff,2.2.2.2",
                                           std::string());
  TestConnectJobDelegate test_delegate;
  TransportConnectJob transport_connect_job(
      DEFAULT_PRIORITY, SocketTag(), &common_connect_job_params_,
      DefaultParams(), &test_delegate, nullptr );
  test_delegate.StartJobExpectingResult(&transport_connect_job, OK,
                                        false );
  IPEndPoint endpoint;
  test_delegate.socket()->GetLocalAddress(&endpoint);
  EXPECT_TRUE(endpoint.address().IsIPv6());
  ConnectionAttempts attempts;
  test_delegate.socket()->GetConnectionAttempts(&attempts);
  ASSERT_EQ(1u, attempts.size());
  EXPECT_THAT(attempts[0].result, test::IsError(ERR_CONNECTION_FAILED));
  EXPECT_TRUE(attempts[0].endpoint.address().IsIPv4());
  EXPECT_EQ(2, client_socket_factory_.allocation_count());
}
TEST_F ( TransportConnectJobTest , IPv6FallbackSocketIPv6FinishesFirst ) { MockTransportClientSocketFactory :: ClientSocketType case_types [ ] = { MockTransportClientSocketFactory :: MOCK_DELAYED_CLIENT_SOCKET , MockTransportClientSocketFactory :: MOCK_STALLED_FAILING_CLIENT_SOCKET } ; client_socket_factory_ . set_client_socket_types ( case_types , 2 ) ; client_socket_factory_ . set_delay ( base :: TimeDelta :: FromMilliseconds ( TransportConnectJob :: kIPv6FallbackTimerInMs + 50 ) ) ; host_resolver_ . rules ( ) -> AddIPLiteralRule ( kHostName , " " , std :: string ( ) ) ; TestConnectJobDelegate test_delegate ; TransportConnectJob transport_connect_job ( DEFAULT_PRIORITY , SocketTag ( ) , & common_connect_job_params_ , DefaultParams ( ) , & test_delegate , nullptr ) ; test_delegate . StartJobExpectingResult ( & transport_connect_job , OK , false ) ; IPEndPoint endpoint ; test_delegate . socket ( ) -> GetLocalAddress ( & endpoint ) ; EXPECT_TRUE ( endpoint . address ( ) . IsIPv6 ( ) ) ; ConnectionAttempts attempts ; test_delegate . socket ( ) -> GetConnectionAttempts ( & attempts ) ; ASSERT_EQ ( 1u , attempts . size ( ) ) ; EXPECT_THAT ( attempts [ 0 ] . result , test :: IsError ( ERR_CONNECTION_FAILED ) ) ; EXPECT_TRUE ( attempts [ 0 ] . endpoint . address ( ) . IsIPv4 ( ) ) ; EXPECT_EQ ( 2 , client_socket_factory_ . allocation_count ( ) ) ; }
Test the case of the IPv6 address being slow, thus falling back to trying to
connect to the IPv4 address, but having the connect to the IPv6 address
finish first.
Test the case of the IPv6 address being slow thus falling back to trying to connect to the IPv4 address but having the connect to the IPv6 address finish first .
// This is the IPv6 socket. // This is the IPv4 socket. It stalls, but presents one failed connection // attempt on GetConnectionAttempts. // Resolve an AddressList with a IPv6 address first and then a IPv4 address. /* net_log */ /* expect_sync_result */ // Check that the failed connection attempt on the fallback socket is // collected.