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

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: sync 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
« no previous file with comments | « net/proxy/proxy_service_unittest.cc ('k') | net/socket/socks5_client_socket_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 base::TimeDelta::FromMicroseconds(1), 759 base::TimeDelta::FromMicroseconds(1),
760 &delegate, 760 &delegate,
761 &client_socket_factory_, 761 &client_socket_factory_,
762 NULL)); 762 NULL));
763 EXPECT_EQ(OK, job->Connect()); 763 EXPECT_EQ(OK, job->Connect());
764 } 764 }
765 765
766 TEST_F(ClientSocketPoolBaseTest, ConnectJob_TimedOut) { 766 TEST_F(ClientSocketPoolBaseTest, ConnectJob_TimedOut) {
767 TestConnectJobDelegate delegate; 767 TestConnectJobDelegate delegate;
768 ClientSocketHandle ignored; 768 ClientSocketHandle ignored;
769 CapturingNetLog log(CapturingNetLog::kUnbounded); 769 CapturingNetLog log;
770 770
771 TestClientSocketPoolBase::Request request( 771 TestClientSocketPoolBase::Request request(
772 &ignored, CompletionCallback(), kDefaultPriority, 772 &ignored, CompletionCallback(), kDefaultPriority,
773 internal::ClientSocketPoolBaseHelper::NORMAL, 773 internal::ClientSocketPoolBaseHelper::NORMAL,
774 false, params_, BoundNetLog()); 774 false, params_, BoundNetLog());
775 // Deleted by TestConnectJobDelegate. 775 // Deleted by TestConnectJobDelegate.
776 TestConnectJob* job = 776 TestConnectJob* job =
777 new TestConnectJob(TestConnectJob::kMockPendingJob, 777 new TestConnectJob(TestConnectJob::kMockPendingJob,
778 "a", 778 "a",
779 request, 779 request,
780 base::TimeDelta::FromMicroseconds(1), 780 base::TimeDelta::FromMicroseconds(1),
781 &delegate, 781 &delegate,
782 &client_socket_factory_, 782 &client_socket_factory_,
783 &log); 783 &log);
784 ASSERT_EQ(ERR_IO_PENDING, job->Connect()); 784 ASSERT_EQ(ERR_IO_PENDING, job->Connect());
785 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); 785 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1));
786 EXPECT_EQ(ERR_TIMED_OUT, delegate.WaitForResult()); 786 EXPECT_EQ(ERR_TIMED_OUT, delegate.WaitForResult());
787 787
788 net::CapturingNetLog::CapturedEntryList entries; 788 CapturingNetLog::CapturedEntryList entries;
789 log.GetEntries(&entries); 789 log.GetEntries(&entries);
790 790
791 EXPECT_EQ(6u, entries.size()); 791 EXPECT_EQ(6u, entries.size());
792 EXPECT_TRUE(LogContainsBeginEvent( 792 EXPECT_TRUE(LogContainsBeginEvent(
793 entries, 0, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); 793 entries, 0, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB));
794 EXPECT_TRUE(LogContainsBeginEvent( 794 EXPECT_TRUE(LogContainsBeginEvent(
795 entries, 1, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT)); 795 entries, 1, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT));
796 EXPECT_TRUE(LogContainsEvent( 796 EXPECT_TRUE(LogContainsEvent(
797 entries, 2, NetLog::TYPE_CONNECT_JOB_SET_SOCKET, 797 entries, 2, NetLog::TYPE_CONNECT_JOB_SET_SOCKET,
798 NetLog::PHASE_NONE)); 798 NetLog::PHASE_NONE));
799 EXPECT_TRUE(LogContainsEvent( 799 EXPECT_TRUE(LogContainsEvent(
800 entries, 3, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_TIMED_OUT, 800 entries, 3, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_TIMED_OUT,
801 NetLog::PHASE_NONE)); 801 NetLog::PHASE_NONE));
802 EXPECT_TRUE(LogContainsEndEvent( 802 EXPECT_TRUE(LogContainsEndEvent(
803 entries, 4, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT)); 803 entries, 4, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT));
804 EXPECT_TRUE(LogContainsEndEvent( 804 EXPECT_TRUE(LogContainsEndEvent(
805 entries, 5, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); 805 entries, 5, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB));
806 } 806 }
807 807
808 TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) { 808 TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) {
809 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 809 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
810 810
811 TestCompletionCallback callback; 811 TestCompletionCallback callback;
812 ClientSocketHandle handle; 812 ClientSocketHandle handle;
813 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 813 CapturingBoundNetLog log;
814 814
815 EXPECT_EQ(OK, 815 EXPECT_EQ(OK,
816 handle.Init("a", 816 handle.Init("a",
817 params_, 817 params_,
818 kDefaultPriority, 818 kDefaultPriority,
819 callback.callback(), 819 callback.callback(),
820 pool_.get(), 820 pool_.get(),
821 log.bound())); 821 log.bound()));
822 EXPECT_TRUE(handle.is_initialized()); 822 EXPECT_TRUE(handle.is_initialized());
823 EXPECT_TRUE(handle.socket()); 823 EXPECT_TRUE(handle.socket());
824 handle.Reset(); 824 handle.Reset();
825 825
826 net::CapturingNetLog::CapturedEntryList entries; 826 CapturingNetLog::CapturedEntryList entries;
827 log.GetEntries(&entries); 827 log.GetEntries(&entries);
828 828
829 EXPECT_EQ(4u, entries.size()); 829 EXPECT_EQ(4u, entries.size());
830 EXPECT_TRUE(LogContainsBeginEvent( 830 EXPECT_TRUE(LogContainsBeginEvent(
831 entries, 0, NetLog::TYPE_SOCKET_POOL)); 831 entries, 0, NetLog::TYPE_SOCKET_POOL));
832 EXPECT_TRUE(LogContainsEvent( 832 EXPECT_TRUE(LogContainsEvent(
833 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, 833 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB,
834 NetLog::PHASE_NONE)); 834 NetLog::PHASE_NONE));
835 EXPECT_TRUE(LogContainsEvent( 835 EXPECT_TRUE(LogContainsEvent(
836 entries, 2, NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, 836 entries, 2, NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET,
837 NetLog::PHASE_NONE)); 837 NetLog::PHASE_NONE));
838 EXPECT_TRUE(LogContainsEndEvent( 838 EXPECT_TRUE(LogContainsEndEvent(
839 entries, 3, NetLog::TYPE_SOCKET_POOL)); 839 entries, 3, NetLog::TYPE_SOCKET_POOL));
840 } 840 }
841 841
842 TEST_F(ClientSocketPoolBaseTest, InitConnectionFailure) { 842 TEST_F(ClientSocketPoolBaseTest, InitConnectionFailure) {
843 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 843 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
844 844
845 connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); 845 connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob);
846 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 846 CapturingBoundNetLog log;
847 847
848 ClientSocketHandle handle; 848 ClientSocketHandle handle;
849 TestCompletionCallback callback; 849 TestCompletionCallback callback;
850 // Set the additional error state members to ensure that they get cleared. 850 // Set the additional error state members to ensure that they get cleared.
851 handle.set_is_ssl_error(true); 851 handle.set_is_ssl_error(true);
852 HttpResponseInfo info; 852 HttpResponseInfo info;
853 info.headers = new HttpResponseHeaders(""); 853 info.headers = new HttpResponseHeaders("");
854 handle.set_ssl_error_response_info(info); 854 handle.set_ssl_error_response_info(info);
855 EXPECT_EQ(ERR_CONNECTION_FAILED, 855 EXPECT_EQ(ERR_CONNECTION_FAILED,
856 handle.Init("a", 856 handle.Init("a",
857 params_, 857 params_,
858 kDefaultPriority, 858 kDefaultPriority,
859 callback.callback(), 859 callback.callback(),
860 pool_.get(), 860 pool_.get(),
861 log.bound())); 861 log.bound()));
862 EXPECT_FALSE(handle.socket()); 862 EXPECT_FALSE(handle.socket());
863 EXPECT_FALSE(handle.is_ssl_error()); 863 EXPECT_FALSE(handle.is_ssl_error());
864 EXPECT_TRUE(handle.ssl_error_response_info().headers.get() == NULL); 864 EXPECT_TRUE(handle.ssl_error_response_info().headers.get() == NULL);
865 865
866 net::CapturingNetLog::CapturedEntryList entries; 866 CapturingNetLog::CapturedEntryList entries;
867 log.GetEntries(&entries); 867 log.GetEntries(&entries);
868 868
869 EXPECT_EQ(3u, entries.size()); 869 EXPECT_EQ(3u, entries.size());
870 EXPECT_TRUE(LogContainsBeginEvent( 870 EXPECT_TRUE(LogContainsBeginEvent(
871 entries, 0, NetLog::TYPE_SOCKET_POOL)); 871 entries, 0, NetLog::TYPE_SOCKET_POOL));
872 EXPECT_TRUE(LogContainsEvent( 872 EXPECT_TRUE(LogContainsEvent(
873 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, 873 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB,
874 NetLog::PHASE_NONE)); 874 NetLog::PHASE_NONE));
875 EXPECT_TRUE(LogContainsEndEvent( 875 EXPECT_TRUE(LogContainsEndEvent(
876 entries, 2, NetLog::TYPE_SOCKET_POOL)); 876 entries, 2, NetLog::TYPE_SOCKET_POOL));
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after
1669 1669
1670 MessageLoop::current()->RunAllPending(); // Run the released socket wakeups 1670 MessageLoop::current()->RunAllPending(); // Run the released socket wakeups
1671 } 1671 }
1672 1672
1673 TEST_F(ClientSocketPoolBaseTest, BasicAsynchronous) { 1673 TEST_F(ClientSocketPoolBaseTest, BasicAsynchronous) {
1674 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 1674 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
1675 1675
1676 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); 1676 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
1677 ClientSocketHandle handle; 1677 ClientSocketHandle handle;
1678 TestCompletionCallback callback; 1678 TestCompletionCallback callback;
1679 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 1679 CapturingBoundNetLog log;
1680 int rv = handle.Init("a", 1680 int rv = handle.Init("a",
1681 params_, 1681 params_,
1682 LOWEST, 1682 LOWEST,
1683 callback.callback(), 1683 callback.callback(),
1684 pool_.get(), 1684 pool_.get(),
1685 log.bound()); 1685 log.bound());
1686 EXPECT_EQ(ERR_IO_PENDING, rv); 1686 EXPECT_EQ(ERR_IO_PENDING, rv);
1687 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle)); 1687 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle));
1688 EXPECT_EQ(OK, callback.WaitForResult()); 1688 EXPECT_EQ(OK, callback.WaitForResult());
1689 EXPECT_TRUE(handle.is_initialized()); 1689 EXPECT_TRUE(handle.is_initialized());
1690 EXPECT_TRUE(handle.socket()); 1690 EXPECT_TRUE(handle.socket());
1691 handle.Reset(); 1691 handle.Reset();
1692 1692
1693 net::CapturingNetLog::CapturedEntryList entries; 1693 CapturingNetLog::CapturedEntryList entries;
1694 log.GetEntries(&entries); 1694 log.GetEntries(&entries);
1695 1695
1696 EXPECT_EQ(4u, entries.size()); 1696 EXPECT_EQ(4u, entries.size());
1697 EXPECT_TRUE(LogContainsBeginEvent( 1697 EXPECT_TRUE(LogContainsBeginEvent(
1698 entries, 0, NetLog::TYPE_SOCKET_POOL)); 1698 entries, 0, NetLog::TYPE_SOCKET_POOL));
1699 EXPECT_TRUE(LogContainsEvent( 1699 EXPECT_TRUE(LogContainsEvent(
1700 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, 1700 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB,
1701 NetLog::PHASE_NONE)); 1701 NetLog::PHASE_NONE));
1702 EXPECT_TRUE(LogContainsEvent( 1702 EXPECT_TRUE(LogContainsEvent(
1703 entries, 2, NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, 1703 entries, 2, NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET,
1704 NetLog::PHASE_NONE)); 1704 NetLog::PHASE_NONE));
1705 EXPECT_TRUE(LogContainsEndEvent( 1705 EXPECT_TRUE(LogContainsEndEvent(
1706 entries, 3, NetLog::TYPE_SOCKET_POOL)); 1706 entries, 3, NetLog::TYPE_SOCKET_POOL));
1707 } 1707 }
1708 1708
1709 TEST_F(ClientSocketPoolBaseTest, 1709 TEST_F(ClientSocketPoolBaseTest,
1710 InitConnectionAsynchronousFailure) { 1710 InitConnectionAsynchronousFailure) {
1711 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 1711 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
1712 1712
1713 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); 1713 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob);
1714 ClientSocketHandle handle; 1714 ClientSocketHandle handle;
1715 TestCompletionCallback callback; 1715 TestCompletionCallback callback;
1716 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 1716 CapturingBoundNetLog log;
1717 // Set the additional error state members to ensure that they get cleared. 1717 // Set the additional error state members to ensure that they get cleared.
1718 handle.set_is_ssl_error(true); 1718 handle.set_is_ssl_error(true);
1719 HttpResponseInfo info; 1719 HttpResponseInfo info;
1720 info.headers = new HttpResponseHeaders(""); 1720 info.headers = new HttpResponseHeaders("");
1721 handle.set_ssl_error_response_info(info); 1721 handle.set_ssl_error_response_info(info);
1722 EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", 1722 EXPECT_EQ(ERR_IO_PENDING, handle.Init("a",
1723 params_, 1723 params_,
1724 kDefaultPriority, 1724 kDefaultPriority,
1725 callback.callback(), 1725 callback.callback(),
1726 pool_.get(), 1726 pool_.get(),
1727 log.bound())); 1727 log.bound()));
1728 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle)); 1728 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle));
1729 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult()); 1729 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult());
1730 EXPECT_FALSE(handle.is_ssl_error()); 1730 EXPECT_FALSE(handle.is_ssl_error());
1731 EXPECT_TRUE(handle.ssl_error_response_info().headers.get() == NULL); 1731 EXPECT_TRUE(handle.ssl_error_response_info().headers.get() == NULL);
1732 1732
1733 net::CapturingNetLog::CapturedEntryList entries; 1733 CapturingNetLog::CapturedEntryList entries;
1734 log.GetEntries(&entries); 1734 log.GetEntries(&entries);
1735 1735
1736 EXPECT_EQ(3u, entries.size()); 1736 EXPECT_EQ(3u, entries.size());
1737 EXPECT_TRUE(LogContainsBeginEvent( 1737 EXPECT_TRUE(LogContainsBeginEvent(
1738 entries, 0, NetLog::TYPE_SOCKET_POOL)); 1738 entries, 0, NetLog::TYPE_SOCKET_POOL));
1739 EXPECT_TRUE(LogContainsEvent( 1739 EXPECT_TRUE(LogContainsEvent(
1740 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, 1740 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB,
1741 NetLog::PHASE_NONE)); 1741 NetLog::PHASE_NONE));
1742 EXPECT_TRUE(LogContainsEndEvent( 1742 EXPECT_TRUE(LogContainsEndEvent(
1743 entries, 2, NetLog::TYPE_SOCKET_POOL)); 1743 entries, 2, NetLog::TYPE_SOCKET_POOL));
(...skipping 10 matching lines...) Expand all
1754 ClientSocketHandle handle2; 1754 ClientSocketHandle handle2;
1755 TestCompletionCallback callback2; 1755 TestCompletionCallback callback2;
1756 1756
1757 EXPECT_EQ(ERR_IO_PENDING, 1757 EXPECT_EQ(ERR_IO_PENDING,
1758 handle.Init("a", 1758 handle.Init("a",
1759 params_, 1759 params_,
1760 kDefaultPriority, 1760 kDefaultPriority,
1761 callback.callback(), 1761 callback.callback(),
1762 pool_.get(), 1762 pool_.get(),
1763 BoundNetLog())); 1763 BoundNetLog()));
1764 CapturingBoundNetLog log2(CapturingNetLog::kUnbounded); 1764 CapturingBoundNetLog log2;
1765 EXPECT_EQ(ERR_IO_PENDING, 1765 EXPECT_EQ(ERR_IO_PENDING,
1766 handle2.Init("a", 1766 handle2.Init("a",
1767 params_, 1767 params_,
1768 kDefaultPriority, 1768 kDefaultPriority,
1769 callback2.callback(), 1769 callback2.callback(),
1770 pool_.get(), 1770 pool_.get(),
1771 BoundNetLog())); 1771 BoundNetLog()));
1772 1772
1773 handle.Reset(); 1773 handle.Reset();
1774 1774
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
2041 2041
2042 // Use and release the socket. 2042 // Use and release the socket.
2043 EXPECT_EQ(1, handle.socket()->Write(NULL, 1, CompletionCallback())); 2043 EXPECT_EQ(1, handle.socket()->Write(NULL, 1, CompletionCallback()));
2044 handle.Reset(); 2044 handle.Reset();
2045 2045
2046 // Should now have one idle socket. 2046 // Should now have one idle socket.
2047 ASSERT_EQ(1, pool_->IdleSocketCount()); 2047 ASSERT_EQ(1, pool_->IdleSocketCount());
2048 2048
2049 // Request a new socket. This should reuse the old socket and complete 2049 // Request a new socket. This should reuse the old socket and complete
2050 // synchronously. 2050 // synchronously.
2051 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 2051 CapturingBoundNetLog log;
2052 rv = handle.Init("a", 2052 rv = handle.Init("a",
2053 params_, 2053 params_,
2054 LOWEST, 2054 LOWEST,
2055 CompletionCallback(), 2055 CompletionCallback(),
2056 pool_.get(), 2056 pool_.get(),
2057 log.bound()); 2057 log.bound());
2058 ASSERT_EQ(OK, rv); 2058 ASSERT_EQ(OK, rv);
2059 EXPECT_TRUE(handle.is_reused()); 2059 EXPECT_TRUE(handle.is_reused());
2060 2060
2061 ASSERT_TRUE(pool_->HasGroup("a")); 2061 ASSERT_TRUE(pool_->HasGroup("a"));
2062 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); 2062 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a"));
2063 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); 2063 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a"));
2064 2064
2065 net::CapturingNetLog::CapturedEntryList entries; 2065 CapturingNetLog::CapturedEntryList entries;
2066 log.GetEntries(&entries); 2066 log.GetEntries(&entries);
2067 EXPECT_TRUE(LogContainsEntryWithType( 2067 EXPECT_TRUE(LogContainsEntryWithType(
2068 entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET)); 2068 entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET));
2069 } 2069 }
2070 2070
2071 // Make sure we cleanup old unused sockets when the cleanup timer is disabled. 2071 // Make sure we cleanup old unused sockets when the cleanup timer is disabled.
2072 TEST_F(ClientSocketPoolBaseTest, DisableCleanupTimerNoReuse) { 2072 TEST_F(ClientSocketPoolBaseTest, DisableCleanupTimerNoReuse) {
2073 // Disable cleanup timer. 2073 // Disable cleanup timer.
2074 internal::ClientSocketPoolBaseHelper::set_cleanup_timer_enabled(false); 2074 internal::ClientSocketPoolBaseHelper::set_cleanup_timer_enabled(false);
2075 2075
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2120 // to flush all tasks, we need to wait so that we know there are no 2120 // to flush all tasks, we need to wait so that we know there are no
2121 // soon-to-be-pending tasks waiting. 2121 // soon-to-be-pending tasks waiting.
2122 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); 2122 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
2123 MessageLoop::current()->RunAllPending(); 2123 MessageLoop::current()->RunAllPending();
2124 2124
2125 // Both sockets should now be idle. 2125 // Both sockets should now be idle.
2126 ASSERT_EQ(2, pool_->IdleSocketCount()); 2126 ASSERT_EQ(2, pool_->IdleSocketCount());
2127 2127
2128 // Request a new socket. This should cleanup the unused and timed out ones. 2128 // Request a new socket. This should cleanup the unused and timed out ones.
2129 // A new socket will be created rather than reusing the idle one. 2129 // A new socket will be created rather than reusing the idle one.
2130 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 2130 CapturingBoundNetLog log;
2131 TestCompletionCallback callback3; 2131 TestCompletionCallback callback3;
2132 rv = handle.Init("a", 2132 rv = handle.Init("a",
2133 params_, 2133 params_,
2134 LOWEST, 2134 LOWEST,
2135 callback3.callback(), 2135 callback3.callback(),
2136 pool_.get(), 2136 pool_.get(),
2137 log.bound()); 2137 log.bound());
2138 ASSERT_EQ(ERR_IO_PENDING, rv); 2138 ASSERT_EQ(ERR_IO_PENDING, rv);
2139 ASSERT_EQ(OK, callback3.WaitForResult()); 2139 ASSERT_EQ(OK, callback3.WaitForResult());
2140 EXPECT_FALSE(handle.is_reused()); 2140 EXPECT_FALSE(handle.is_reused());
2141 2141
2142 // Make sure the idle socket is closed. 2142 // Make sure the idle socket is closed.
2143 ASSERT_TRUE(pool_->HasGroup("a")); 2143 ASSERT_TRUE(pool_->HasGroup("a"));
2144 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); 2144 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a"));
2145 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); 2145 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a"));
2146 2146
2147 net::CapturingNetLog::CapturedEntryList entries; 2147 CapturingNetLog::CapturedEntryList entries;
2148 log.GetEntries(&entries); 2148 log.GetEntries(&entries);
2149 EXPECT_FALSE(LogContainsEntryWithType( 2149 EXPECT_FALSE(LogContainsEntryWithType(
2150 entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET)); 2150 entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET));
2151 } 2151 }
2152 2152
2153 TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSockets) { 2153 TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSockets) {
2154 CreatePoolWithIdleTimeouts( 2154 CreatePoolWithIdleTimeouts(
2155 kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, 2155 kDefaultMaxSockets, kDefaultMaxSocketsPerGroup,
2156 base::TimeDelta(), // Time out unused sockets immediately. 2156 base::TimeDelta(), // Time out unused sockets immediately.
2157 base::TimeDelta::FromDays(1)); // Don't time out used sockets. 2157 base::TimeDelta::FromDays(1)); // Don't time out used sockets.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2199 // soon-to-be-pending tasks waiting. 2199 // soon-to-be-pending tasks waiting.
2200 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); 2200 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
2201 MessageLoop::current()->RunAllPending(); 2201 MessageLoop::current()->RunAllPending();
2202 2202
2203 ASSERT_EQ(2, pool_->IdleSocketCount()); 2203 ASSERT_EQ(2, pool_->IdleSocketCount());
2204 2204
2205 // Invoke the idle socket cleanup check. Only one socket should be left, the 2205 // Invoke the idle socket cleanup check. Only one socket should be left, the
2206 // used socket. Request it to make sure that it's used. 2206 // used socket. Request it to make sure that it's used.
2207 2207
2208 pool_->CleanupTimedOutIdleSockets(); 2208 pool_->CleanupTimedOutIdleSockets();
2209 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 2209 CapturingBoundNetLog log;
2210 rv = handle.Init("a", 2210 rv = handle.Init("a",
2211 params_, 2211 params_,
2212 LOWEST, 2212 LOWEST,
2213 callback.callback(), 2213 callback.callback(),
2214 pool_.get(), 2214 pool_.get(),
2215 log.bound()); 2215 log.bound());
2216 EXPECT_EQ(OK, rv); 2216 EXPECT_EQ(OK, rv);
2217 EXPECT_TRUE(handle.is_reused()); 2217 EXPECT_TRUE(handle.is_reused());
2218 2218
2219 net::CapturingNetLog::CapturedEntryList entries; 2219 CapturingNetLog::CapturedEntryList entries;
2220 log.GetEntries(&entries); 2220 log.GetEntries(&entries);
2221 EXPECT_TRUE(LogContainsEntryWithType( 2221 EXPECT_TRUE(LogContainsEntryWithType(
2222 entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET)); 2222 entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET));
2223 } 2223 }
2224 2224
2225 // Make sure that we process all pending requests even when we're stalling 2225 // Make sure that we process all pending requests even when we're stalling
2226 // because of multiple releasing disconnected sockets. 2226 // because of multiple releasing disconnected sockets.
2227 TEST_F(ClientSocketPoolBaseTest, MultipleReleasingDisconnectedSockets) { 2227 TEST_F(ClientSocketPoolBaseTest, MultipleReleasingDisconnectedSockets) {
2228 CreatePoolWithIdleTimeouts( 2228 CreatePoolWithIdleTimeouts(
2229 kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, 2229 kDefaultMaxSockets, kDefaultMaxSocketsPerGroup,
(...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after
3521 // complete. 3521 // complete.
3522 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); 3522 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
3523 EXPECT_EQ(0, pool_->NumUnassignedConnectJobsInGroup("a")); 3523 EXPECT_EQ(0, pool_->NumUnassignedConnectJobsInGroup("a"));
3524 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); 3524 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a"));
3525 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); 3525 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a"));
3526 } 3526 }
3527 3527
3528 } // namespace 3528 } // namespace
3529 3529
3530 } // namespace net 3530 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_service_unittest.cc ('k') | net/socket/socks5_client_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698