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

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

Issue 10546071: CapturingNetLog - remove maximum entries constructor argument. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 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 | Annotate | Revision Log
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/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 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 base::TimeDelta::FromMicroseconds(1), 755 base::TimeDelta::FromMicroseconds(1),
756 &delegate, 756 &delegate,
757 &client_socket_factory_, 757 &client_socket_factory_,
758 NULL)); 758 NULL));
759 EXPECT_EQ(OK, job->Connect()); 759 EXPECT_EQ(OK, job->Connect());
760 } 760 }
761 761
762 TEST_F(ClientSocketPoolBaseTest, ConnectJob_TimedOut) { 762 TEST_F(ClientSocketPoolBaseTest, ConnectJob_TimedOut) {
763 TestConnectJobDelegate delegate; 763 TestConnectJobDelegate delegate;
764 ClientSocketHandle ignored; 764 ClientSocketHandle ignored;
765 CapturingNetLog log(CapturingNetLog::kUnbounded); 765 CapturingNetLog log;
766 766
767 TestClientSocketPoolBase::Request request( 767 TestClientSocketPoolBase::Request request(
768 &ignored, CompletionCallback(), kDefaultPriority, 768 &ignored, CompletionCallback(), kDefaultPriority,
769 internal::ClientSocketPoolBaseHelper::NORMAL, 769 internal::ClientSocketPoolBaseHelper::NORMAL,
770 false, params_, BoundNetLog()); 770 false, params_, BoundNetLog());
771 // Deleted by TestConnectJobDelegate. 771 // Deleted by TestConnectJobDelegate.
772 TestConnectJob* job = 772 TestConnectJob* job =
773 new TestConnectJob(TestConnectJob::kMockPendingJob, 773 new TestConnectJob(TestConnectJob::kMockPendingJob,
774 "a", 774 "a",
775 request, 775 request,
776 base::TimeDelta::FromMicroseconds(1), 776 base::TimeDelta::FromMicroseconds(1),
777 &delegate, 777 &delegate,
778 &client_socket_factory_, 778 &client_socket_factory_,
779 &log); 779 &log);
780 ASSERT_EQ(ERR_IO_PENDING, job->Connect()); 780 ASSERT_EQ(ERR_IO_PENDING, job->Connect());
781 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); 781 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1));
782 EXPECT_EQ(ERR_TIMED_OUT, delegate.WaitForResult()); 782 EXPECT_EQ(ERR_TIMED_OUT, delegate.WaitForResult());
783 783
784 net::CapturingNetLog::CapturedEntryList entries; 784 CapturingNetLog::CapturedEntryList entries;
785 log.GetEntries(&entries); 785 log.GetEntries(&entries);
786 786
787 EXPECT_EQ(6u, entries.size()); 787 EXPECT_EQ(6u, entries.size());
788 EXPECT_TRUE(LogContainsBeginEvent( 788 EXPECT_TRUE(LogContainsBeginEvent(
789 entries, 0, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); 789 entries, 0, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB));
790 EXPECT_TRUE(LogContainsBeginEvent( 790 EXPECT_TRUE(LogContainsBeginEvent(
791 entries, 1, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT)); 791 entries, 1, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT));
792 EXPECT_TRUE(LogContainsEvent( 792 EXPECT_TRUE(LogContainsEvent(
793 entries, 2, NetLog::TYPE_CONNECT_JOB_SET_SOCKET, 793 entries, 2, NetLog::TYPE_CONNECT_JOB_SET_SOCKET,
794 NetLog::PHASE_NONE)); 794 NetLog::PHASE_NONE));
795 EXPECT_TRUE(LogContainsEvent( 795 EXPECT_TRUE(LogContainsEvent(
796 entries, 3, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_TIMED_OUT, 796 entries, 3, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_TIMED_OUT,
797 NetLog::PHASE_NONE)); 797 NetLog::PHASE_NONE));
798 EXPECT_TRUE(LogContainsEndEvent( 798 EXPECT_TRUE(LogContainsEndEvent(
799 entries, 4, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT)); 799 entries, 4, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT));
800 EXPECT_TRUE(LogContainsEndEvent( 800 EXPECT_TRUE(LogContainsEndEvent(
801 entries, 5, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); 801 entries, 5, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB));
802 } 802 }
803 803
804 TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) { 804 TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) {
805 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 805 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
806 806
807 TestCompletionCallback callback; 807 TestCompletionCallback callback;
808 ClientSocketHandle handle; 808 ClientSocketHandle handle;
809 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 809 CapturingBoundNetLog log;
810 810
811 EXPECT_EQ(OK, 811 EXPECT_EQ(OK,
812 handle.Init("a", 812 handle.Init("a",
813 params_, 813 params_,
814 kDefaultPriority, 814 kDefaultPriority,
815 callback.callback(), 815 callback.callback(),
816 pool_.get(), 816 pool_.get(),
817 log.bound())); 817 log.bound()));
818 EXPECT_TRUE(handle.is_initialized()); 818 EXPECT_TRUE(handle.is_initialized());
819 EXPECT_TRUE(handle.socket()); 819 EXPECT_TRUE(handle.socket());
820 handle.Reset(); 820 handle.Reset();
821 821
822 net::CapturingNetLog::CapturedEntryList entries; 822 CapturingNetLog::CapturedEntryList entries;
823 log.GetEntries(&entries); 823 log.GetEntries(&entries);
824 824
825 EXPECT_EQ(4u, entries.size()); 825 EXPECT_EQ(4u, entries.size());
826 EXPECT_TRUE(LogContainsBeginEvent( 826 EXPECT_TRUE(LogContainsBeginEvent(
827 entries, 0, NetLog::TYPE_SOCKET_POOL)); 827 entries, 0, NetLog::TYPE_SOCKET_POOL));
828 EXPECT_TRUE(LogContainsEvent( 828 EXPECT_TRUE(LogContainsEvent(
829 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, 829 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB,
830 NetLog::PHASE_NONE)); 830 NetLog::PHASE_NONE));
831 EXPECT_TRUE(LogContainsEvent( 831 EXPECT_TRUE(LogContainsEvent(
832 entries, 2, NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, 832 entries, 2, NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET,
833 NetLog::PHASE_NONE)); 833 NetLog::PHASE_NONE));
834 EXPECT_TRUE(LogContainsEndEvent( 834 EXPECT_TRUE(LogContainsEndEvent(
835 entries, 3, NetLog::TYPE_SOCKET_POOL)); 835 entries, 3, NetLog::TYPE_SOCKET_POOL));
836 } 836 }
837 837
838 TEST_F(ClientSocketPoolBaseTest, InitConnectionFailure) { 838 TEST_F(ClientSocketPoolBaseTest, InitConnectionFailure) {
839 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 839 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
840 840
841 connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); 841 connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob);
842 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 842 CapturingBoundNetLog log;
843 843
844 ClientSocketHandle handle; 844 ClientSocketHandle handle;
845 TestCompletionCallback callback; 845 TestCompletionCallback callback;
846 // Set the additional error state members to ensure that they get cleared. 846 // Set the additional error state members to ensure that they get cleared.
847 handle.set_is_ssl_error(true); 847 handle.set_is_ssl_error(true);
848 HttpResponseInfo info; 848 HttpResponseInfo info;
849 info.headers = new HttpResponseHeaders(""); 849 info.headers = new HttpResponseHeaders("");
850 handle.set_ssl_error_response_info(info); 850 handle.set_ssl_error_response_info(info);
851 EXPECT_EQ(ERR_CONNECTION_FAILED, 851 EXPECT_EQ(ERR_CONNECTION_FAILED,
852 handle.Init("a", 852 handle.Init("a",
853 params_, 853 params_,
854 kDefaultPriority, 854 kDefaultPriority,
855 callback.callback(), 855 callback.callback(),
856 pool_.get(), 856 pool_.get(),
857 log.bound())); 857 log.bound()));
858 EXPECT_FALSE(handle.socket()); 858 EXPECT_FALSE(handle.socket());
859 EXPECT_FALSE(handle.is_ssl_error()); 859 EXPECT_FALSE(handle.is_ssl_error());
860 EXPECT_TRUE(handle.ssl_error_response_info().headers.get() == NULL); 860 EXPECT_TRUE(handle.ssl_error_response_info().headers.get() == NULL);
861 861
862 net::CapturingNetLog::CapturedEntryList entries; 862 CapturingNetLog::CapturedEntryList entries;
863 log.GetEntries(&entries); 863 log.GetEntries(&entries);
864 864
865 EXPECT_EQ(3u, entries.size()); 865 EXPECT_EQ(3u, entries.size());
866 EXPECT_TRUE(LogContainsBeginEvent( 866 EXPECT_TRUE(LogContainsBeginEvent(
867 entries, 0, NetLog::TYPE_SOCKET_POOL)); 867 entries, 0, NetLog::TYPE_SOCKET_POOL));
868 EXPECT_TRUE(LogContainsEvent( 868 EXPECT_TRUE(LogContainsEvent(
869 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, 869 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB,
870 NetLog::PHASE_NONE)); 870 NetLog::PHASE_NONE));
871 EXPECT_TRUE(LogContainsEndEvent( 871 EXPECT_TRUE(LogContainsEndEvent(
872 entries, 2, NetLog::TYPE_SOCKET_POOL)); 872 entries, 2, NetLog::TYPE_SOCKET_POOL));
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
1662 1662
1663 MessageLoop::current()->RunAllPending(); // Run the released socket wakeups 1663 MessageLoop::current()->RunAllPending(); // Run the released socket wakeups
1664 } 1664 }
1665 1665
1666 TEST_F(ClientSocketPoolBaseTest, BasicAsynchronous) { 1666 TEST_F(ClientSocketPoolBaseTest, BasicAsynchronous) {
1667 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 1667 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
1668 1668
1669 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); 1669 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
1670 ClientSocketHandle handle; 1670 ClientSocketHandle handle;
1671 TestCompletionCallback callback; 1671 TestCompletionCallback callback;
1672 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 1672 CapturingBoundNetLog log;
1673 int rv = handle.Init("a", 1673 int rv = handle.Init("a",
1674 params_, 1674 params_,
1675 LOWEST, 1675 LOWEST,
1676 callback.callback(), 1676 callback.callback(),
1677 pool_.get(), 1677 pool_.get(),
1678 log.bound()); 1678 log.bound());
1679 EXPECT_EQ(ERR_IO_PENDING, rv); 1679 EXPECT_EQ(ERR_IO_PENDING, rv);
1680 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle)); 1680 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle));
1681 EXPECT_EQ(OK, callback.WaitForResult()); 1681 EXPECT_EQ(OK, callback.WaitForResult());
1682 EXPECT_TRUE(handle.is_initialized()); 1682 EXPECT_TRUE(handle.is_initialized());
1683 EXPECT_TRUE(handle.socket()); 1683 EXPECT_TRUE(handle.socket());
1684 handle.Reset(); 1684 handle.Reset();
1685 1685
1686 net::CapturingNetLog::CapturedEntryList entries; 1686 CapturingNetLog::CapturedEntryList entries;
1687 log.GetEntries(&entries); 1687 log.GetEntries(&entries);
1688 1688
1689 EXPECT_EQ(4u, entries.size()); 1689 EXPECT_EQ(4u, entries.size());
1690 EXPECT_TRUE(LogContainsBeginEvent( 1690 EXPECT_TRUE(LogContainsBeginEvent(
1691 entries, 0, NetLog::TYPE_SOCKET_POOL)); 1691 entries, 0, NetLog::TYPE_SOCKET_POOL));
1692 EXPECT_TRUE(LogContainsEvent( 1692 EXPECT_TRUE(LogContainsEvent(
1693 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, 1693 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB,
1694 NetLog::PHASE_NONE)); 1694 NetLog::PHASE_NONE));
1695 EXPECT_TRUE(LogContainsEvent( 1695 EXPECT_TRUE(LogContainsEvent(
1696 entries, 2, NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, 1696 entries, 2, NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET,
1697 NetLog::PHASE_NONE)); 1697 NetLog::PHASE_NONE));
1698 EXPECT_TRUE(LogContainsEndEvent( 1698 EXPECT_TRUE(LogContainsEndEvent(
1699 entries, 3, NetLog::TYPE_SOCKET_POOL)); 1699 entries, 3, NetLog::TYPE_SOCKET_POOL));
1700 } 1700 }
1701 1701
1702 TEST_F(ClientSocketPoolBaseTest, 1702 TEST_F(ClientSocketPoolBaseTest,
1703 InitConnectionAsynchronousFailure) { 1703 InitConnectionAsynchronousFailure) {
1704 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 1704 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
1705 1705
1706 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); 1706 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob);
1707 ClientSocketHandle handle; 1707 ClientSocketHandle handle;
1708 TestCompletionCallback callback; 1708 TestCompletionCallback callback;
1709 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 1709 CapturingBoundNetLog log;
1710 // Set the additional error state members to ensure that they get cleared. 1710 // Set the additional error state members to ensure that they get cleared.
1711 handle.set_is_ssl_error(true); 1711 handle.set_is_ssl_error(true);
1712 HttpResponseInfo info; 1712 HttpResponseInfo info;
1713 info.headers = new HttpResponseHeaders(""); 1713 info.headers = new HttpResponseHeaders("");
1714 handle.set_ssl_error_response_info(info); 1714 handle.set_ssl_error_response_info(info);
1715 EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", 1715 EXPECT_EQ(ERR_IO_PENDING, handle.Init("a",
1716 params_, 1716 params_,
1717 kDefaultPriority, 1717 kDefaultPriority,
1718 callback.callback(), 1718 callback.callback(),
1719 pool_.get(), 1719 pool_.get(),
1720 log.bound())); 1720 log.bound()));
1721 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle)); 1721 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle));
1722 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult()); 1722 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult());
1723 EXPECT_FALSE(handle.is_ssl_error()); 1723 EXPECT_FALSE(handle.is_ssl_error());
1724 EXPECT_TRUE(handle.ssl_error_response_info().headers.get() == NULL); 1724 EXPECT_TRUE(handle.ssl_error_response_info().headers.get() == NULL);
1725 1725
1726 net::CapturingNetLog::CapturedEntryList entries; 1726 CapturingNetLog::CapturedEntryList entries;
1727 log.GetEntries(&entries); 1727 log.GetEntries(&entries);
1728 1728
1729 EXPECT_EQ(3u, entries.size()); 1729 EXPECT_EQ(3u, entries.size());
1730 EXPECT_TRUE(LogContainsBeginEvent( 1730 EXPECT_TRUE(LogContainsBeginEvent(
1731 entries, 0, NetLog::TYPE_SOCKET_POOL)); 1731 entries, 0, NetLog::TYPE_SOCKET_POOL));
1732 EXPECT_TRUE(LogContainsEvent( 1732 EXPECT_TRUE(LogContainsEvent(
1733 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, 1733 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB,
1734 NetLog::PHASE_NONE)); 1734 NetLog::PHASE_NONE));
1735 EXPECT_TRUE(LogContainsEndEvent( 1735 EXPECT_TRUE(LogContainsEndEvent(
1736 entries, 2, NetLog::TYPE_SOCKET_POOL)); 1736 entries, 2, NetLog::TYPE_SOCKET_POOL));
(...skipping 10 matching lines...) Expand all
1747 ClientSocketHandle handle2; 1747 ClientSocketHandle handle2;
1748 TestCompletionCallback callback2; 1748 TestCompletionCallback callback2;
1749 1749
1750 EXPECT_EQ(ERR_IO_PENDING, 1750 EXPECT_EQ(ERR_IO_PENDING,
1751 handle.Init("a", 1751 handle.Init("a",
1752 params_, 1752 params_,
1753 kDefaultPriority, 1753 kDefaultPriority,
1754 callback.callback(), 1754 callback.callback(),
1755 pool_.get(), 1755 pool_.get(),
1756 BoundNetLog())); 1756 BoundNetLog()));
1757 CapturingBoundNetLog log2(CapturingNetLog::kUnbounded); 1757 CapturingBoundNetLog log2;
1758 EXPECT_EQ(ERR_IO_PENDING, 1758 EXPECT_EQ(ERR_IO_PENDING,
1759 handle2.Init("a", 1759 handle2.Init("a",
1760 params_, 1760 params_,
1761 kDefaultPriority, 1761 kDefaultPriority,
1762 callback2.callback(), 1762 callback2.callback(),
1763 pool_.get(), 1763 pool_.get(),
1764 BoundNetLog())); 1764 BoundNetLog()));
1765 1765
1766 handle.Reset(); 1766 handle.Reset();
1767 1767
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
2034 2034
2035 // Use and release the socket. 2035 // Use and release the socket.
2036 EXPECT_EQ(1, handle.socket()->Write(NULL, 1, CompletionCallback())); 2036 EXPECT_EQ(1, handle.socket()->Write(NULL, 1, CompletionCallback()));
2037 handle.Reset(); 2037 handle.Reset();
2038 2038
2039 // Should now have one idle socket. 2039 // Should now have one idle socket.
2040 ASSERT_EQ(1, pool_->IdleSocketCount()); 2040 ASSERT_EQ(1, pool_->IdleSocketCount());
2041 2041
2042 // Request a new socket. This should reuse the old socket and complete 2042 // Request a new socket. This should reuse the old socket and complete
2043 // synchronously. 2043 // synchronously.
2044 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 2044 CapturingBoundNetLog log;
2045 rv = handle.Init("a", 2045 rv = handle.Init("a",
2046 params_, 2046 params_,
2047 LOWEST, 2047 LOWEST,
2048 CompletionCallback(), 2048 CompletionCallback(),
2049 pool_.get(), 2049 pool_.get(),
2050 log.bound()); 2050 log.bound());
2051 ASSERT_EQ(OK, rv); 2051 ASSERT_EQ(OK, rv);
2052 EXPECT_TRUE(handle.is_reused()); 2052 EXPECT_TRUE(handle.is_reused());
2053 2053
2054 ASSERT_TRUE(pool_->HasGroup("a")); 2054 ASSERT_TRUE(pool_->HasGroup("a"));
2055 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); 2055 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a"));
2056 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); 2056 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a"));
2057 2057
2058 net::CapturingNetLog::CapturedEntryList entries; 2058 CapturingNetLog::CapturedEntryList entries;
2059 log.GetEntries(&entries); 2059 log.GetEntries(&entries);
2060 EXPECT_TRUE(LogContainsEntryWithType( 2060 EXPECT_TRUE(LogContainsEntryWithType(
2061 entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET)); 2061 entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET));
2062 } 2062 }
2063 2063
2064 // Make sure we cleanup old unused sockets when the cleanup timer is disabled. 2064 // Make sure we cleanup old unused sockets when the cleanup timer is disabled.
2065 TEST_F(ClientSocketPoolBaseTest, DisableCleanupTimerNoReuse) { 2065 TEST_F(ClientSocketPoolBaseTest, DisableCleanupTimerNoReuse) {
2066 // Disable cleanup timer. 2066 // Disable cleanup timer.
2067 internal::ClientSocketPoolBaseHelper::set_cleanup_timer_enabled(false); 2067 internal::ClientSocketPoolBaseHelper::set_cleanup_timer_enabled(false);
2068 2068
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2113 // to flush all tasks, we need to wait so that we know there are no 2113 // to flush all tasks, we need to wait so that we know there are no
2114 // soon-to-be-pending tasks waiting. 2114 // soon-to-be-pending tasks waiting.
2115 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); 2115 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
2116 MessageLoop::current()->RunAllPending(); 2116 MessageLoop::current()->RunAllPending();
2117 2117
2118 // Both sockets should now be idle. 2118 // Both sockets should now be idle.
2119 ASSERT_EQ(2, pool_->IdleSocketCount()); 2119 ASSERT_EQ(2, pool_->IdleSocketCount());
2120 2120
2121 // Request a new socket. This should cleanup the unused and timed out ones. 2121 // Request a new socket. This should cleanup the unused and timed out ones.
2122 // A new socket will be created rather than reusing the idle one. 2122 // A new socket will be created rather than reusing the idle one.
2123 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 2123 CapturingBoundNetLog log;
2124 TestCompletionCallback callback3; 2124 TestCompletionCallback callback3;
2125 rv = handle.Init("a", 2125 rv = handle.Init("a",
2126 params_, 2126 params_,
2127 LOWEST, 2127 LOWEST,
2128 callback3.callback(), 2128 callback3.callback(),
2129 pool_.get(), 2129 pool_.get(),
2130 log.bound()); 2130 log.bound());
2131 ASSERT_EQ(ERR_IO_PENDING, rv); 2131 ASSERT_EQ(ERR_IO_PENDING, rv);
2132 ASSERT_EQ(OK, callback3.WaitForResult()); 2132 ASSERT_EQ(OK, callback3.WaitForResult());
2133 EXPECT_FALSE(handle.is_reused()); 2133 EXPECT_FALSE(handle.is_reused());
2134 2134
2135 // Make sure the idle socket is closed. 2135 // Make sure the idle socket is closed.
2136 ASSERT_TRUE(pool_->HasGroup("a")); 2136 ASSERT_TRUE(pool_->HasGroup("a"));
2137 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); 2137 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a"));
2138 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); 2138 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a"));
2139 2139
2140 net::CapturingNetLog::CapturedEntryList entries; 2140 CapturingNetLog::CapturedEntryList entries;
2141 log.GetEntries(&entries); 2141 log.GetEntries(&entries);
2142 EXPECT_FALSE(LogContainsEntryWithType( 2142 EXPECT_FALSE(LogContainsEntryWithType(
2143 entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET)); 2143 entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET));
2144 } 2144 }
2145 2145
2146 TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSockets) { 2146 TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSockets) {
2147 CreatePoolWithIdleTimeouts( 2147 CreatePoolWithIdleTimeouts(
2148 kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, 2148 kDefaultMaxSockets, kDefaultMaxSocketsPerGroup,
2149 base::TimeDelta(), // Time out unused sockets immediately. 2149 base::TimeDelta(), // Time out unused sockets immediately.
2150 base::TimeDelta::FromDays(1)); // Don't time out used sockets. 2150 base::TimeDelta::FromDays(1)); // Don't time out used sockets.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2192 // soon-to-be-pending tasks waiting. 2192 // soon-to-be-pending tasks waiting.
2193 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); 2193 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
2194 MessageLoop::current()->RunAllPending(); 2194 MessageLoop::current()->RunAllPending();
2195 2195
2196 ASSERT_EQ(2, pool_->IdleSocketCount()); 2196 ASSERT_EQ(2, pool_->IdleSocketCount());
2197 2197
2198 // Invoke the idle socket cleanup check. Only one socket should be left, the 2198 // Invoke the idle socket cleanup check. Only one socket should be left, the
2199 // used socket. Request it to make sure that it's used. 2199 // used socket. Request it to make sure that it's used.
2200 2200
2201 pool_->CleanupTimedOutIdleSockets(); 2201 pool_->CleanupTimedOutIdleSockets();
2202 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 2202 CapturingBoundNetLog log;
2203 rv = handle.Init("a", 2203 rv = handle.Init("a",
2204 params_, 2204 params_,
2205 LOWEST, 2205 LOWEST,
2206 callback.callback(), 2206 callback.callback(),
2207 pool_.get(), 2207 pool_.get(),
2208 log.bound()); 2208 log.bound());
2209 EXPECT_EQ(OK, rv); 2209 EXPECT_EQ(OK, rv);
2210 EXPECT_TRUE(handle.is_reused()); 2210 EXPECT_TRUE(handle.is_reused());
2211 2211
2212 net::CapturingNetLog::CapturedEntryList entries; 2212 CapturingNetLog::CapturedEntryList entries;
2213 log.GetEntries(&entries); 2213 log.GetEntries(&entries);
2214 EXPECT_TRUE(LogContainsEntryWithType( 2214 EXPECT_TRUE(LogContainsEntryWithType(
2215 entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET)); 2215 entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET));
2216 } 2216 }
2217 2217
2218 // Make sure that we process all pending requests even when we're stalling 2218 // Make sure that we process all pending requests even when we're stalling
2219 // because of multiple releasing disconnected sockets. 2219 // because of multiple releasing disconnected sockets.
2220 TEST_F(ClientSocketPoolBaseTest, MultipleReleasingDisconnectedSockets) { 2220 TEST_F(ClientSocketPoolBaseTest, MultipleReleasingDisconnectedSockets) {
2221 CreatePoolWithIdleTimeouts( 2221 CreatePoolWithIdleTimeouts(
2222 kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, 2222 kDefaultMaxSockets, kDefaultMaxSocketsPerGroup,
(...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after
3479 // The hung connect job should still be there, but everything else should be 3479 // The hung connect job should still be there, but everything else should be
3480 // complete. 3480 // complete.
3481 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); 3481 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
3482 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); 3482 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a"));
3483 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); 3483 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a"));
3484 } 3484 }
3485 3485
3486 } // namespace 3486 } // namespace
3487 3487
3488 } // namespace net 3488 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698