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" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
17 #include "base/run_loop.h" | |
17 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
18 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
19 #include "base/threading/platform_thread.h" | 20 #include "base/threading/platform_thread.h" |
20 #include "base/values.h" | 21 #include "base/values.h" |
22 #include "net/base/load_timing_info.h" | |
21 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
22 #include "net/base/net_log.h" | 24 #include "net/base/net_log.h" |
23 #include "net/base/net_log_unittest.h" | 25 #include "net/base/net_log_unittest.h" |
24 #include "net/base/request_priority.h" | 26 #include "net/base/request_priority.h" |
25 #include "net/base/test_completion_callback.h" | 27 #include "net/base/test_completion_callback.h" |
26 #include "net/http/http_response_headers.h" | 28 #include "net/http/http_response_headers.h" |
27 #include "net/socket/client_socket_factory.h" | 29 #include "net/socket/client_socket_factory.h" |
28 #include "net/socket/client_socket_handle.h" | 30 #include "net/socket/client_socket_handle.h" |
29 #include "net/socket/client_socket_pool_histograms.h" | 31 #include "net/socket/client_socket_pool_histograms.h" |
30 #include "net/socket/socket_test_util.h" | 32 #include "net/socket/socket_test_util.h" |
31 #include "net/socket/stream_socket.h" | 33 #include "net/socket/stream_socket.h" |
32 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
33 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
34 | 36 |
35 using ::testing::Invoke; | 37 using ::testing::Invoke; |
36 using ::testing::Return; | 38 using ::testing::Return; |
37 | 39 |
38 namespace net { | 40 namespace net { |
39 | 41 |
40 namespace { | 42 namespace { |
41 | 43 |
42 const int kDefaultMaxSockets = 4; | 44 const int kDefaultMaxSockets = 4; |
43 const int kDefaultMaxSocketsPerGroup = 2; | 45 const int kDefaultMaxSocketsPerGroup = 2; |
44 const net::RequestPriority kDefaultPriority = MEDIUM; | 46 const net::RequestPriority kDefaultPriority = MEDIUM; |
45 | 47 |
48 // Make sure |handle| sets load times are set correctly when it has been | |
eroman
2012/12/14 04:08:35
This reads weird, i think there is a "set" too man
mmenke
2012/12/14 13:36:12
Done. I should know by now to vet all my last min
| |
49 // assigned a reused socket. | |
50 void TestLoadTimingInfoConnectedReused(const ClientSocketHandle& handle) { | |
51 LoadTimingInfo load_timing_info; | |
52 // Only pass true in as |is_reused|, as in general, HttpStream types should | |
53 // have stricter concepts of reuse than socket pools. | |
54 EXPECT_TRUE(handle.GetLoadTimingInfo(true, &load_timing_info)); | |
55 | |
56 EXPECT_EQ(true, load_timing_info.socket_reused); | |
57 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | |
58 | |
59 EXPECT_TRUE(load_timing_info.connect_start.is_null()); | |
60 EXPECT_TRUE(load_timing_info.connect_end.is_null()); | |
61 EXPECT_TRUE(load_timing_info.dns_start.is_null()); | |
62 EXPECT_TRUE(load_timing_info.dns_end.is_null()); | |
63 EXPECT_TRUE(load_timing_info.ssl_start.is_null()); | |
64 EXPECT_TRUE(load_timing_info.ssl_end.is_null()); | |
65 EXPECT_TRUE(load_timing_info.proxy_start.is_null()); | |
66 EXPECT_TRUE(load_timing_info.proxy_end.is_null()); | |
67 EXPECT_TRUE(load_timing_info.send_start.is_null()); | |
68 EXPECT_TRUE(load_timing_info.send_end.is_null()); | |
69 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); | |
70 } | |
71 | |
72 // Make sure |handle| sets load times are set correctly when it has been | |
eroman
2012/12/14 04:08:35
same comment as earlier.
mmenke
2012/12/14 13:36:12
Done.
| |
73 // assigned a fresh socket. Also runs TestLoadTimingInfoConnectedReused, since | |
74 // the own of a connection where |is_reused| is false may consider the | |
eroman
2012/12/14 04:08:35
typo? "the own of a connection"
mmenke
2012/12/14 13:36:12
Done.
| |
75 // connection reused. | |
76 void TestLoadTimingInfoConnectedNotReused(const ClientSocketHandle& handle) { | |
77 EXPECT_FALSE(handle.is_reused()); | |
78 | |
79 LoadTimingInfo load_timing_info; | |
80 EXPECT_TRUE(handle.GetLoadTimingInfo(false, &load_timing_info)); | |
81 | |
82 EXPECT_FALSE(load_timing_info.socket_reused); | |
83 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | |
84 | |
85 EXPECT_FALSE(load_timing_info.connect_start.is_null()); | |
86 EXPECT_LE(load_timing_info.connect_start, load_timing_info.connect_end); | |
87 EXPECT_TRUE(load_timing_info.dns_start.is_null()); | |
88 EXPECT_TRUE(load_timing_info.dns_end.is_null()); | |
89 EXPECT_TRUE(load_timing_info.ssl_start.is_null()); | |
90 EXPECT_TRUE(load_timing_info.ssl_end.is_null()); | |
91 EXPECT_TRUE(load_timing_info.proxy_start.is_null()); | |
92 EXPECT_TRUE(load_timing_info.proxy_end.is_null()); | |
93 EXPECT_TRUE(load_timing_info.send_start.is_null()); | |
94 EXPECT_TRUE(load_timing_info.send_end.is_null()); | |
95 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); | |
96 | |
97 TestLoadTimingInfoConnectedReused(handle); | |
98 } | |
99 | |
100 // Make sure |handle| sets load times correctly, in the case that it does not | |
101 // currently have a socket. | |
102 void TestLoadTimingInfoNotConnected(const ClientSocketHandle& handle) { | |
103 // Should only be set to true once a socket is assigned, if at all. | |
104 EXPECT_FALSE(handle.is_reused()); | |
105 | |
106 LoadTimingInfo load_timing_info; | |
107 EXPECT_FALSE(handle.GetLoadTimingInfo(false, &load_timing_info)); | |
108 | |
109 EXPECT_FALSE(load_timing_info.socket_reused); | |
110 EXPECT_EQ(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | |
111 | |
112 EXPECT_TRUE(load_timing_info.connect_start.is_null()); | |
113 EXPECT_TRUE(load_timing_info.connect_end.is_null()); | |
114 EXPECT_TRUE(load_timing_info.dns_start.is_null()); | |
115 EXPECT_TRUE(load_timing_info.dns_end.is_null()); | |
116 EXPECT_TRUE(load_timing_info.ssl_start.is_null()); | |
117 EXPECT_TRUE(load_timing_info.ssl_end.is_null()); | |
118 EXPECT_TRUE(load_timing_info.proxy_start.is_null()); | |
119 EXPECT_TRUE(load_timing_info.proxy_end.is_null()); | |
120 EXPECT_TRUE(load_timing_info.send_start.is_null()); | |
121 EXPECT_TRUE(load_timing_info.send_end.is_null()); | |
122 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); | |
123 } | |
124 | |
46 class TestSocketParams : public base::RefCounted<TestSocketParams> { | 125 class TestSocketParams : public base::RefCounted<TestSocketParams> { |
47 public: | 126 public: |
48 TestSocketParams() : ignore_limits_(false) {} | 127 TestSocketParams() : ignore_limits_(false) {} |
49 | 128 |
50 void set_ignore_limits(bool ignore_limits) { | 129 void set_ignore_limits(bool ignore_limits) { |
51 ignore_limits_ = ignore_limits; | 130 ignore_limits_ = ignore_limits; |
52 } | 131 } |
53 bool ignore_limits() { return ignore_limits_; } | 132 bool ignore_limits() { return ignore_limits_; } |
54 | 133 |
55 private: | 134 private: |
56 friend class base::RefCounted<TestSocketParams>; | 135 friend class base::RefCounted<TestSocketParams>; |
57 ~TestSocketParams() {} | 136 ~TestSocketParams() {} |
58 | 137 |
59 bool ignore_limits_; | 138 bool ignore_limits_; |
60 }; | 139 }; |
61 typedef ClientSocketPoolBase<TestSocketParams> TestClientSocketPoolBase; | 140 typedef ClientSocketPoolBase<TestSocketParams> TestClientSocketPoolBase; |
62 | 141 |
63 class MockClientSocket : public StreamSocket { | 142 class MockClientSocket : public StreamSocket { |
64 public: | 143 public: |
65 MockClientSocket() : connected_(false), was_used_to_convey_data_(false), | 144 explicit MockClientSocket(net::NetLog* net_log) |
66 num_bytes_read_(0) {} | 145 : connected_(false), |
146 net_log_(BoundNetLog::Make(net_log, net::NetLog::SOURCE_SOCKET)), | |
147 was_used_to_convey_data_(false), | |
148 num_bytes_read_(0) { | |
149 } | |
67 | 150 |
68 // Socket implementation. | 151 // Socket implementation. |
69 virtual int Read( | 152 virtual int Read( |
70 IOBuffer* /* buf */, int len, | 153 IOBuffer* /* buf */, int len, |
71 const CompletionCallback& /* callback */) OVERRIDE { | 154 const CompletionCallback& /* callback */) OVERRIDE { |
72 num_bytes_read_ += len; | 155 num_bytes_read_ += len; |
73 return len; | 156 return len; |
74 } | 157 } |
75 | 158 |
76 virtual int Write( | 159 virtual int Write( |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 } | 314 } |
232 } | 315 } |
233 | 316 |
234 private: | 317 private: |
235 // ConnectJob implementation. | 318 // ConnectJob implementation. |
236 | 319 |
237 virtual int ConnectInternal() { | 320 virtual int ConnectInternal() { |
238 AddressList ignored; | 321 AddressList ignored; |
239 client_socket_factory_->CreateTransportClientSocket( | 322 client_socket_factory_->CreateTransportClientSocket( |
240 ignored, NULL, net::NetLog::Source()); | 323 ignored, NULL, net::NetLog::Source()); |
241 set_socket(new MockClientSocket()); | 324 set_socket(new MockClientSocket(net_log().net_log())); |
242 switch (job_type_) { | 325 switch (job_type_) { |
243 case kMockJob: | 326 case kMockJob: |
244 return DoConnect(true /* successful */, false /* sync */, | 327 return DoConnect(true /* successful */, false /* sync */, |
245 false /* recoverable */); | 328 false /* recoverable */); |
246 case kMockFailingJob: | 329 case kMockFailingJob: |
247 return DoConnect(false /* error */, false /* sync */, | 330 return DoConnect(false /* error */, false /* sync */, |
248 false /* recoverable */); | 331 false /* recoverable */); |
249 case kMockPendingJob: | 332 case kMockPendingJob: |
250 set_load_state(LOAD_STATE_CONNECTING); | 333 set_load_state(LOAD_STATE_CONNECTING); |
251 | 334 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 base::WeakPtrFactory<TestConnectJob> weak_factory_; | 449 base::WeakPtrFactory<TestConnectJob> weak_factory_; |
367 LoadState load_state_; | 450 LoadState load_state_; |
368 bool store_additional_error_state_; | 451 bool store_additional_error_state_; |
369 | 452 |
370 DISALLOW_COPY_AND_ASSIGN(TestConnectJob); | 453 DISALLOW_COPY_AND_ASSIGN(TestConnectJob); |
371 }; | 454 }; |
372 | 455 |
373 class TestConnectJobFactory | 456 class TestConnectJobFactory |
374 : public TestClientSocketPoolBase::ConnectJobFactory { | 457 : public TestClientSocketPoolBase::ConnectJobFactory { |
375 public: | 458 public: |
376 explicit TestConnectJobFactory(MockClientSocketFactory* client_socket_factory) | 459 TestConnectJobFactory(MockClientSocketFactory* client_socket_factory, |
460 NetLog* net_log) | |
377 : job_type_(TestConnectJob::kMockJob), | 461 : job_type_(TestConnectJob::kMockJob), |
378 job_types_(NULL), | 462 job_types_(NULL), |
379 client_socket_factory_(client_socket_factory) {} | 463 client_socket_factory_(client_socket_factory), |
464 net_log_(net_log) { | |
465 } | |
380 | 466 |
381 virtual ~TestConnectJobFactory() {} | 467 virtual ~TestConnectJobFactory() {} |
382 | 468 |
383 void set_job_type(TestConnectJob::JobType job_type) { job_type_ = job_type; } | 469 void set_job_type(TestConnectJob::JobType job_type) { job_type_ = job_type; } |
384 | 470 |
385 void set_job_types(std::list<TestConnectJob::JobType>* job_types) { | 471 void set_job_types(std::list<TestConnectJob::JobType>* job_types) { |
386 job_types_ = job_types; | 472 job_types_ = job_types; |
387 CHECK(!job_types_->empty()); | 473 CHECK(!job_types_->empty()); |
388 } | 474 } |
389 | 475 |
(...skipping 12 matching lines...) Expand all Loading... | |
402 if (job_types_ && !job_types_->empty()) { | 488 if (job_types_ && !job_types_->empty()) { |
403 job_type = job_types_->front(); | 489 job_type = job_types_->front(); |
404 job_types_->pop_front(); | 490 job_types_->pop_front(); |
405 } | 491 } |
406 return new TestConnectJob(job_type, | 492 return new TestConnectJob(job_type, |
407 group_name, | 493 group_name, |
408 request, | 494 request, |
409 timeout_duration_, | 495 timeout_duration_, |
410 delegate, | 496 delegate, |
411 client_socket_factory_, | 497 client_socket_factory_, |
412 NULL); | 498 net_log_); |
413 } | 499 } |
414 | 500 |
415 virtual base::TimeDelta ConnectionTimeout() const { | 501 virtual base::TimeDelta ConnectionTimeout() const { |
416 return timeout_duration_; | 502 return timeout_duration_; |
417 } | 503 } |
418 | 504 |
419 private: | 505 private: |
420 TestConnectJob::JobType job_type_; | 506 TestConnectJob::JobType job_type_; |
421 std::list<TestConnectJob::JobType>* job_types_; | 507 std::list<TestConnectJob::JobType>* job_types_; |
422 base::TimeDelta timeout_duration_; | 508 base::TimeDelta timeout_duration_; |
423 MockClientSocketFactory* const client_socket_factory_; | 509 MockClientSocketFactory* const client_socket_factory_; |
510 NetLog* net_log_; | |
424 | 511 |
425 DISALLOW_COPY_AND_ASSIGN(TestConnectJobFactory); | 512 DISALLOW_COPY_AND_ASSIGN(TestConnectJobFactory); |
426 }; | 513 }; |
427 | 514 |
428 class TestClientSocketPool : public ClientSocketPool { | 515 class TestClientSocketPool : public ClientSocketPool { |
429 public: | 516 public: |
430 TestClientSocketPool( | 517 TestClientSocketPool( |
431 int max_sockets, | 518 int max_sockets, |
432 int max_sockets_per_group, | 519 int max_sockets_per_group, |
433 ClientSocketPoolHistograms* histograms, | 520 ClientSocketPoolHistograms* histograms, |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
631 max_sockets_per_group, | 718 max_sockets_per_group, |
632 ClientSocketPool::unused_idle_socket_timeout(), | 719 ClientSocketPool::unused_idle_socket_timeout(), |
633 ClientSocketPool::used_idle_socket_timeout()); | 720 ClientSocketPool::used_idle_socket_timeout()); |
634 } | 721 } |
635 | 722 |
636 void CreatePoolWithIdleTimeouts( | 723 void CreatePoolWithIdleTimeouts( |
637 int max_sockets, int max_sockets_per_group, | 724 int max_sockets, int max_sockets_per_group, |
638 base::TimeDelta unused_idle_socket_timeout, | 725 base::TimeDelta unused_idle_socket_timeout, |
639 base::TimeDelta used_idle_socket_timeout) { | 726 base::TimeDelta used_idle_socket_timeout) { |
640 DCHECK(!pool_.get()); | 727 DCHECK(!pool_.get()); |
641 connect_job_factory_ = new TestConnectJobFactory(&client_socket_factory_); | 728 connect_job_factory_ = new TestConnectJobFactory(&client_socket_factory_, |
729 &net_log_); | |
642 pool_.reset(new TestClientSocketPool(max_sockets, | 730 pool_.reset(new TestClientSocketPool(max_sockets, |
643 max_sockets_per_group, | 731 max_sockets_per_group, |
644 &histograms_, | 732 &histograms_, |
645 unused_idle_socket_timeout, | 733 unused_idle_socket_timeout, |
646 used_idle_socket_timeout, | 734 used_idle_socket_timeout, |
647 connect_job_factory_)); | 735 connect_job_factory_)); |
648 } | 736 } |
649 | 737 |
650 int StartRequest(const std::string& group_name, | 738 int StartRequest(const std::string& group_name, |
651 net::RequestPriority priority) { | 739 net::RequestPriority priority) { |
(...skipping 12 matching lines...) Expand all Loading... | |
664 | 752 |
665 void ReleaseAllConnections(ClientSocketPoolTest::KeepAlive keep_alive) { | 753 void ReleaseAllConnections(ClientSocketPoolTest::KeepAlive keep_alive) { |
666 test_base_.ReleaseAllConnections(keep_alive); | 754 test_base_.ReleaseAllConnections(keep_alive); |
667 } | 755 } |
668 | 756 |
669 TestSocketRequest* request(int i) { return test_base_.request(i); } | 757 TestSocketRequest* request(int i) { return test_base_.request(i); } |
670 size_t requests_size() const { return test_base_.requests_size(); } | 758 size_t requests_size() const { return test_base_.requests_size(); } |
671 ScopedVector<TestSocketRequest>* requests() { return test_base_.requests(); } | 759 ScopedVector<TestSocketRequest>* requests() { return test_base_.requests(); } |
672 size_t completion_count() const { return test_base_.completion_count(); } | 760 size_t completion_count() const { return test_base_.completion_count(); } |
673 | 761 |
762 CapturingNetLog net_log_; | |
674 bool connect_backup_jobs_enabled_; | 763 bool connect_backup_jobs_enabled_; |
675 bool cleanup_timer_enabled_; | 764 bool cleanup_timer_enabled_; |
676 MockClientSocketFactory client_socket_factory_; | 765 MockClientSocketFactory client_socket_factory_; |
677 TestConnectJobFactory* connect_job_factory_; | 766 TestConnectJobFactory* connect_job_factory_; |
678 scoped_refptr<TestSocketParams> params_; | 767 scoped_refptr<TestSocketParams> params_; |
679 ClientSocketPoolHistograms histograms_; | 768 ClientSocketPoolHistograms histograms_; |
680 scoped_ptr<TestClientSocketPool> pool_; | 769 scoped_ptr<TestClientSocketPool> pool_; |
681 ClientSocketPoolTest test_base_; | 770 ClientSocketPoolTest test_base_; |
682 }; | 771 }; |
683 | 772 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
807 EXPECT_TRUE(LogContainsEndEvent( | 896 EXPECT_TRUE(LogContainsEndEvent( |
808 entries, 5, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); | 897 entries, 5, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); |
809 } | 898 } |
810 | 899 |
811 TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) { | 900 TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) { |
812 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 901 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
813 | 902 |
814 TestCompletionCallback callback; | 903 TestCompletionCallback callback; |
815 ClientSocketHandle handle; | 904 ClientSocketHandle handle; |
816 CapturingBoundNetLog log; | 905 CapturingBoundNetLog log; |
906 TestLoadTimingInfoNotConnected(handle); | |
817 | 907 |
818 EXPECT_EQ(OK, | 908 EXPECT_EQ(OK, |
819 handle.Init("a", | 909 handle.Init("a", |
820 params_, | 910 params_, |
821 kDefaultPriority, | 911 kDefaultPriority, |
822 callback.callback(), | 912 callback.callback(), |
823 pool_.get(), | 913 pool_.get(), |
824 log.bound())); | 914 log.bound())); |
825 EXPECT_TRUE(handle.is_initialized()); | 915 EXPECT_TRUE(handle.is_initialized()); |
826 EXPECT_TRUE(handle.socket()); | 916 EXPECT_TRUE(handle.socket()); |
917 TestLoadTimingInfoConnectedNotReused(handle); | |
918 | |
827 handle.Reset(); | 919 handle.Reset(); |
920 TestLoadTimingInfoNotConnected(handle); | |
828 | 921 |
829 CapturingNetLog::CapturedEntryList entries; | 922 CapturingNetLog::CapturedEntryList entries; |
830 log.GetEntries(&entries); | 923 log.GetEntries(&entries); |
831 | 924 |
832 EXPECT_EQ(4u, entries.size()); | 925 EXPECT_EQ(4u, entries.size()); |
833 EXPECT_TRUE(LogContainsBeginEvent( | 926 EXPECT_TRUE(LogContainsBeginEvent( |
834 entries, 0, NetLog::TYPE_SOCKET_POOL)); | 927 entries, 0, NetLog::TYPE_SOCKET_POOL)); |
835 EXPECT_TRUE(LogContainsEvent( | 928 EXPECT_TRUE(LogContainsEvent( |
836 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, | 929 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, |
837 NetLog::PHASE_NONE)); | 930 NetLog::PHASE_NONE)); |
(...skipping 20 matching lines...) Expand all Loading... | |
858 EXPECT_EQ(ERR_CONNECTION_FAILED, | 951 EXPECT_EQ(ERR_CONNECTION_FAILED, |
859 handle.Init("a", | 952 handle.Init("a", |
860 params_, | 953 params_, |
861 kDefaultPriority, | 954 kDefaultPriority, |
862 callback.callback(), | 955 callback.callback(), |
863 pool_.get(), | 956 pool_.get(), |
864 log.bound())); | 957 log.bound())); |
865 EXPECT_FALSE(handle.socket()); | 958 EXPECT_FALSE(handle.socket()); |
866 EXPECT_FALSE(handle.is_ssl_error()); | 959 EXPECT_FALSE(handle.is_ssl_error()); |
867 EXPECT_TRUE(handle.ssl_error_response_info().headers.get() == NULL); | 960 EXPECT_TRUE(handle.ssl_error_response_info().headers.get() == NULL); |
961 TestLoadTimingInfoNotConnected(handle); | |
868 | 962 |
869 CapturingNetLog::CapturedEntryList entries; | 963 CapturingNetLog::CapturedEntryList entries; |
870 log.GetEntries(&entries); | 964 log.GetEntries(&entries); |
871 | 965 |
872 EXPECT_EQ(3u, entries.size()); | 966 EXPECT_EQ(3u, entries.size()); |
873 EXPECT_TRUE(LogContainsBeginEvent( | 967 EXPECT_TRUE(LogContainsBeginEvent( |
874 entries, 0, NetLog::TYPE_SOCKET_POOL)); | 968 entries, 0, NetLog::TYPE_SOCKET_POOL)); |
875 EXPECT_TRUE(LogContainsEvent( | 969 EXPECT_TRUE(LogContainsEvent( |
876 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, | 970 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, |
877 NetLog::PHASE_NONE)); | 971 NetLog::PHASE_NONE)); |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1627 rv = handle.Init("a", | 1721 rv = handle.Init("a", |
1628 params_, | 1722 params_, |
1629 kDefaultPriority, | 1723 kDefaultPriority, |
1630 callback.callback(), | 1724 callback.callback(), |
1631 pool_.get(), | 1725 pool_.get(), |
1632 BoundNetLog()); | 1726 BoundNetLog()); |
1633 EXPECT_EQ(ERR_IO_PENDING, rv); | 1727 EXPECT_EQ(ERR_IO_PENDING, rv); |
1634 EXPECT_EQ(OK, callback.WaitForResult()); | 1728 EXPECT_EQ(OK, callback.WaitForResult()); |
1635 | 1729 |
1636 EXPECT_FALSE(handle.is_reused()); | 1730 EXPECT_FALSE(handle.is_reused()); |
1731 TestLoadTimingInfoConnectedNotReused(handle); | |
1637 EXPECT_EQ(2, client_socket_factory_.allocation_count()); | 1732 EXPECT_EQ(2, client_socket_factory_.allocation_count()); |
1638 } | 1733 } |
1639 | 1734 |
1640 // Regression test for http://crbug.com/17985. | 1735 // Regression test for http://crbug.com/17985. |
1641 TEST_F(ClientSocketPoolBaseTest, GroupWithPendingRequestsIsNotEmpty) { | 1736 TEST_F(ClientSocketPoolBaseTest, GroupWithPendingRequestsIsNotEmpty) { |
1642 const int kMaxSockets = 3; | 1737 const int kMaxSockets = 3; |
1643 const int kMaxSocketsPerGroup = 2; | 1738 const int kMaxSocketsPerGroup = 2; |
1644 CreatePool(kMaxSockets, kMaxSocketsPerGroup); | 1739 CreatePool(kMaxSockets, kMaxSocketsPerGroup); |
1645 | 1740 |
1646 const RequestPriority kHighPriority = HIGHEST; | 1741 const RequestPriority kHighPriority = HIGHEST; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1681 TestCompletionCallback callback; | 1776 TestCompletionCallback callback; |
1682 CapturingBoundNetLog log; | 1777 CapturingBoundNetLog log; |
1683 int rv = handle.Init("a", | 1778 int rv = handle.Init("a", |
1684 params_, | 1779 params_, |
1685 LOWEST, | 1780 LOWEST, |
1686 callback.callback(), | 1781 callback.callback(), |
1687 pool_.get(), | 1782 pool_.get(), |
1688 log.bound()); | 1783 log.bound()); |
1689 EXPECT_EQ(ERR_IO_PENDING, rv); | 1784 EXPECT_EQ(ERR_IO_PENDING, rv); |
1690 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle)); | 1785 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle)); |
1786 TestLoadTimingInfoNotConnected(handle); | |
1787 | |
1691 EXPECT_EQ(OK, callback.WaitForResult()); | 1788 EXPECT_EQ(OK, callback.WaitForResult()); |
1692 EXPECT_TRUE(handle.is_initialized()); | 1789 EXPECT_TRUE(handle.is_initialized()); |
1693 EXPECT_TRUE(handle.socket()); | 1790 EXPECT_TRUE(handle.socket()); |
1791 TestLoadTimingInfoConnectedNotReused(handle); | |
1792 | |
1694 handle.Reset(); | 1793 handle.Reset(); |
1794 TestLoadTimingInfoNotConnected(handle); | |
1695 | 1795 |
1696 CapturingNetLog::CapturedEntryList entries; | 1796 CapturingNetLog::CapturedEntryList entries; |
1697 log.GetEntries(&entries); | 1797 log.GetEntries(&entries); |
1698 | 1798 |
1699 EXPECT_EQ(4u, entries.size()); | 1799 EXPECT_EQ(4u, entries.size()); |
1700 EXPECT_TRUE(LogContainsBeginEvent( | 1800 EXPECT_TRUE(LogContainsBeginEvent( |
1701 entries, 0, NetLog::TYPE_SOCKET_POOL)); | 1801 entries, 0, NetLog::TYPE_SOCKET_POOL)); |
1702 EXPECT_TRUE(LogContainsEvent( | 1802 EXPECT_TRUE(LogContainsEvent( |
1703 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, | 1803 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, |
1704 NetLog::PHASE_NONE)); | 1804 NetLog::PHASE_NONE)); |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2037 LOWEST, | 2137 LOWEST, |
2038 callback.callback(), | 2138 callback.callback(), |
2039 pool_.get(), | 2139 pool_.get(), |
2040 BoundNetLog()); | 2140 BoundNetLog()); |
2041 ASSERT_EQ(ERR_IO_PENDING, rv); | 2141 ASSERT_EQ(ERR_IO_PENDING, rv); |
2042 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle)); | 2142 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle)); |
2043 ASSERT_EQ(OK, callback.WaitForResult()); | 2143 ASSERT_EQ(OK, callback.WaitForResult()); |
2044 | 2144 |
2045 // Use and release the socket. | 2145 // Use and release the socket. |
2046 EXPECT_EQ(1, handle.socket()->Write(NULL, 1, CompletionCallback())); | 2146 EXPECT_EQ(1, handle.socket()->Write(NULL, 1, CompletionCallback())); |
2147 TestLoadTimingInfoConnectedNotReused(handle); | |
2047 handle.Reset(); | 2148 handle.Reset(); |
2048 | 2149 |
2049 // Should now have one idle socket. | 2150 // Should now have one idle socket. |
2050 ASSERT_EQ(1, pool_->IdleSocketCount()); | 2151 ASSERT_EQ(1, pool_->IdleSocketCount()); |
2051 | 2152 |
2052 // Request a new socket. This should reuse the old socket and complete | 2153 // Request a new socket. This should reuse the old socket and complete |
2053 // synchronously. | 2154 // synchronously. |
2054 CapturingBoundNetLog log; | 2155 CapturingBoundNetLog log; |
2055 rv = handle.Init("a", | 2156 rv = handle.Init("a", |
2056 params_, | 2157 params_, |
2057 LOWEST, | 2158 LOWEST, |
2058 CompletionCallback(), | 2159 CompletionCallback(), |
2059 pool_.get(), | 2160 pool_.get(), |
2060 log.bound()); | 2161 log.bound()); |
2061 ASSERT_EQ(OK, rv); | 2162 ASSERT_EQ(OK, rv); |
2062 EXPECT_TRUE(handle.is_reused()); | 2163 EXPECT_TRUE(handle.is_reused()); |
2164 TestLoadTimingInfoConnectedReused(handle); | |
2063 | 2165 |
2064 ASSERT_TRUE(pool_->HasGroup("a")); | 2166 ASSERT_TRUE(pool_->HasGroup("a")); |
2065 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); | 2167 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); |
2066 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); | 2168 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); |
2067 | 2169 |
2068 CapturingNetLog::CapturedEntryList entries; | 2170 CapturingNetLog::CapturedEntryList entries; |
2069 log.GetEntries(&entries); | 2171 log.GetEntries(&entries); |
2070 EXPECT_TRUE(LogContainsEntryWithType( | 2172 EXPECT_TRUE(LogContainsEntryWithType( |
2071 entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET)); | 2173 entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET)); |
2072 } | 2174 } |
(...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3376 callback1.callback(), | 3478 callback1.callback(), |
3377 pool_.get(), | 3479 pool_.get(), |
3378 BoundNetLog())); | 3480 BoundNetLog())); |
3379 | 3481 |
3380 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); | 3482 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); |
3381 EXPECT_EQ(0, pool_->NumUnassignedConnectJobsInGroup("a")); | 3483 EXPECT_EQ(0, pool_->NumUnassignedConnectJobsInGroup("a")); |
3382 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); | 3484 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); |
3383 | 3485 |
3384 ASSERT_EQ(OK, callback1.WaitForResult()); | 3486 ASSERT_EQ(OK, callback1.WaitForResult()); |
3385 | 3487 |
3488 // Make sure if a preconneced socket is not fully connected when a request | |
3489 // starts, it has a connect start time. | |
3490 TestLoadTimingInfoConnectedNotReused(handle1); | |
3386 handle1.Reset(); | 3491 handle1.Reset(); |
3387 | 3492 |
3388 EXPECT_EQ(1, pool_->IdleSocketCountInGroup("a")); | 3493 EXPECT_EQ(1, pool_->IdleSocketCountInGroup("a")); |
3389 } | 3494 } |
3390 | 3495 |
3496 // Checks that fully connected preconnect jobs have no connect times, and are | |
3497 // marked as reused. | |
3498 TEST_F(ClientSocketPoolBaseTest, ConnectedPreconnectJobsHaveNoConnectTimes) { | |
3499 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | |
3500 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); | |
3501 pool_->RequestSockets("a", ¶ms_, 1, BoundNetLog()); | |
3502 | |
3503 ASSERT_TRUE(pool_->HasGroup("a")); | |
3504 EXPECT_EQ(0, pool_->NumConnectJobsInGroup("a")); | |
3505 EXPECT_EQ(0, pool_->NumUnassignedConnectJobsInGroup("a")); | |
3506 EXPECT_EQ(1, pool_->IdleSocketCountInGroup("a")); | |
3507 | |
3508 ClientSocketHandle handle; | |
3509 TestCompletionCallback callback; | |
3510 EXPECT_EQ(OK, handle.Init("a", | |
3511 params_, | |
3512 kDefaultPriority, | |
3513 callback.callback(), | |
3514 pool_.get(), | |
3515 BoundNetLog())); | |
3516 | |
3517 // Make sure thee idle socket was used. | |
eroman
2012/12/14 04:08:35
thee --> the; unless thou wants to sound pompous.
mmenke
2012/12/14 13:36:12
Done.
| |
3518 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); | |
3519 | |
3520 TestLoadTimingInfoConnectedReused(handle); | |
3521 handle.Reset(); | |
3522 TestLoadTimingInfoNotConnected(handle); | |
3523 } | |
3524 | |
3391 // http://crbug.com/64940 regression test. | 3525 // http://crbug.com/64940 regression test. |
3392 TEST_F(ClientSocketPoolBaseTest, PreconnectClosesIdleSocketRemovesGroup) { | 3526 TEST_F(ClientSocketPoolBaseTest, PreconnectClosesIdleSocketRemovesGroup) { |
3393 const int kMaxTotalSockets = 3; | 3527 const int kMaxTotalSockets = 3; |
3394 const int kMaxSocketsPerGroup = 2; | 3528 const int kMaxSocketsPerGroup = 2; |
3395 CreatePool(kMaxTotalSockets, kMaxSocketsPerGroup); | 3529 CreatePool(kMaxTotalSockets, kMaxSocketsPerGroup); |
3396 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 3530 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
3397 | 3531 |
3398 // Note that group name ordering matters here. "a" comes before "b", so | 3532 // Note that group name ordering matters here. "a" comes before "b", so |
3399 // CloseOneIdleSocket() will try to close "a"'s idle socket. | 3533 // CloseOneIdleSocket() will try to close "a"'s idle socket. |
3400 | 3534 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3524 // complete. | 3658 // complete. |
3525 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); | 3659 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); |
3526 EXPECT_EQ(0, pool_->NumUnassignedConnectJobsInGroup("a")); | 3660 EXPECT_EQ(0, pool_->NumUnassignedConnectJobsInGroup("a")); |
3527 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); | 3661 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); |
3528 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); | 3662 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); |
3529 } | 3663 } |
3530 | 3664 |
3531 } // namespace | 3665 } // namespace |
3532 | 3666 |
3533 } // namespace net | 3667 } // namespace net |
OLD | NEW |