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

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

Issue 1084533002: Rename NetLogLogger and CapturingNetLog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename NetLogLogger and CapturingNetLog(removed compiler error for chromeOS) Created 5 years, 8 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/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
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
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));
787 EXPECT_TRUE(LogContainsEvent( 787 EXPECT_TRUE(LogContainsEvent(
788 entries, 3, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_TIMED_OUT, 788 entries, 3, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_TIMED_OUT,
789 NetLog::PHASE_NONE)); 789 NetLog::PHASE_NONE));
790 EXPECT_TRUE(LogContainsEndEvent( 790 EXPECT_TRUE(LogContainsEndEvent(
791 entries, 4, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT)); 791 entries, 4, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT));
792 EXPECT_TRUE(LogContainsEndEvent( 792 EXPECT_TRUE(LogContainsEndEvent(
793 entries, 5, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); 793 entries, 5, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB));
794 } 794 }
795 795
796 TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) { 796 TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) {
797 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 797 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
798 798
799 TestCompletionCallback callback; 799 TestCompletionCallback callback;
800 ClientSocketHandle handle; 800 ClientSocketHandle handle;
801 CapturingBoundNetLog log; 801 BoundTestNetLog log;
802 TestLoadTimingInfoNotConnected(handle); 802 TestLoadTimingInfoNotConnected(handle);
803 803
804 EXPECT_EQ(OK, 804 EXPECT_EQ(OK,
805 handle.Init("a", 805 handle.Init("a",
806 params_, 806 params_,
807 DEFAULT_PRIORITY, 807 DEFAULT_PRIORITY,
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,
829 NetLog::PHASE_NONE)); 829 NetLog::PHASE_NONE));
830 EXPECT_TRUE(LogContainsEndEvent( 830 EXPECT_TRUE(LogContainsEndEvent(
831 entries, 3, NetLog::TYPE_SOCKET_POOL)); 831 entries, 3, NetLog::TYPE_SOCKET_POOL));
832 } 832 }
833 833
834 TEST_F(ClientSocketPoolBaseTest, InitConnectionFailure) { 834 TEST_F(ClientSocketPoolBaseTest, InitConnectionFailure) {
835 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 835 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
836 836
837 connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); 837 connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob);
838 CapturingBoundNetLog log; 838 BoundTestNetLog log;
839 839
840 ClientSocketHandle handle; 840 ClientSocketHandle handle;
841 TestCompletionCallback callback; 841 TestCompletionCallback callback;
842 // Set the additional error state members to ensure that they get cleared. 842 // Set the additional error state members to ensure that they get cleared.
843 handle.set_is_ssl_error(true); 843 handle.set_is_ssl_error(true);
844 HttpResponseInfo info; 844 HttpResponseInfo info;
845 info.headers = new HttpResponseHeaders(std::string()); 845 info.headers = new HttpResponseHeaders(std::string());
846 handle.set_ssl_error_response_info(info); 846 handle.set_ssl_error_response_info(info);
847 EXPECT_EQ(ERR_CONNECTION_FAILED, 847 EXPECT_EQ(ERR_CONNECTION_FAILED,
848 handle.Init("a", 848 handle.Init("a",
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 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 // Run the released socket wakeups. 1665 // Run the released socket wakeups.
1666 base::MessageLoop::current()->RunUntilIdle(); 1666 base::MessageLoop::current()->RunUntilIdle();
1667 } 1667 }
1668 1668
1669 TEST_F(ClientSocketPoolBaseTest, BasicAsynchronous) { 1669 TEST_F(ClientSocketPoolBaseTest, BasicAsynchronous) {
1670 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 1670 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
1671 1671
1672 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); 1672 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
1673 ClientSocketHandle handle; 1673 ClientSocketHandle handle;
1674 TestCompletionCallback callback; 1674 TestCompletionCallback callback;
1675 CapturingBoundNetLog log; 1675 BoundTestNetLog log;
1676 int rv = handle.Init("a", 1676 int rv = handle.Init("a",
1677 params_, 1677 params_,
1678 LOWEST, 1678 LOWEST,
1679 callback.callback(), 1679 callback.callback(),
1680 pool_.get(), 1680 pool_.get(),
1681 log.bound()); 1681 log.bound());
1682 EXPECT_EQ(ERR_IO_PENDING, rv); 1682 EXPECT_EQ(ERR_IO_PENDING, rv);
1683 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle)); 1683 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle));
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,
1705 NetLog::PHASE_NONE)); 1705 NetLog::PHASE_NONE));
1706 EXPECT_TRUE(LogContainsEndEvent( 1706 EXPECT_TRUE(LogContainsEndEvent(
1707 entries, 3, NetLog::TYPE_SOCKET_POOL)); 1707 entries, 3, NetLog::TYPE_SOCKET_POOL));
1708 } 1708 }
1709 1709
1710 TEST_F(ClientSocketPoolBaseTest, 1710 TEST_F(ClientSocketPoolBaseTest,
1711 InitConnectionAsynchronousFailure) { 1711 InitConnectionAsynchronousFailure) {
1712 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 1712 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
1713 1713
1714 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); 1714 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob);
1715 ClientSocketHandle handle; 1715 ClientSocketHandle handle;
1716 TestCompletionCallback callback; 1716 TestCompletionCallback callback;
1717 CapturingBoundNetLog log; 1717 BoundTestNetLog log;
1718 // Set the additional error state members to ensure that they get cleared. 1718 // Set the additional error state members to ensure that they get cleared.
1719 handle.set_is_ssl_error(true); 1719 handle.set_is_ssl_error(true);
1720 HttpResponseInfo info; 1720 HttpResponseInfo info;
1721 info.headers = new HttpResponseHeaders(std::string()); 1721 info.headers = new HttpResponseHeaders(std::string());
1722 handle.set_ssl_error_response_info(info); 1722 handle.set_ssl_error_response_info(info);
1723 EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", 1723 EXPECT_EQ(ERR_IO_PENDING, handle.Init("a",
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 26 matching lines...) Expand all
1771 ClientSocketHandle handle2; 1771 ClientSocketHandle handle2;
1772 TestCompletionCallback callback2; 1772 TestCompletionCallback callback2;
1773 1773
1774 EXPECT_EQ(ERR_IO_PENDING, 1774 EXPECT_EQ(ERR_IO_PENDING,
1775 handle.Init("a", 1775 handle.Init("a",
1776 params_, 1776 params_,
1777 DEFAULT_PRIORITY, 1777 DEFAULT_PRIORITY,
1778 callback.callback(), 1778 callback.callback(),
1779 pool_.get(), 1779 pool_.get(),
1780 BoundNetLog())); 1780 BoundNetLog()));
1781 CapturingBoundNetLog log2; 1781 BoundTestNetLog log2;
1782 EXPECT_EQ(ERR_IO_PENDING, 1782 EXPECT_EQ(ERR_IO_PENDING,
1783 handle2.Init("a", 1783 handle2.Init("a",
1784 params_, 1784 params_,
1785 DEFAULT_PRIORITY, 1785 DEFAULT_PRIORITY,
1786 callback2.callback(), 1786 callback2.callback(),
1787 pool_.get(), 1787 pool_.get(),
1788 BoundNetLog())); 1788 BoundNetLog()));
1789 1789
1790 handle.Reset(); 1790 handle.Reset();
1791 1791
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
2208 // Use and release the socket. 2208 // Use and release the socket.
2209 EXPECT_EQ(1, handle.socket()->Write(NULL, 1, CompletionCallback())); 2209 EXPECT_EQ(1, handle.socket()->Write(NULL, 1, CompletionCallback()));
2210 TestLoadTimingInfoConnectedNotReused(handle); 2210 TestLoadTimingInfoConnectedNotReused(handle);
2211 handle.Reset(); 2211 handle.Reset();
2212 2212
2213 // Should now have one idle socket. 2213 // Should now have one idle socket.
2214 ASSERT_EQ(1, pool_->IdleSocketCount()); 2214 ASSERT_EQ(1, pool_->IdleSocketCount());
2215 2215
2216 // Request a new socket. This should reuse the old socket and complete 2216 // Request a new socket. This should reuse the old socket and complete
2217 // synchronously. 2217 // synchronously.
2218 CapturingBoundNetLog log; 2218 BoundTestNetLog log;
2219 rv = handle.Init("a", 2219 rv = handle.Init("a",
2220 params_, 2220 params_,
2221 LOWEST, 2221 LOWEST,
2222 CompletionCallback(), 2222 CompletionCallback(),
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2288 // to flush all tasks, we need to wait so that we know there are no 2288 // to flush all tasks, we need to wait so that we know there are no
2289 // soon-to-be-pending tasks waiting. 2289 // soon-to-be-pending tasks waiting.
2290 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); 2290 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
2291 base::MessageLoop::current()->RunUntilIdle(); 2291 base::MessageLoop::current()->RunUntilIdle();
2292 2292
2293 // Both sockets should now be idle. 2293 // Both sockets should now be idle.
2294 ASSERT_EQ(2, pool_->IdleSocketCount()); 2294 ASSERT_EQ(2, pool_->IdleSocketCount());
2295 2295
2296 // Request a new socket. This should cleanup the unused and timed out ones. 2296 // Request a new socket. This should cleanup the unused and timed out ones.
2297 // A new socket will be created rather than reusing the idle one. 2297 // A new socket will be created rather than reusing the idle one.
2298 CapturingBoundNetLog log; 2298 BoundTestNetLog log;
2299 TestCompletionCallback callback3; 2299 TestCompletionCallback callback3;
2300 rv = handle.Init("a", 2300 rv = handle.Init("a",
2301 params_, 2301 params_,
2302 LOWEST, 2302 LOWEST,
2303 callback3.callback(), 2303 callback3.callback(),
2304 pool_.get(), 2304 pool_.get(),
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2367 // soon-to-be-pending tasks waiting. 2367 // soon-to-be-pending tasks waiting.
2368 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); 2368 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
2369 base::MessageLoop::current()->RunUntilIdle(); 2369 base::MessageLoop::current()->RunUntilIdle();
2370 2370
2371 ASSERT_EQ(2, pool_->IdleSocketCount()); 2371 ASSERT_EQ(2, pool_->IdleSocketCount());
2372 2372
2373 // Invoke the idle socket cleanup check. Only one socket should be left, the 2373 // Invoke the idle socket cleanup check. Only one socket should be left, the
2374 // used socket. Request it to make sure that it's used. 2374 // used socket. Request it to make sure that it's used.
2375 2375
2376 pool_->CleanupTimedOutIdleSockets(); 2376 pool_->CleanupTimedOutIdleSockets();
2377 CapturingBoundNetLog log; 2377 BoundTestNetLog 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
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
OLDNEW
« no previous file with comments | « net/quic/quic_network_transaction_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