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