Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: net/socket/transport_client_socket_pool_unittest.cc

Issue 1096203006: Collect all ConnectionAttempts from both sockets in TransportConnectJob. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@domrel_serverip1
Patch Set: Return fake ConnectionAttempt in MockTCPClientSocket Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/socket/transport_client_socket_pool.h" 5 #include "net/socket/transport_client_socket_pool.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 // Let the second connect be synchronous. Otherwise, the emulated 769 // Let the second connect be synchronous. Otherwise, the emulated
770 // host resolution takes an extra trip through the message loop. 770 // host resolution takes an extra trip through the message loop.
771 host_resolver_->set_synchronous_mode(true); 771 host_resolver_->set_synchronous_mode(true);
772 772
773 // Let the appropriate socket connect. 773 // Let the appropriate socket connect.
774 base::MessageLoop::current()->RunUntilIdle(); 774 base::MessageLoop::current()->RunUntilIdle();
775 775
776 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult()); 776 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult());
777 EXPECT_FALSE(handle.is_initialized()); 777 EXPECT_FALSE(handle.is_initialized());
778 EXPECT_FALSE(handle.socket()); 778 EXPECT_FALSE(handle.socket());
779 ASSERT_EQ(1u, handle.connection_attempts().size());
780 EXPECT_EQ(ERR_CONNECTION_FAILED, handle.connection_attempts()[0].result);
779 EXPECT_EQ(0, pool_.IdleSocketCount()); 781 EXPECT_EQ(0, pool_.IdleSocketCount());
780 handle.Reset(); 782 handle.Reset();
781 783
782 // Reset for the next case. 784 // Reset for the next case.
783 host_resolver_->set_synchronous_mode(false); 785 host_resolver_->set_synchronous_mode(false);
784 } 786 }
785 787
786 // Test the case where a socket took long enough to start the creation 788 // Test the case where a socket took long enough to start the creation
787 // of the backup socket and eventually completes, but the backup socket 789 // of the backup socket and eventually completes, but the backup socket
788 // fails. 790 // fails.
(...skipping 28 matching lines...) Expand all
817 // Let the second connect be synchronous. Otherwise, the emulated 819 // Let the second connect be synchronous. Otherwise, the emulated
818 // host resolution takes an extra trip through the message loop. 820 // host resolution takes an extra trip through the message loop.
819 host_resolver_->set_synchronous_mode(true); 821 host_resolver_->set_synchronous_mode(true);
820 822
821 // Let the appropriate socket connect. 823 // Let the appropriate socket connect.
822 base::MessageLoop::current()->RunUntilIdle(); 824 base::MessageLoop::current()->RunUntilIdle();
823 825
824 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult()); 826 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult());
825 EXPECT_FALSE(handle.is_initialized()); 827 EXPECT_FALSE(handle.is_initialized());
826 EXPECT_FALSE(handle.socket()); 828 EXPECT_FALSE(handle.socket());
829 ASSERT_EQ(1u, handle.connection_attempts().size());
830 EXPECT_EQ(ERR_CONNECTION_FAILED, handle.connection_attempts()[0].result);
827 handle.Reset(); 831 handle.Reset();
828 832
829 // Reset for the next case. 833 // Reset for the next case.
830 host_resolver_->set_synchronous_mode(false); 834 host_resolver_->set_synchronous_mode(false);
831 } 835 }
832 836
833 // Test the case of the IPv6 address stalling, and falling back to the IPv4 837 // Test the case of the IPv6 address stalling, and falling back to the IPv4
834 // socket which finishes first. 838 // socket which finishes first.
835 TEST_F(TransportClientSocketPoolTest, IPv6FallbackSocketIPv4FinishesFirst) { 839 TEST_F(TransportClientSocketPoolTest, IPv6FallbackSocketIPv4FinishesFirst) {
836 // Create a pool without backup jobs. 840 // Create a pool without backup jobs.
837 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); 841 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false);
838 TransportClientSocketPool pool(kMaxSockets, 842 TransportClientSocketPool pool(kMaxSockets,
839 kMaxSocketsPerGroup, 843 kMaxSocketsPerGroup,
840 host_resolver_.get(), 844 host_resolver_.get(),
841 &client_socket_factory_, 845 &client_socket_factory_,
842 NULL); 846 NULL);
843 847
844 MockTransportClientSocketFactory::ClientSocketType case_types[] = { 848 MockTransportClientSocketFactory::ClientSocketType case_types[] = {
845 // This is the IPv6 socket. 849 // This is the IPv6 socket. It stalls, but presents one failed connection
846 MockTransportClientSocketFactory::MOCK_STALLED_CLIENT_SOCKET, 850 // attempt on GetConnectionAttempts.
847 // This is the IPv4 socket. 851 MockTransportClientSocketFactory::MOCK_STALLED_FAILING_CLIENT_SOCKET,
848 MockTransportClientSocketFactory::MOCK_PENDING_CLIENT_SOCKET 852 // This is the IPv4 socket.
849 }; 853 MockTransportClientSocketFactory::MOCK_PENDING_CLIENT_SOCKET};
850 854
851 client_socket_factory_.set_client_socket_types(case_types, 2); 855 client_socket_factory_.set_client_socket_types(case_types, 2);
852 856
853 // Resolve an AddressList with a IPv6 address first and then a IPv4 address. 857 // Resolve an AddressList with a IPv6 address first and then a IPv4 address.
854 host_resolver_->rules() 858 host_resolver_->rules()
855 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,2.2.2.2", std::string()); 859 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,2.2.2.2", std::string());
856 860
857 TestCompletionCallback callback; 861 TestCompletionCallback callback;
858 ClientSocketHandle handle; 862 ClientSocketHandle handle;
859 int rv = handle.Init("a", params_, LOW, callback.callback(), &pool, 863 int rv = handle.Init("a", params_, LOW, callback.callback(), &pool,
860 BoundNetLog()); 864 BoundNetLog());
861 EXPECT_EQ(ERR_IO_PENDING, rv); 865 EXPECT_EQ(ERR_IO_PENDING, rv);
862 EXPECT_FALSE(handle.is_initialized()); 866 EXPECT_FALSE(handle.is_initialized());
863 EXPECT_FALSE(handle.socket()); 867 EXPECT_FALSE(handle.socket());
864 868
865 EXPECT_EQ(OK, callback.WaitForResult()); 869 EXPECT_EQ(OK, callback.WaitForResult());
866 EXPECT_TRUE(handle.is_initialized()); 870 EXPECT_TRUE(handle.is_initialized());
867 EXPECT_TRUE(handle.socket()); 871 EXPECT_TRUE(handle.socket());
868 IPEndPoint endpoint; 872 IPEndPoint endpoint;
869 handle.socket()->GetLocalAddress(&endpoint); 873 handle.socket()->GetLocalAddress(&endpoint);
870 EXPECT_EQ(kIPv4AddressSize, endpoint.address().size()); 874 EXPECT_EQ(kIPv4AddressSize, endpoint.address().size());
875
876 // Check that the failed connection attempt on the main socket is collected.
877 ConnectionAttempts attempts;
878 handle.socket()->GetConnectionAttempts(&attempts);
879 ASSERT_EQ(1u, attempts.size());
880 EXPECT_EQ(ERR_CONNECTION_FAILED, attempts[0].result);
881 EXPECT_EQ(kIPv6AddressSize, attempts[0].endpoint.address().size());
882
871 EXPECT_EQ(2, client_socket_factory_.allocation_count()); 883 EXPECT_EQ(2, client_socket_factory_.allocation_count());
872 } 884 }
873 885
874 // Test the case of the IPv6 address being slow, thus falling back to trying to 886 // Test the case of the IPv6 address being slow, thus falling back to trying to
875 // connect to the IPv4 address, but having the connect to the IPv6 address 887 // connect to the IPv4 address, but having the connect to the IPv6 address
876 // finish first. 888 // finish first.
877 TEST_F(TransportClientSocketPoolTest, IPv6FallbackSocketIPv6FinishesFirst) { 889 TEST_F(TransportClientSocketPoolTest, IPv6FallbackSocketIPv6FinishesFirst) {
878 // Create a pool without backup jobs. 890 // Create a pool without backup jobs.
879 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); 891 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false);
880 TransportClientSocketPool pool(kMaxSockets, 892 TransportClientSocketPool pool(kMaxSockets,
881 kMaxSocketsPerGroup, 893 kMaxSocketsPerGroup,
882 host_resolver_.get(), 894 host_resolver_.get(),
883 &client_socket_factory_, 895 &client_socket_factory_,
884 NULL); 896 NULL);
885 897
886 MockTransportClientSocketFactory::ClientSocketType case_types[] = { 898 MockTransportClientSocketFactory::ClientSocketType case_types[] = {
887 // This is the IPv6 socket. 899 // This is the IPv6 socket.
888 MockTransportClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET, 900 MockTransportClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET,
889 // This is the IPv4 socket. 901 // This is the IPv4 socket. It stalls, but presents one failed connection
890 MockTransportClientSocketFactory::MOCK_STALLED_CLIENT_SOCKET 902 // attempt on GetConnectionATtempts.
891 }; 903 MockTransportClientSocketFactory::MOCK_STALLED_FAILING_CLIENT_SOCKET};
892 904
893 client_socket_factory_.set_client_socket_types(case_types, 2); 905 client_socket_factory_.set_client_socket_types(case_types, 2);
894 client_socket_factory_.set_delay(base::TimeDelta::FromMilliseconds( 906 client_socket_factory_.set_delay(base::TimeDelta::FromMilliseconds(
895 TransportConnectJobHelper::kIPv6FallbackTimerInMs + 50)); 907 TransportConnectJobHelper::kIPv6FallbackTimerInMs + 50));
896 908
897 // Resolve an AddressList with a IPv6 address first and then a IPv4 address. 909 // Resolve an AddressList with a IPv6 address first and then a IPv4 address.
898 host_resolver_->rules() 910 host_resolver_->rules()
899 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,2.2.2.2", std::string()); 911 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,2.2.2.2", std::string());
900 912
901 TestCompletionCallback callback; 913 TestCompletionCallback callback;
902 ClientSocketHandle handle; 914 ClientSocketHandle handle;
903 int rv = handle.Init("a", params_, LOW, callback.callback(), &pool, 915 int rv = handle.Init("a", params_, LOW, callback.callback(), &pool,
904 BoundNetLog()); 916 BoundNetLog());
905 EXPECT_EQ(ERR_IO_PENDING, rv); 917 EXPECT_EQ(ERR_IO_PENDING, rv);
906 EXPECT_FALSE(handle.is_initialized()); 918 EXPECT_FALSE(handle.is_initialized());
907 EXPECT_FALSE(handle.socket()); 919 EXPECT_FALSE(handle.socket());
908 920
909 EXPECT_EQ(OK, callback.WaitForResult()); 921 EXPECT_EQ(OK, callback.WaitForResult());
910 EXPECT_TRUE(handle.is_initialized()); 922 EXPECT_TRUE(handle.is_initialized());
911 EXPECT_TRUE(handle.socket()); 923 EXPECT_TRUE(handle.socket());
912 IPEndPoint endpoint; 924 IPEndPoint endpoint;
913 handle.socket()->GetLocalAddress(&endpoint); 925 handle.socket()->GetLocalAddress(&endpoint);
914 EXPECT_EQ(kIPv6AddressSize, endpoint.address().size()); 926 EXPECT_EQ(kIPv6AddressSize, endpoint.address().size());
927
928 // Check that the failed connection attempt on the fallback socket is
929 // collected.
930 ConnectionAttempts attempts;
931 handle.socket()->GetConnectionAttempts(&attempts);
932 ASSERT_EQ(1u, attempts.size());
933 EXPECT_EQ(ERR_CONNECTION_FAILED, attempts[0].result);
934 EXPECT_EQ(kIPv4AddressSize, attempts[0].endpoint.address().size());
935
915 EXPECT_EQ(2, client_socket_factory_.allocation_count()); 936 EXPECT_EQ(2, client_socket_factory_.allocation_count());
916 } 937 }
917 938
918 TEST_F(TransportClientSocketPoolTest, IPv6NoIPv4AddressesToFallbackTo) { 939 TEST_F(TransportClientSocketPoolTest, IPv6NoIPv4AddressesToFallbackTo) {
919 // Create a pool without backup jobs. 940 // Create a pool without backup jobs.
920 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); 941 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false);
921 TransportClientSocketPool pool(kMaxSockets, 942 TransportClientSocketPool pool(kMaxSockets,
922 kMaxSocketsPerGroup, 943 kMaxSocketsPerGroup,
923 host_resolver_.get(), 944 host_resolver_.get(),
924 &client_socket_factory_, 945 &client_socket_factory_,
(...skipping 13 matching lines...) Expand all
938 EXPECT_EQ(ERR_IO_PENDING, rv); 959 EXPECT_EQ(ERR_IO_PENDING, rv);
939 EXPECT_FALSE(handle.is_initialized()); 960 EXPECT_FALSE(handle.is_initialized());
940 EXPECT_FALSE(handle.socket()); 961 EXPECT_FALSE(handle.socket());
941 962
942 EXPECT_EQ(OK, callback.WaitForResult()); 963 EXPECT_EQ(OK, callback.WaitForResult());
943 EXPECT_TRUE(handle.is_initialized()); 964 EXPECT_TRUE(handle.is_initialized());
944 EXPECT_TRUE(handle.socket()); 965 EXPECT_TRUE(handle.socket());
945 IPEndPoint endpoint; 966 IPEndPoint endpoint;
946 handle.socket()->GetLocalAddress(&endpoint); 967 handle.socket()->GetLocalAddress(&endpoint);
947 EXPECT_EQ(kIPv6AddressSize, endpoint.address().size()); 968 EXPECT_EQ(kIPv6AddressSize, endpoint.address().size());
969 EXPECT_EQ(0u, handle.connection_attempts().size());
948 EXPECT_EQ(1, client_socket_factory_.allocation_count()); 970 EXPECT_EQ(1, client_socket_factory_.allocation_count());
949 } 971 }
950 972
951 TEST_F(TransportClientSocketPoolTest, IPv4HasNoFallback) { 973 TEST_F(TransportClientSocketPoolTest, IPv4HasNoFallback) {
952 // Create a pool without backup jobs. 974 // Create a pool without backup jobs.
953 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); 975 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false);
954 TransportClientSocketPool pool(kMaxSockets, 976 TransportClientSocketPool pool(kMaxSockets,
955 kMaxSocketsPerGroup, 977 kMaxSocketsPerGroup,
956 host_resolver_.get(), 978 host_resolver_.get(),
957 &client_socket_factory_, 979 &client_socket_factory_,
(...skipping 12 matching lines...) Expand all
970 EXPECT_EQ(ERR_IO_PENDING, rv); 992 EXPECT_EQ(ERR_IO_PENDING, rv);
971 EXPECT_FALSE(handle.is_initialized()); 993 EXPECT_FALSE(handle.is_initialized());
972 EXPECT_FALSE(handle.socket()); 994 EXPECT_FALSE(handle.socket());
973 995
974 EXPECT_EQ(OK, callback.WaitForResult()); 996 EXPECT_EQ(OK, callback.WaitForResult());
975 EXPECT_TRUE(handle.is_initialized()); 997 EXPECT_TRUE(handle.is_initialized());
976 EXPECT_TRUE(handle.socket()); 998 EXPECT_TRUE(handle.socket());
977 IPEndPoint endpoint; 999 IPEndPoint endpoint;
978 handle.socket()->GetLocalAddress(&endpoint); 1000 handle.socket()->GetLocalAddress(&endpoint);
979 EXPECT_EQ(kIPv4AddressSize, endpoint.address().size()); 1001 EXPECT_EQ(kIPv4AddressSize, endpoint.address().size());
1002 EXPECT_EQ(0u, handle.connection_attempts().size());
980 EXPECT_EQ(1, client_socket_factory_.allocation_count()); 1003 EXPECT_EQ(1, client_socket_factory_.allocation_count());
981 } 1004 }
982 1005
983 // Test that if TCP FastOpen is enabled, it is set on the socket 1006 // Test that if TCP FastOpen is enabled, it is set on the socket
984 // when we have only an IPv4 address. 1007 // when we have only an IPv4 address.
985 TEST_F(TransportClientSocketPoolTest, TCPFastOpenOnIPv4WithNoFallback) { 1008 TEST_F(TransportClientSocketPoolTest, TCPFastOpenOnIPv4WithNoFallback) {
986 // Create a pool without backup jobs. 1009 // Create a pool without backup jobs.
987 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); 1010 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false);
988 TransportClientSocketPool pool(kMaxSockets, 1011 TransportClientSocketPool pool(kMaxSockets,
989 kMaxSocketsPerGroup, 1012 kMaxSocketsPerGroup,
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 handle.socket()->GetLocalAddress(&endpoint); 1126 handle.socket()->GetLocalAddress(&endpoint);
1104 EXPECT_EQ(kIPv6AddressSize, endpoint.address().size()); 1127 EXPECT_EQ(kIPv6AddressSize, endpoint.address().size());
1105 EXPECT_EQ(1, client_socket_factory_.allocation_count()); 1128 EXPECT_EQ(1, client_socket_factory_.allocation_count());
1106 // Verify that TCP FastOpen was not turned on for the socket. 1129 // Verify that TCP FastOpen was not turned on for the socket.
1107 EXPECT_FALSE(handle.socket()->UsingTCPFastOpen()); 1130 EXPECT_FALSE(handle.socket()->UsingTCPFastOpen());
1108 } 1131 }
1109 1132
1110 } // namespace 1133 } // namespace
1111 1134
1112 } // namespace net 1135 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/transport_client_socket_pool_test_util.cc ('k') | net/socket/unix_domain_client_socket_posix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698