| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/websocket_transport_client_socket_pool.h" | 5 #include "net/socket/websocket_transport_client_socket_pool.h" |
| 6 | 6 |
| 7 #include <queue> | 7 #include <queue> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 // RunLoop doesn't support this natively but it is easy to emulate. | 42 // RunLoop doesn't support this natively but it is easy to emulate. |
| 43 void RunLoopForTimePeriod(base::TimeDelta period) { | 43 void RunLoopForTimePeriod(base::TimeDelta period) { |
| 44 base::RunLoop run_loop; | 44 base::RunLoop run_loop; |
| 45 base::Closure quit_closure(run_loop.QuitClosure()); | 45 base::Closure quit_closure(run_loop.QuitClosure()); |
| 46 base::MessageLoop::current()->PostDelayedTask( | 46 base::MessageLoop::current()->PostDelayedTask( |
| 47 FROM_HERE, quit_closure, period); | 47 FROM_HERE, quit_closure, period); |
| 48 run_loop.Run(); | 48 run_loop.Run(); |
| 49 } | 49 } |
| 50 | 50 |
| 51 class WebSocketTransportClientSocketPoolTest : public testing::Test { | 51 class WebSocketTransportClientSocketPoolTest : public ::testing::Test { |
| 52 protected: | 52 protected: |
| 53 WebSocketTransportClientSocketPoolTest() | 53 WebSocketTransportClientSocketPoolTest() |
| 54 : params_(new TransportSocketParams( | 54 : params_(new TransportSocketParams( |
| 55 HostPortPair("www.google.com", 80), | 55 HostPortPair("www.google.com", 80), |
| 56 false, | 56 false, |
| 57 false, | 57 false, |
| 58 OnHostResolutionCallback(), | 58 OnHostResolutionCallback(), |
| 59 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)), | 59 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)), |
| 60 histograms_(new ClientSocketPoolHistograms("TCPUnitTest")), | 60 histograms_(new ClientSocketPoolHistograms("TCPUnitTest")), |
| 61 host_resolver_(new MockHostResolver), | 61 host_resolver_(new MockHostResolver), |
| 62 client_socket_factory_(&net_log_), | 62 client_socket_factory_(&net_log_), |
| 63 pool_(kMaxSockets, | 63 pool_(kMaxSockets, |
| 64 kMaxSocketsPerGroup, | 64 kMaxSocketsPerGroup, |
| 65 histograms_.get(), | 65 histograms_.get(), |
| 66 host_resolver_.get(), | 66 host_resolver_.get(), |
| 67 &client_socket_factory_, | 67 &client_socket_factory_, |
| 68 NULL) {} | 68 NULL) {} |
| 69 | 69 |
| 70 ~WebSocketTransportClientSocketPoolTest() override { | 70 ~WebSocketTransportClientSocketPoolTest() override { |
| 71 RunUntilIdle(); |
| 72 // ReleaseAllConnections() calls RunUntilIdle() after releasing each |
| 73 // connection. |
| 71 ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); | 74 ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
| 72 EXPECT_TRUE(WebSocketEndpointLockManager::GetInstance()->IsEmpty()); | 75 EXPECT_TRUE(WebSocketEndpointLockManager::GetInstance()->IsEmpty()); |
| 73 } | 76 } |
| 74 | 77 |
| 78 static void RunUntilIdle() { base::RunLoop().RunUntilIdle(); } |
| 79 |
| 75 int StartRequest(const std::string& group_name, RequestPriority priority) { | 80 int StartRequest(const std::string& group_name, RequestPriority priority) { |
| 76 scoped_refptr<TransportSocketParams> params( | 81 scoped_refptr<TransportSocketParams> params( |
| 77 new TransportSocketParams( | 82 new TransportSocketParams( |
| 78 HostPortPair("www.google.com", 80), | 83 HostPortPair("www.google.com", 80), |
| 79 false, | 84 false, |
| 80 false, | 85 false, |
| 81 OnHostResolutionCallback(), | 86 OnHostResolutionCallback(), |
| 82 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)); | 87 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)); |
| 83 return test_base_.StartRequestUsingPool( | 88 return test_base_.StartRequestUsingPool( |
| 84 &pool_, group_name, priority, params); | 89 &pool_, group_name, priority, params); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 101 ScopedVector<TestSocketRequest>* requests() { return test_base_.requests(); } | 106 ScopedVector<TestSocketRequest>* requests() { return test_base_.requests(); } |
| 102 size_t completion_count() const { return test_base_.completion_count(); } | 107 size_t completion_count() const { return test_base_.completion_count(); } |
| 103 | 108 |
| 104 CapturingNetLog net_log_; | 109 CapturingNetLog net_log_; |
| 105 scoped_refptr<TransportSocketParams> params_; | 110 scoped_refptr<TransportSocketParams> params_; |
| 106 scoped_ptr<ClientSocketPoolHistograms> histograms_; | 111 scoped_ptr<ClientSocketPoolHistograms> histograms_; |
| 107 scoped_ptr<MockHostResolver> host_resolver_; | 112 scoped_ptr<MockHostResolver> host_resolver_; |
| 108 MockTransportClientSocketFactory client_socket_factory_; | 113 MockTransportClientSocketFactory client_socket_factory_; |
| 109 WebSocketTransportClientSocketPool pool_; | 114 WebSocketTransportClientSocketPool pool_; |
| 110 ClientSocketPoolTest test_base_; | 115 ClientSocketPoolTest test_base_; |
| 116 ScopedWebSocketEndpointZeroUnlockDelay zero_unlock_delay_; |
| 111 | 117 |
| 112 private: | 118 private: |
| 113 DISALLOW_COPY_AND_ASSIGN(WebSocketTransportClientSocketPoolTest); | 119 DISALLOW_COPY_AND_ASSIGN(WebSocketTransportClientSocketPoolTest); |
| 114 }; | 120 }; |
| 115 | 121 |
| 116 TEST_F(WebSocketTransportClientSocketPoolTest, Basic) { | 122 TEST_F(WebSocketTransportClientSocketPoolTest, Basic) { |
| 117 TestCompletionCallback callback; | 123 TestCompletionCallback callback; |
| 118 ClientSocketHandle handle; | 124 ClientSocketHandle handle; |
| 119 int rv = handle.Init( | 125 int rv = handle.Init( |
| 120 "a", params_, LOW, callback.callback(), &pool_, BoundNetLog()); | 126 "a", params_, LOW, callback.callback(), &pool_, BoundNetLog()); |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 EXPECT_EQ(ERR_CONNECTION_FAILED, request(i)->WaitForResult()); | 501 EXPECT_EQ(ERR_CONNECTION_FAILED, request(i)->WaitForResult()); |
| 496 } | 502 } |
| 497 | 503 |
| 498 // The lock on the endpoint is released when a ClientSocketHandle is reset. | 504 // The lock on the endpoint is released when a ClientSocketHandle is reset. |
| 499 TEST_F(WebSocketTransportClientSocketPoolTest, LockReleasedOnHandleReset) { | 505 TEST_F(WebSocketTransportClientSocketPoolTest, LockReleasedOnHandleReset) { |
| 500 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 506 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 501 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 507 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 502 EXPECT_EQ(OK, request(0)->WaitForResult()); | 508 EXPECT_EQ(OK, request(0)->WaitForResult()); |
| 503 EXPECT_FALSE(request(1)->handle()->is_initialized()); | 509 EXPECT_FALSE(request(1)->handle()->is_initialized()); |
| 504 request(0)->handle()->Reset(); | 510 request(0)->handle()->Reset(); |
| 505 base::RunLoop().RunUntilIdle(); | 511 RunUntilIdle(); |
| 506 EXPECT_TRUE(request(1)->handle()->is_initialized()); | 512 EXPECT_TRUE(request(1)->handle()->is_initialized()); |
| 507 } | 513 } |
| 508 | 514 |
| 509 // The lock on the endpoint is released when a ClientSocketHandle is deleted. | 515 // The lock on the endpoint is released when a ClientSocketHandle is deleted. |
| 510 TEST_F(WebSocketTransportClientSocketPoolTest, LockReleasedOnHandleDelete) { | 516 TEST_F(WebSocketTransportClientSocketPoolTest, LockReleasedOnHandleDelete) { |
| 511 TestCompletionCallback callback; | 517 TestCompletionCallback callback; |
| 512 scoped_ptr<ClientSocketHandle> handle(new ClientSocketHandle); | 518 scoped_ptr<ClientSocketHandle> handle(new ClientSocketHandle); |
| 513 int rv = handle->Init( | 519 int rv = handle->Init( |
| 514 "a", params_, LOW, callback.callback(), &pool_, BoundNetLog()); | 520 "a", params_, LOW, callback.callback(), &pool_, BoundNetLog()); |
| 515 EXPECT_EQ(ERR_IO_PENDING, rv); | 521 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 516 | 522 |
| 517 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 523 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 518 EXPECT_EQ(OK, callback.WaitForResult()); | 524 EXPECT_EQ(OK, callback.WaitForResult()); |
| 519 EXPECT_FALSE(request(0)->handle()->is_initialized()); | 525 EXPECT_FALSE(request(0)->handle()->is_initialized()); |
| 520 handle.reset(); | 526 handle.reset(); |
| 521 base::RunLoop().RunUntilIdle(); | 527 RunUntilIdle(); |
| 522 EXPECT_TRUE(request(0)->handle()->is_initialized()); | 528 EXPECT_TRUE(request(0)->handle()->is_initialized()); |
| 523 } | 529 } |
| 524 | 530 |
| 525 // A new connection is performed when the lock on the previous connection is | 531 // A new connection is performed when the lock on the previous connection is |
| 526 // explicitly released. | 532 // explicitly released. |
| 527 TEST_F(WebSocketTransportClientSocketPoolTest, | 533 TEST_F(WebSocketTransportClientSocketPoolTest, |
| 528 ConnectionProceedsOnExplicitRelease) { | 534 ConnectionProceedsOnExplicitRelease) { |
| 529 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 535 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 530 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 536 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 531 EXPECT_EQ(OK, request(0)->WaitForResult()); | 537 EXPECT_EQ(OK, request(0)->WaitForResult()); |
| 532 EXPECT_FALSE(request(1)->handle()->is_initialized()); | 538 EXPECT_FALSE(request(1)->handle()->is_initialized()); |
| 533 WebSocketTransportClientSocketPool::UnlockEndpoint(request(0)->handle()); | 539 WebSocketTransportClientSocketPool::UnlockEndpoint(request(0)->handle()); |
| 534 base::RunLoop().RunUntilIdle(); | 540 RunUntilIdle(); |
| 535 EXPECT_TRUE(request(1)->handle()->is_initialized()); | 541 EXPECT_TRUE(request(1)->handle()->is_initialized()); |
| 536 } | 542 } |
| 537 | 543 |
| 538 // A connection which is cancelled before completion does not block subsequent | 544 // A connection which is cancelled before completion does not block subsequent |
| 539 // connections. | 545 // connections. |
| 540 TEST_F(WebSocketTransportClientSocketPoolTest, | 546 TEST_F(WebSocketTransportClientSocketPoolTest, |
| 541 CancelDuringConnectionReleasesLock) { | 547 CancelDuringConnectionReleasesLock) { |
| 542 MockTransportClientSocketFactory::ClientSocketType case_types[] = { | 548 MockTransportClientSocketFactory::ClientSocketType case_types[] = { |
| 543 MockTransportClientSocketFactory::MOCK_STALLED_CLIENT_SOCKET, | 549 MockTransportClientSocketFactory::MOCK_STALLED_CLIENT_SOCKET, |
| 544 MockTransportClientSocketFactory::MOCK_PENDING_CLIENT_SOCKET}; | 550 MockTransportClientSocketFactory::MOCK_PENDING_CLIENT_SOCKET}; |
| 545 | 551 |
| 546 client_socket_factory_.set_client_socket_types(case_types, | 552 client_socket_factory_.set_client_socket_types(case_types, |
| 547 arraysize(case_types)); | 553 arraysize(case_types)); |
| 548 | 554 |
| 549 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 555 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 550 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 556 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 551 base::RunLoop().RunUntilIdle(); | 557 RunUntilIdle(); |
| 552 pool_.CancelRequest("a", request(0)->handle()); | 558 pool_.CancelRequest("a", request(0)->handle()); |
| 553 EXPECT_EQ(OK, request(1)->WaitForResult()); | 559 EXPECT_EQ(OK, request(1)->WaitForResult()); |
| 554 } | 560 } |
| 555 | 561 |
| 556 // Test the case of the IPv6 address stalling, and falling back to the IPv4 | 562 // Test the case of the IPv6 address stalling, and falling back to the IPv4 |
| 557 // socket which finishes first. | 563 // socket which finishes first. |
| 558 TEST_F(WebSocketTransportClientSocketPoolTest, | 564 TEST_F(WebSocketTransportClientSocketPoolTest, |
| 559 IPv6FallbackSocketIPv4FinishesFirst) { | 565 IPv6FallbackSocketIPv4FinishesFirst) { |
| 560 WebSocketTransportClientSocketPool pool(kMaxSockets, | 566 WebSocketTransportClientSocketPool pool(kMaxSockets, |
| 561 kMaxSocketsPerGroup, | 567 kMaxSocketsPerGroup, |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 int rv = | 901 int rv = |
| 896 handle.Init("a", params_, LOW, callback.callback(), &pool, BoundNetLog()); | 902 handle.Init("a", params_, LOW, callback.callback(), &pool, BoundNetLog()); |
| 897 EXPECT_EQ(ERR_IO_PENDING, rv); | 903 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 898 | 904 |
| 899 EXPECT_EQ(ERR_TIMED_OUT, callback.WaitForResult()); | 905 EXPECT_EQ(ERR_TIMED_OUT, callback.WaitForResult()); |
| 900 } | 906 } |
| 901 | 907 |
| 902 TEST_F(WebSocketTransportClientSocketPoolTest, MaxSocketsEnforced) { | 908 TEST_F(WebSocketTransportClientSocketPoolTest, MaxSocketsEnforced) { |
| 903 host_resolver_->set_synchronous_mode(true); | 909 host_resolver_->set_synchronous_mode(true); |
| 904 for (int i = 0; i < kMaxSockets; ++i) { | 910 for (int i = 0; i < kMaxSockets; ++i) { |
| 905 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); | 911 ASSERT_EQ(OK, StartRequest("a", kDefaultPriority)); |
| 906 WebSocketTransportClientSocketPool::UnlockEndpoint(request(i)->handle()); | 912 WebSocketTransportClientSocketPool::UnlockEndpoint(request(i)->handle()); |
| 913 RunUntilIdle(); |
| 907 } | 914 } |
| 908 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 915 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 909 } | 916 } |
| 910 | 917 |
| 911 TEST_F(WebSocketTransportClientSocketPoolTest, MaxSocketsEnforcedWhenPending) { | 918 TEST_F(WebSocketTransportClientSocketPoolTest, MaxSocketsEnforcedWhenPending) { |
| 912 for (int i = 0; i < kMaxSockets + 1; ++i) { | 919 for (int i = 0; i < kMaxSockets + 1; ++i) { |
| 913 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 920 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 914 } | 921 } |
| 915 // Now there are 32 sockets waiting to connect, and one stalled. | 922 // Now there are 32 sockets waiting to connect, and one stalled. |
| 916 for (int i = 0; i < kMaxSockets; ++i) { | 923 for (int i = 0; i < kMaxSockets; ++i) { |
| 917 base::RunLoop().RunUntilIdle(); | 924 RunUntilIdle(); |
| 918 EXPECT_TRUE(request(i)->handle()->is_initialized()); | 925 EXPECT_TRUE(request(i)->handle()->is_initialized()); |
| 919 EXPECT_TRUE(request(i)->handle()->socket()); | 926 EXPECT_TRUE(request(i)->handle()->socket()); |
| 920 WebSocketTransportClientSocketPool::UnlockEndpoint(request(i)->handle()); | 927 WebSocketTransportClientSocketPool::UnlockEndpoint(request(i)->handle()); |
| 921 } | 928 } |
| 922 // Now there are 32 sockets connected, and one stalled. | 929 // Now there are 32 sockets connected, and one stalled. |
| 923 base::RunLoop().RunUntilIdle(); | 930 RunUntilIdle(); |
| 924 EXPECT_FALSE(request(kMaxSockets)->handle()->is_initialized()); | 931 EXPECT_FALSE(request(kMaxSockets)->handle()->is_initialized()); |
| 925 EXPECT_FALSE(request(kMaxSockets)->handle()->socket()); | 932 EXPECT_FALSE(request(kMaxSockets)->handle()->socket()); |
| 926 } | 933 } |
| 927 | 934 |
| 928 TEST_F(WebSocketTransportClientSocketPoolTest, StalledSocketReleased) { | 935 TEST_F(WebSocketTransportClientSocketPoolTest, StalledSocketReleased) { |
| 929 host_resolver_->set_synchronous_mode(true); | 936 host_resolver_->set_synchronous_mode(true); |
| 930 for (int i = 0; i < kMaxSockets; ++i) { | 937 for (int i = 0; i < kMaxSockets; ++i) { |
| 931 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); | 938 ASSERT_EQ(OK, StartRequest("a", kDefaultPriority)); |
| 932 WebSocketTransportClientSocketPool::UnlockEndpoint(request(i)->handle()); | 939 WebSocketTransportClientSocketPool::UnlockEndpoint(request(i)->handle()); |
| 940 RunUntilIdle(); |
| 933 } | 941 } |
| 934 | 942 |
| 935 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 943 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 936 ReleaseOneConnection(ClientSocketPoolTest::NO_KEEP_ALIVE); | 944 ReleaseOneConnection(ClientSocketPoolTest::NO_KEEP_ALIVE); |
| 937 EXPECT_TRUE(request(kMaxSockets)->handle()->is_initialized()); | 945 EXPECT_TRUE(request(kMaxSockets)->handle()->is_initialized()); |
| 938 EXPECT_TRUE(request(kMaxSockets)->handle()->socket()); | 946 EXPECT_TRUE(request(kMaxSockets)->handle()->socket()); |
| 939 } | 947 } |
| 940 | 948 |
| 941 TEST_F(WebSocketTransportClientSocketPoolTest, IsStalledTrueWhenStalled) { | 949 TEST_F(WebSocketTransportClientSocketPoolTest, IsStalledTrueWhenStalled) { |
| 942 for (int i = 0; i < kMaxSockets + 1; ++i) { | 950 for (int i = 0; i < kMaxSockets + 1; ++i) { |
| 943 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 951 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 944 } | 952 } |
| 945 EXPECT_EQ(OK, request(0)->WaitForResult()); | 953 EXPECT_EQ(OK, request(0)->WaitForResult()); |
| 946 EXPECT_TRUE(pool_.IsStalled()); | 954 EXPECT_TRUE(pool_.IsStalled()); |
| 947 } | 955 } |
| 948 | 956 |
| 949 TEST_F(WebSocketTransportClientSocketPoolTest, | 957 TEST_F(WebSocketTransportClientSocketPoolTest, |
| 950 CancellingPendingSocketUnstallsStalledSocket) { | 958 CancellingPendingSocketUnstallsStalledSocket) { |
| 951 for (int i = 0; i < kMaxSockets + 1; ++i) { | 959 for (int i = 0; i < kMaxSockets + 1; ++i) { |
| 952 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 960 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 953 } | 961 } |
| 954 EXPECT_EQ(OK, request(0)->WaitForResult()); | 962 EXPECT_EQ(OK, request(0)->WaitForResult()); |
| 955 request(1)->handle()->Reset(); | 963 request(1)->handle()->Reset(); |
| 956 base::RunLoop().RunUntilIdle(); | 964 RunUntilIdle(); |
| 957 EXPECT_FALSE(pool_.IsStalled()); | 965 EXPECT_FALSE(pool_.IsStalled()); |
| 958 } | 966 } |
| 959 | 967 |
| 960 TEST_F(WebSocketTransportClientSocketPoolTest, | 968 TEST_F(WebSocketTransportClientSocketPoolTest, |
| 961 LoadStateOfStalledSocketIsWaitingForAvailableSocket) { | 969 LoadStateOfStalledSocketIsWaitingForAvailableSocket) { |
| 962 for (int i = 0; i < kMaxSockets + 1; ++i) { | 970 for (int i = 0; i < kMaxSockets + 1; ++i) { |
| 963 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 971 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 964 } | 972 } |
| 965 EXPECT_EQ(LOAD_STATE_WAITING_FOR_AVAILABLE_SOCKET, | 973 EXPECT_EQ(LOAD_STATE_WAITING_FOR_AVAILABLE_SOCKET, |
| 966 pool_.GetLoadState("a", request(kMaxSockets)->handle())); | 974 pool_.GetLoadState("a", request(kMaxSockets)->handle())); |
| 967 } | 975 } |
| 968 | 976 |
| 969 TEST_F(WebSocketTransportClientSocketPoolTest, | 977 TEST_F(WebSocketTransportClientSocketPoolTest, |
| 970 CancellingStalledSocketUnstallsPool) { | 978 CancellingStalledSocketUnstallsPool) { |
| 971 for (int i = 0; i < kMaxSockets + 1; ++i) { | 979 for (int i = 0; i < kMaxSockets + 1; ++i) { |
| 972 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 980 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 973 } | 981 } |
| 974 request(kMaxSockets)->handle()->Reset(); | 982 request(kMaxSockets)->handle()->Reset(); |
| 983 RunUntilIdle(); |
| 975 EXPECT_FALSE(pool_.IsStalled()); | 984 EXPECT_FALSE(pool_.IsStalled()); |
| 976 } | 985 } |
| 977 | 986 |
| 978 TEST_F(WebSocketTransportClientSocketPoolTest, | 987 TEST_F(WebSocketTransportClientSocketPoolTest, |
| 979 FlushWithErrorFlushesPendingConnections) { | 988 FlushWithErrorFlushesPendingConnections) { |
| 980 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 989 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 981 pool_.FlushWithError(ERR_FAILED); | 990 pool_.FlushWithError(ERR_FAILED); |
| 982 EXPECT_EQ(ERR_FAILED, request(0)->WaitForResult()); | 991 EXPECT_EQ(ERR_FAILED, request(0)->WaitForResult()); |
| 983 } | 992 } |
| 984 | 993 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1107 | 1116 |
| 1108 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 1117 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 1109 | 1118 |
| 1110 base::Closure connect_trigger = | 1119 base::Closure connect_trigger = |
| 1111 client_socket_factory_.WaitForTriggerableSocketCreation(); | 1120 client_socket_factory_.WaitForTriggerableSocketCreation(); |
| 1112 | 1121 |
| 1113 connect_trigger.Run(); // Calls InvokeUserCallbackLater() | 1122 connect_trigger.Run(); // Calls InvokeUserCallbackLater() |
| 1114 | 1123 |
| 1115 request(0)->handle()->Reset(); // calls CancelRequest() | 1124 request(0)->handle()->Reset(); // calls CancelRequest() |
| 1116 | 1125 |
| 1126 RunUntilIdle(); |
| 1117 // We should now be able to create a new connection without blocking on the | 1127 // We should now be able to create a new connection without blocking on the |
| 1118 // endpoint lock. | 1128 // endpoint lock. |
| 1119 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); | 1129 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); |
| 1120 } | 1130 } |
| 1121 | 1131 |
| 1122 // A handshake completing and then the WebSocket closing should only release one | 1132 // A handshake completing and then the WebSocket closing should only release one |
| 1123 // Endpoint, not two. | 1133 // Endpoint, not two. |
| 1124 TEST_F(WebSocketTransportClientSocketPoolTest, EndpointLockIsOnlyReleasedOnce) { | 1134 TEST_F(WebSocketTransportClientSocketPoolTest, EndpointLockIsOnlyReleasedOnce) { |
| 1125 host_resolver_->set_synchronous_mode(true); | 1135 host_resolver_->set_synchronous_mode(true); |
| 1126 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); | 1136 ASSERT_EQ(OK, StartRequest("a", kDefaultPriority)); |
| 1127 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 1137 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 1128 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 1138 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 1129 // First socket completes handshake. | 1139 // First socket completes handshake. |
| 1130 WebSocketTransportClientSocketPool::UnlockEndpoint(request(0)->handle()); | 1140 WebSocketTransportClientSocketPool::UnlockEndpoint(request(0)->handle()); |
| 1141 RunUntilIdle(); |
| 1131 // First socket is closed. | 1142 // First socket is closed. |
| 1132 request(0)->handle()->Reset(); | 1143 request(0)->handle()->Reset(); |
| 1133 // Second socket should have been released. | 1144 // Second socket should have been released. |
| 1134 EXPECT_EQ(OK, request(1)->WaitForResult()); | 1145 EXPECT_EQ(OK, request(1)->WaitForResult()); |
| 1135 // Third socket should still be waiting for endpoint. | 1146 // Third socket should still be waiting for endpoint. |
| 1136 ASSERT_FALSE(request(2)->handle()->is_initialized()); | 1147 ASSERT_FALSE(request(2)->handle()->is_initialized()); |
| 1137 EXPECT_EQ(LOAD_STATE_WAITING_FOR_AVAILABLE_SOCKET, | 1148 EXPECT_EQ(LOAD_STATE_WAITING_FOR_AVAILABLE_SOCKET, |
| 1138 request(2)->handle()->GetLoadState()); | 1149 request(2)->handle()->GetLoadState()); |
| 1139 } | 1150 } |
| 1140 | 1151 |
| 1141 } // namespace | 1152 } // namespace |
| 1142 | 1153 |
| 1143 } // namespace net | 1154 } // namespace net |
| OLD | NEW |