OLD | NEW |
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/client_socket_pool_base.h" | 5 #include "net/socket/client_socket_pool_base.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 | 714 |
715 void ReleaseAllConnections(ClientSocketPoolTest::KeepAlive keep_alive) { | 715 void ReleaseAllConnections(ClientSocketPoolTest::KeepAlive keep_alive) { |
716 test_base_.ReleaseAllConnections(keep_alive); | 716 test_base_.ReleaseAllConnections(keep_alive); |
717 } | 717 } |
718 | 718 |
719 TestSocketRequest* request(int i) { return test_base_.request(i); } | 719 TestSocketRequest* request(int i) { return test_base_.request(i); } |
720 size_t requests_size() const { return test_base_.requests_size(); } | 720 size_t requests_size() const { return test_base_.requests_size(); } |
721 ScopedVector<TestSocketRequest>* requests() { return test_base_.requests(); } | 721 ScopedVector<TestSocketRequest>* requests() { return test_base_.requests(); } |
722 size_t completion_count() const { return test_base_.completion_count(); } | 722 size_t completion_count() const { return test_base_.completion_count(); } |
723 | 723 |
724 CapturingNetLog net_log_; | 724 TestNetLog net_log_; |
725 bool connect_backup_jobs_enabled_; | 725 bool connect_backup_jobs_enabled_; |
726 bool cleanup_timer_enabled_; | 726 bool cleanup_timer_enabled_; |
727 MockClientSocketFactory client_socket_factory_; | 727 MockClientSocketFactory client_socket_factory_; |
728 TestConnectJobFactory* connect_job_factory_; | 728 TestConnectJobFactory* connect_job_factory_; |
729 scoped_refptr<TestSocketParams> params_; | 729 scoped_refptr<TestSocketParams> params_; |
730 scoped_ptr<TestClientSocketPool> pool_; | 730 scoped_ptr<TestClientSocketPool> pool_; |
731 ClientSocketPoolTest test_base_; | 731 ClientSocketPoolTest test_base_; |
732 }; | 732 }; |
733 | 733 |
734 // Even though a timeout is specified, it doesn't time out on a synchronous | 734 // Even though a timeout is specified, it doesn't time out on a synchronous |
(...skipping 12 matching lines...) Expand all Loading... |
747 base::TimeDelta::FromMicroseconds(1), | 747 base::TimeDelta::FromMicroseconds(1), |
748 &delegate, | 748 &delegate, |
749 &client_socket_factory_, | 749 &client_socket_factory_, |
750 NULL)); | 750 NULL)); |
751 EXPECT_EQ(OK, job->Connect()); | 751 EXPECT_EQ(OK, job->Connect()); |
752 } | 752 } |
753 | 753 |
754 TEST_F(ClientSocketPoolBaseTest, ConnectJob_TimedOut) { | 754 TEST_F(ClientSocketPoolBaseTest, ConnectJob_TimedOut) { |
755 TestConnectJobDelegate delegate; | 755 TestConnectJobDelegate delegate; |
756 ClientSocketHandle ignored; | 756 ClientSocketHandle ignored; |
757 CapturingNetLog log; | 757 TestNetLog log; |
758 | 758 |
759 TestClientSocketPoolBase::Request request( | 759 TestClientSocketPoolBase::Request request( |
760 &ignored, CompletionCallback(), DEFAULT_PRIORITY, | 760 &ignored, CompletionCallback(), DEFAULT_PRIORITY, |
761 internal::ClientSocketPoolBaseHelper::NORMAL, | 761 internal::ClientSocketPoolBaseHelper::NORMAL, |
762 false, params_, BoundNetLog()); | 762 false, params_, BoundNetLog()); |
763 // Deleted by TestConnectJobDelegate. | 763 // Deleted by TestConnectJobDelegate. |
764 TestConnectJob* job = | 764 TestConnectJob* job = |
765 new TestConnectJob(TestConnectJob::kMockPendingJob, | 765 new TestConnectJob(TestConnectJob::kMockPendingJob, |
766 "a", | 766 "a", |
767 request, | 767 request, |
768 base::TimeDelta::FromMicroseconds(1), | 768 base::TimeDelta::FromMicroseconds(1), |
769 &delegate, | 769 &delegate, |
770 &client_socket_factory_, | 770 &client_socket_factory_, |
771 &log); | 771 &log); |
772 ASSERT_EQ(ERR_IO_PENDING, job->Connect()); | 772 ASSERT_EQ(ERR_IO_PENDING, job->Connect()); |
773 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); | 773 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); |
774 EXPECT_EQ(ERR_TIMED_OUT, delegate.WaitForResult()); | 774 EXPECT_EQ(ERR_TIMED_OUT, delegate.WaitForResult()); |
775 | 775 |
776 CapturingNetLog::CapturedEntryList entries; | 776 TestNetLog::CapturedEntryList entries; |
777 log.GetEntries(&entries); | 777 log.GetEntries(&entries); |
778 | 778 |
779 EXPECT_EQ(6u, entries.size()); | 779 EXPECT_EQ(6u, entries.size()); |
780 EXPECT_TRUE(LogContainsBeginEvent( | 780 EXPECT_TRUE(LogContainsBeginEvent( |
781 entries, 0, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); | 781 entries, 0, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); |
782 EXPECT_TRUE(LogContainsBeginEvent( | 782 EXPECT_TRUE(LogContainsBeginEvent( |
783 entries, 1, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT)); | 783 entries, 1, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT)); |
784 EXPECT_TRUE(LogContainsEvent( | 784 EXPECT_TRUE(LogContainsEvent( |
785 entries, 2, NetLog::TYPE_CONNECT_JOB_SET_SOCKET, | 785 entries, 2, NetLog::TYPE_CONNECT_JOB_SET_SOCKET, |
786 NetLog::PHASE_NONE)); | 786 NetLog::PHASE_NONE)); |
(...skipping 21 matching lines...) Expand all Loading... |
808 callback.callback(), | 808 callback.callback(), |
809 pool_.get(), | 809 pool_.get(), |
810 log.bound())); | 810 log.bound())); |
811 EXPECT_TRUE(handle.is_initialized()); | 811 EXPECT_TRUE(handle.is_initialized()); |
812 EXPECT_TRUE(handle.socket()); | 812 EXPECT_TRUE(handle.socket()); |
813 TestLoadTimingInfoConnectedNotReused(handle); | 813 TestLoadTimingInfoConnectedNotReused(handle); |
814 | 814 |
815 handle.Reset(); | 815 handle.Reset(); |
816 TestLoadTimingInfoNotConnected(handle); | 816 TestLoadTimingInfoNotConnected(handle); |
817 | 817 |
818 CapturingNetLog::CapturedEntryList entries; | 818 TestNetLog::CapturedEntryList entries; |
819 log.GetEntries(&entries); | 819 log.GetEntries(&entries); |
820 | 820 |
821 EXPECT_EQ(4u, entries.size()); | 821 EXPECT_EQ(4u, entries.size()); |
822 EXPECT_TRUE(LogContainsBeginEvent( | 822 EXPECT_TRUE(LogContainsBeginEvent( |
823 entries, 0, NetLog::TYPE_SOCKET_POOL)); | 823 entries, 0, NetLog::TYPE_SOCKET_POOL)); |
824 EXPECT_TRUE(LogContainsEvent( | 824 EXPECT_TRUE(LogContainsEvent( |
825 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, | 825 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, |
826 NetLog::PHASE_NONE)); | 826 NetLog::PHASE_NONE)); |
827 EXPECT_TRUE(LogContainsEvent( | 827 EXPECT_TRUE(LogContainsEvent( |
828 entries, 2, NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, | 828 entries, 2, NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, |
(...skipping 20 matching lines...) Expand all Loading... |
849 params_, | 849 params_, |
850 DEFAULT_PRIORITY, | 850 DEFAULT_PRIORITY, |
851 callback.callback(), | 851 callback.callback(), |
852 pool_.get(), | 852 pool_.get(), |
853 log.bound())); | 853 log.bound())); |
854 EXPECT_FALSE(handle.socket()); | 854 EXPECT_FALSE(handle.socket()); |
855 EXPECT_FALSE(handle.is_ssl_error()); | 855 EXPECT_FALSE(handle.is_ssl_error()); |
856 EXPECT_TRUE(handle.ssl_error_response_info().headers.get() == NULL); | 856 EXPECT_TRUE(handle.ssl_error_response_info().headers.get() == NULL); |
857 TestLoadTimingInfoNotConnected(handle); | 857 TestLoadTimingInfoNotConnected(handle); |
858 | 858 |
859 CapturingNetLog::CapturedEntryList entries; | 859 TestNetLog::CapturedEntryList entries; |
860 log.GetEntries(&entries); | 860 log.GetEntries(&entries); |
861 | 861 |
862 EXPECT_EQ(3u, entries.size()); | 862 EXPECT_EQ(3u, entries.size()); |
863 EXPECT_TRUE(LogContainsBeginEvent( | 863 EXPECT_TRUE(LogContainsBeginEvent( |
864 entries, 0, NetLog::TYPE_SOCKET_POOL)); | 864 entries, 0, NetLog::TYPE_SOCKET_POOL)); |
865 EXPECT_TRUE(LogContainsEvent( | 865 EXPECT_TRUE(LogContainsEvent( |
866 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, | 866 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, |
867 NetLog::PHASE_NONE)); | 867 NetLog::PHASE_NONE)); |
868 EXPECT_TRUE(LogContainsEndEvent( | 868 EXPECT_TRUE(LogContainsEndEvent( |
869 entries, 2, NetLog::TYPE_SOCKET_POOL)); | 869 entries, 2, NetLog::TYPE_SOCKET_POOL)); |
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1684 TestLoadTimingInfoNotConnected(handle); | 1684 TestLoadTimingInfoNotConnected(handle); |
1685 | 1685 |
1686 EXPECT_EQ(OK, callback.WaitForResult()); | 1686 EXPECT_EQ(OK, callback.WaitForResult()); |
1687 EXPECT_TRUE(handle.is_initialized()); | 1687 EXPECT_TRUE(handle.is_initialized()); |
1688 EXPECT_TRUE(handle.socket()); | 1688 EXPECT_TRUE(handle.socket()); |
1689 TestLoadTimingInfoConnectedNotReused(handle); | 1689 TestLoadTimingInfoConnectedNotReused(handle); |
1690 | 1690 |
1691 handle.Reset(); | 1691 handle.Reset(); |
1692 TestLoadTimingInfoNotConnected(handle); | 1692 TestLoadTimingInfoNotConnected(handle); |
1693 | 1693 |
1694 CapturingNetLog::CapturedEntryList entries; | 1694 TestNetLog::CapturedEntryList entries; |
1695 log.GetEntries(&entries); | 1695 log.GetEntries(&entries); |
1696 | 1696 |
1697 EXPECT_EQ(4u, entries.size()); | 1697 EXPECT_EQ(4u, entries.size()); |
1698 EXPECT_TRUE(LogContainsBeginEvent( | 1698 EXPECT_TRUE(LogContainsBeginEvent( |
1699 entries, 0, NetLog::TYPE_SOCKET_POOL)); | 1699 entries, 0, NetLog::TYPE_SOCKET_POOL)); |
1700 EXPECT_TRUE(LogContainsEvent( | 1700 EXPECT_TRUE(LogContainsEvent( |
1701 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, | 1701 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, |
1702 NetLog::PHASE_NONE)); | 1702 NetLog::PHASE_NONE)); |
1703 EXPECT_TRUE(LogContainsEvent( | 1703 EXPECT_TRUE(LogContainsEvent( |
1704 entries, 2, NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, | 1704 entries, 2, NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, |
(...skipping 19 matching lines...) Expand all Loading... |
1724 params_, | 1724 params_, |
1725 DEFAULT_PRIORITY, | 1725 DEFAULT_PRIORITY, |
1726 callback.callback(), | 1726 callback.callback(), |
1727 pool_.get(), | 1727 pool_.get(), |
1728 log.bound())); | 1728 log.bound())); |
1729 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle)); | 1729 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle)); |
1730 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult()); | 1730 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult()); |
1731 EXPECT_FALSE(handle.is_ssl_error()); | 1731 EXPECT_FALSE(handle.is_ssl_error()); |
1732 EXPECT_TRUE(handle.ssl_error_response_info().headers.get() == NULL); | 1732 EXPECT_TRUE(handle.ssl_error_response_info().headers.get() == NULL); |
1733 | 1733 |
1734 CapturingNetLog::CapturedEntryList entries; | 1734 TestNetLog::CapturedEntryList entries; |
1735 log.GetEntries(&entries); | 1735 log.GetEntries(&entries); |
1736 | 1736 |
1737 EXPECT_EQ(3u, entries.size()); | 1737 EXPECT_EQ(3u, entries.size()); |
1738 EXPECT_TRUE(LogContainsBeginEvent( | 1738 EXPECT_TRUE(LogContainsBeginEvent( |
1739 entries, 0, NetLog::TYPE_SOCKET_POOL)); | 1739 entries, 0, NetLog::TYPE_SOCKET_POOL)); |
1740 EXPECT_TRUE(LogContainsEvent( | 1740 EXPECT_TRUE(LogContainsEvent( |
1741 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, | 1741 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, |
1742 NetLog::PHASE_NONE)); | 1742 NetLog::PHASE_NONE)); |
1743 EXPECT_TRUE(LogContainsEndEvent( | 1743 EXPECT_TRUE(LogContainsEndEvent( |
1744 entries, 2, NetLog::TYPE_SOCKET_POOL)); | 1744 entries, 2, NetLog::TYPE_SOCKET_POOL)); |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2223 pool_.get(), | 2223 pool_.get(), |
2224 log.bound()); | 2224 log.bound()); |
2225 ASSERT_EQ(OK, rv); | 2225 ASSERT_EQ(OK, rv); |
2226 EXPECT_TRUE(handle.is_reused()); | 2226 EXPECT_TRUE(handle.is_reused()); |
2227 TestLoadTimingInfoConnectedReused(handle); | 2227 TestLoadTimingInfoConnectedReused(handle); |
2228 | 2228 |
2229 ASSERT_TRUE(pool_->HasGroup("a")); | 2229 ASSERT_TRUE(pool_->HasGroup("a")); |
2230 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); | 2230 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); |
2231 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); | 2231 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); |
2232 | 2232 |
2233 CapturingNetLog::CapturedEntryList entries; | 2233 TestNetLog::CapturedEntryList entries; |
2234 log.GetEntries(&entries); | 2234 log.GetEntries(&entries); |
2235 EXPECT_TRUE(LogContainsEntryWithType( | 2235 EXPECT_TRUE(LogContainsEntryWithType( |
2236 entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET)); | 2236 entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET)); |
2237 } | 2237 } |
2238 | 2238 |
2239 // Make sure we cleanup old unused sockets when the cleanup timer is disabled. | 2239 // Make sure we cleanup old unused sockets when the cleanup timer is disabled. |
2240 TEST_F(ClientSocketPoolBaseTest, DisableCleanupTimerNoReuse) { | 2240 TEST_F(ClientSocketPoolBaseTest, DisableCleanupTimerNoReuse) { |
2241 // Disable cleanup timer. | 2241 // Disable cleanup timer. |
2242 internal::ClientSocketPoolBaseHelper::set_cleanup_timer_enabled(false); | 2242 internal::ClientSocketPoolBaseHelper::set_cleanup_timer_enabled(false); |
2243 | 2243 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2305 log.bound()); | 2305 log.bound()); |
2306 ASSERT_EQ(ERR_IO_PENDING, rv); | 2306 ASSERT_EQ(ERR_IO_PENDING, rv); |
2307 ASSERT_EQ(OK, callback3.WaitForResult()); | 2307 ASSERT_EQ(OK, callback3.WaitForResult()); |
2308 EXPECT_FALSE(handle.is_reused()); | 2308 EXPECT_FALSE(handle.is_reused()); |
2309 | 2309 |
2310 // Make sure the idle socket is closed. | 2310 // Make sure the idle socket is closed. |
2311 ASSERT_TRUE(pool_->HasGroup("a")); | 2311 ASSERT_TRUE(pool_->HasGroup("a")); |
2312 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); | 2312 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); |
2313 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); | 2313 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); |
2314 | 2314 |
2315 CapturingNetLog::CapturedEntryList entries; | 2315 TestNetLog::CapturedEntryList entries; |
2316 log.GetEntries(&entries); | 2316 log.GetEntries(&entries); |
2317 EXPECT_FALSE(LogContainsEntryWithType( | 2317 EXPECT_FALSE(LogContainsEntryWithType( |
2318 entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET)); | 2318 entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET)); |
2319 } | 2319 } |
2320 | 2320 |
2321 TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSockets) { | 2321 TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSockets) { |
2322 CreatePoolWithIdleTimeouts( | 2322 CreatePoolWithIdleTimeouts( |
2323 kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, | 2323 kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, |
2324 base::TimeDelta(), // Time out unused sockets immediately. | 2324 base::TimeDelta(), // Time out unused sockets immediately. |
2325 base::TimeDelta::FromDays(1)); // Don't time out used sockets. | 2325 base::TimeDelta::FromDays(1)); // Don't time out used sockets. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2377 CapturingBoundNetLog log; | 2377 CapturingBoundNetLog log; |
2378 rv = handle.Init("a", | 2378 rv = handle.Init("a", |
2379 params_, | 2379 params_, |
2380 LOWEST, | 2380 LOWEST, |
2381 callback.callback(), | 2381 callback.callback(), |
2382 pool_.get(), | 2382 pool_.get(), |
2383 log.bound()); | 2383 log.bound()); |
2384 EXPECT_EQ(OK, rv); | 2384 EXPECT_EQ(OK, rv); |
2385 EXPECT_TRUE(handle.is_reused()); | 2385 EXPECT_TRUE(handle.is_reused()); |
2386 | 2386 |
2387 CapturingNetLog::CapturedEntryList entries; | 2387 TestNetLog::CapturedEntryList entries; |
2388 log.GetEntries(&entries); | 2388 log.GetEntries(&entries); |
2389 EXPECT_TRUE(LogContainsEntryWithType( | 2389 EXPECT_TRUE(LogContainsEntryWithType( |
2390 entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET)); | 2390 entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET)); |
2391 } | 2391 } |
2392 | 2392 |
2393 // Make sure that we process all pending requests even when we're stalling | 2393 // Make sure that we process all pending requests even when we're stalling |
2394 // because of multiple releasing disconnected sockets. | 2394 // because of multiple releasing disconnected sockets. |
2395 TEST_F(ClientSocketPoolBaseTest, MultipleReleasingDisconnectedSockets) { | 2395 TEST_F(ClientSocketPoolBaseTest, MultipleReleasingDisconnectedSockets) { |
2396 CreatePoolWithIdleTimeouts( | 2396 CreatePoolWithIdleTimeouts( |
2397 kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, | 2397 kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, |
(...skipping 1706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4104 request(1)->handle()->Reset(); | 4104 request(1)->handle()->Reset(); |
4105 ASSERT_EQ(1, pool_->NumConnectJobsInGroup("a")); | 4105 ASSERT_EQ(1, pool_->NumConnectJobsInGroup("a")); |
4106 | 4106 |
4107 EXPECT_EQ(OK, request(2)->WaitForResult()); | 4107 EXPECT_EQ(OK, request(2)->WaitForResult()); |
4108 EXPECT_FALSE(request(1)->have_result()); | 4108 EXPECT_FALSE(request(1)->have_result()); |
4109 } | 4109 } |
4110 | 4110 |
4111 } // namespace | 4111 } // namespace |
4112 | 4112 |
4113 } // namespace net | 4113 } // namespace net |
OLD | NEW |