Avi Drissman | 6459548 | 2022-09-14 20:52:29 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
tbansal | f82cc8e | 2015-10-14 20:05:49 | [diff] [blame] | 5 | #include <stdint.h> |
Daniel Cheng | 5feb16f | 2022-02-28 06:52:07 | [diff] [blame] | 6 | |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 7 | #include <utility> |
[email protected] | 51fdc7c | 2012-04-10 19:19:48 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
Hans Wennborg | 0924470b | 2020-04-27 21:08:05 | [diff] [blame] | 10 | #include "base/check_op.h" |
Avi Drissman | 41c4a41 | 2023-01-11 22:45:37 | [diff] [blame] | 11 | #include "base/functional/bind.h" |
| 12 | #include "base/functional/callback.h" |
| 13 | #include "base/functional/callback_helpers.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 14 | #include "base/location.h" |
Daniel Cheng | 5feb16f | 2022-02-28 06:52:07 | [diff] [blame] | 15 | #include "base/memory/raw_ptr.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 16 | #include "base/memory/ref_counted.h" |
[email protected] | 6ea7b15 | 2011-12-21 21:21:13 | [diff] [blame] | 17 | #include "base/memory/weak_ptr.h" |
Hans Wennborg | 0924470b | 2020-04-27 21:08:05 | [diff] [blame] | 18 | #include "base/notreached.h" |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 19 | #include "base/run_loop.h" |
[email protected] | fc9be580 | 2013-06-11 10:56:51 | [diff] [blame] | 20 | #include "base/strings/string_number_conversions.h" |
[email protected] | 18b57741 | 2013-07-18 04:19:15 | [diff] [blame] | 21 | #include "base/strings/stringprintf.h" |
Patrick Monette | 643cdf6 | 2021-10-15 19:13:42 | [diff] [blame] | 22 | #include "base/task/single_thread_task_runner.h" |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 23 | #include "base/test/scoped_feature_list.h" |
[email protected] | f214f879 | 2011-01-01 02:17:08 | [diff] [blame] | 24 | #include "base/threading/platform_thread.h" |
Gabriel Charette | d87f10f | 2022-03-31 00:44:22 | [diff] [blame] | 25 | #include "base/time/time.h" |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 26 | #include "base/values.h" |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 27 | #include "net/base/features.h" |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 28 | #include "net/base/host_port_pair.h" |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 29 | #include "net/base/load_timing_info.h" |
[email protected] | b258e079 | 2013-01-12 07:11:59 | [diff] [blame] | 30 | #include "net/base/load_timing_info_test_util.h" |
[email protected] | d8eb8424 | 2010-09-25 02:25:06 | [diff] [blame] | 31 | #include "net/base/net_errors.h" |
Brianna Goldstein | a7593fca | 2022-09-28 02:59:32 | [diff] [blame] | 32 | #include "net/base/network_anonymization_key.h" |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 33 | #include "net/base/privacy_mode.h" |
Matt Menke | aafff54 | 2019-04-22 22:09:36 | [diff] [blame] | 34 | #include "net/base/proxy_server.h" |
Eric Orth | 5ccc3f0 | 2021-09-23 00:01:57 | [diff] [blame] | 35 | #include "net/base/proxy_string_util.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 36 | #include "net/base/request_priority.h" |
Matt Menke | 4807a9a | 2020-11-21 00:14:41 | [diff] [blame] | 37 | #include "net/base/schemeful_site.h" |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 38 | #include "net/base/test_completion_callback.h" |
dalyk | edd30d98 | 2019-12-16 15:31:10 | [diff] [blame] | 39 | #include "net/dns/public/resolve_error_info.h" |
Ben Schwartz | 3ff4dc1e6 | 2021-04-27 21:15:23 | [diff] [blame] | 40 | #include "net/dns/public/secure_dns_policy.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 41 | #include "net/http/http_response_headers.h" |
Matt Menke | 39b7c5a | 2019-04-10 19:47:51 | [diff] [blame] | 42 | #include "net/http/http_response_info.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 43 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 44 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 45 | #include "net/log/net_log_source.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 46 | #include "net/log/net_log_source_type.h" |
mmenke | 16a7cbdd | 2015-04-24 23:00:56 | [diff] [blame] | 47 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 48 | #include "net/log/test_net_log_util.h" |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 49 | #include "net/socket/client_socket_factory.h" |
| 50 | #include "net/socket/client_socket_handle.h" |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 51 | #include "net/socket/connect_job_factory.h" |
tfarina | 5dd13c2 | 2016-11-16 12:08:26 | [diff] [blame] | 52 | #include "net/socket/datagram_client_socket.h" |
tbansal | ca83c00 | 2016-04-28 20:56:28 | [diff] [blame] | 53 | #include "net/socket/socket_performance_watcher.h" |
Paul Jensen | 8d6f87ec | 2018-01-13 00:46:54 | [diff] [blame] | 54 | #include "net/socket/socket_tag.h" |
[email protected] | 75439d3b | 2009-07-23 22:11:17 | [diff] [blame] | 55 | #include "net/socket/socket_test_util.h" |
[email protected] | 18ccfdb | 2013-08-15 00:13:44 | [diff] [blame] | 56 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 3268023f | 2011-05-05 00:08:10 | [diff] [blame] | 57 | #include "net/socket/stream_socket.h" |
Daniel Cheng | 5feb16f | 2022-02-28 06:52:07 | [diff] [blame] | 58 | #include "net/socket/transport_client_socket_pool.h" |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 59 | #include "net/socket/transport_connect_job.h" |
Matt Menke | 39b7c5a | 2019-04-10 19:47:51 | [diff] [blame] | 60 | #include "net/ssl/ssl_cert_request_info.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 61 | #include "net/test/gtest_util.h" |
Gabriel Charette | c710874 | 2019-08-23 03:31:40 | [diff] [blame] | 62 | #include "net/test/test_with_task_environment.h" |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 63 | #include "net/traffic_annotation/network_traffic_annotation.h" |
Ramin Halavati | 0a08cc8 | 2018-02-06 07:46:38 | [diff] [blame] | 64 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
[email protected] | 51fdc7c | 2012-04-10 19:19:48 | [diff] [blame] | 65 | #include "testing/gmock/include/gmock/gmock.h" |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 66 | #include "testing/gtest/include/gtest/gtest.h" |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 67 | #include "third_party/abseil-cpp/absl/types/optional.h" |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 68 | #include "url/scheme_host_port.h" |
| 69 | #include "url/url_constants.h" |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 70 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 71 | using net::test::IsError; |
| 72 | using net::test::IsOk; |
| 73 | |
[email protected] | 51fdc7c | 2012-04-10 19:19:48 | [diff] [blame] | 74 | using ::testing::Invoke; |
| 75 | using ::testing::Return; |
| 76 | |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 77 | namespace net { |
| 78 | |
| 79 | namespace { |
| 80 | |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 81 | const int kDefaultMaxSockets = 4; |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 82 | const int kDefaultMaxSocketsPerGroup = 2; |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 83 | constexpr base::TimeDelta kUnusedIdleSocketTimeout = base::Seconds(10); |
[email protected] | 0b7648c | 2009-07-06 20:14:01 | [diff] [blame] | 84 | |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 85 | ClientSocketPool::GroupId TestGroupId( |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 86 | base::StringPiece host, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 87 | int port = 80, |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 88 | base::StringPiece scheme = url::kHttpScheme, |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 89 | PrivacyMode privacy_mode = PrivacyMode::PRIVACY_MODE_DISABLED, |
Brianna Goldstein | a7593fca | 2022-09-28 02:59:32 | [diff] [blame] | 90 | NetworkAnonymizationKey network_anonymization_key = |
| 91 | NetworkAnonymizationKey()) { |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 92 | return ClientSocketPool::GroupId(url::SchemeHostPort(scheme, host, port), |
Brianna Goldstein | a7593fca | 2022-09-28 02:59:32 | [diff] [blame] | 93 | privacy_mode, network_anonymization_key, |
Ben Schwartz | 3ff4dc1e6 | 2021-04-27 21:15:23 | [diff] [blame] | 94 | SecureDnsPolicy::kAllow); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 95 | } |
| 96 | |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 97 | // Make sure |handle| sets load times correctly when it has been assigned a |
| 98 | // reused socket. |
| 99 | void TestLoadTimingInfoConnectedReused(const ClientSocketHandle& handle) { |
| 100 | LoadTimingInfo load_timing_info; |
| 101 | // Only pass true in as |is_reused|, as in general, HttpStream types should |
| 102 | // have stricter concepts of reuse than socket pools. |
| 103 | EXPECT_TRUE(handle.GetLoadTimingInfo(true, &load_timing_info)); |
| 104 | |
| 105 | EXPECT_EQ(true, load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 106 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 107 | |
[email protected] | b258e079 | 2013-01-12 07:11:59 | [diff] [blame] | 108 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
| 109 | ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | // Make sure |handle| sets load times correctly when it has been assigned a |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 113 | // fresh socket. Also runs TestLoadTimingInfoConnectedReused, since the owner |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 114 | // of a connection where |is_reused| is false may consider the connection |
| 115 | // reused. |
| 116 | void TestLoadTimingInfoConnectedNotReused(const ClientSocketHandle& handle) { |
| 117 | EXPECT_FALSE(handle.is_reused()); |
| 118 | |
| 119 | LoadTimingInfo load_timing_info; |
| 120 | EXPECT_TRUE(handle.GetLoadTimingInfo(false, &load_timing_info)); |
| 121 | |
| 122 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 123 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 124 | |
[email protected] | b258e079 | 2013-01-12 07:11:59 | [diff] [blame] | 125 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 126 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 127 | ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 128 | |
| 129 | TestLoadTimingInfoConnectedReused(handle); |
| 130 | } |
| 131 | |
| 132 | // Make sure |handle| sets load times correctly, in the case that it does not |
| 133 | // currently have a socket. |
| 134 | void TestLoadTimingInfoNotConnected(const ClientSocketHandle& handle) { |
| 135 | // Should only be set to true once a socket is assigned, if at all. |
| 136 | EXPECT_FALSE(handle.is_reused()); |
| 137 | |
| 138 | LoadTimingInfo load_timing_info; |
| 139 | EXPECT_FALSE(handle.GetLoadTimingInfo(false, &load_timing_info)); |
| 140 | |
| 141 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 142 | EXPECT_EQ(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 143 | |
[email protected] | b258e079 | 2013-01-12 07:11:59 | [diff] [blame] | 144 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
| 145 | ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 146 | } |
| 147 | |
[email protected] | 3268023f | 2011-05-05 00:08:10 | [diff] [blame] | 148 | class MockClientSocket : public StreamSocket { |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 149 | public: |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 150 | explicit MockClientSocket(net::NetLog* net_log) |
Tsuyoshi Horo | 2ec06e00 | 2022-06-09 01:38:59 | [diff] [blame] | 151 | : net_log_(NetLogWithSource::Make(net_log, NetLogSourceType::SOCKET)) {} |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 152 | |
Peter Boström | 407869b | 2021-10-07 04:42:48 | [diff] [blame] | 153 | MockClientSocket(const MockClientSocket&) = delete; |
| 154 | MockClientSocket& operator=(const MockClientSocket&) = delete; |
| 155 | |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 156 | // Sets whether the socket has unread data. If true, the next call to Read() |
| 157 | // will return 1 byte and IsConnectedAndIdle() will return false. |
| 158 | void set_has_unread_data(bool has_unread_data) { |
| 159 | has_unread_data_ = has_unread_data; |
| 160 | } |
| 161 | |
[email protected] | 3f55aa1 | 2011-12-07 02:03:33 | [diff] [blame] | 162 | // Socket implementation. |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 163 | int Read(IOBuffer* /* buf */, |
| 164 | int len, |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 165 | CompletionOnceCallback /* callback */) override { |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 166 | if (has_unread_data_ && len > 0) { |
| 167 | has_unread_data_ = false; |
| 168 | was_used_to_convey_data_ = true; |
| 169 | return 1; |
| 170 | } |
[email protected] | e86df8dc | 2013-03-30 13:18:28 | [diff] [blame] | 171 | return ERR_UNEXPECTED; |
[email protected] | 3f55aa1 | 2011-12-07 02:03:33 | [diff] [blame] | 172 | } |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 173 | |
[email protected] | a2b2cfc | 2017-12-06 09:06:08 | [diff] [blame] | 174 | int Write( |
| 175 | IOBuffer* /* buf */, |
| 176 | int len, |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 177 | CompletionOnceCallback /* callback */, |
[email protected] | a2b2cfc | 2017-12-06 09:06:08 | [diff] [blame] | 178 | const NetworkTrafficAnnotationTag& /*traffic_annotation*/) override { |
[email protected] | 0f873e8 | 2010-09-02 16:09:01 | [diff] [blame] | 179 | was_used_to_convey_data_ = true; |
| 180 | return len; |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 181 | } |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 182 | int SetReceiveBufferSize(int32_t size) override { return OK; } |
| 183 | int SetSendBufferSize(int32_t size) override { return OK; } |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 184 | |
[email protected] | dbf036f | 2011-12-06 23:33:24 | [diff] [blame] | 185 | // StreamSocket implementation. |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 186 | int Connect(CompletionOnceCallback callback) override { |
[email protected] | dbf036f | 2011-12-06 23:33:24 | [diff] [blame] | 187 | connected_ = true; |
| 188 | return OK; |
| 189 | } |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 190 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 191 | void Disconnect() override { connected_ = false; } |
| 192 | bool IsConnected() const override { return connected_; } |
| 193 | bool IsConnectedAndIdle() const override { |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 194 | return connected_ && !has_unread_data_; |
| 195 | } |
[email protected] | 0b7648c | 2009-07-06 20:14:01 | [diff] [blame] | 196 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 197 | int GetPeerAddress(IPEndPoint* /* address */) const override { |
[email protected] | 9f864b3 | 2010-01-20 15:01:16 | [diff] [blame] | 198 | return ERR_UNEXPECTED; |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 199 | } |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 200 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 201 | int GetLocalAddress(IPEndPoint* /* address */) const override { |
[email protected] | e7f74da | 2011-04-19 23:49:35 | [diff] [blame] | 202 | return ERR_UNEXPECTED; |
| 203 | } |
| 204 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 205 | const NetLogWithSource& NetLog() const override { return net_log_; } |
[email protected] | a2006ece | 2010-04-23 16:44:02 | [diff] [blame] | 206 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 207 | bool WasEverUsed() const override { return was_used_to_convey_data_; } |
tfarina | 2846404c | 2016-12-25 14:31:37 | [diff] [blame] | 208 | bool WasAlpnNegotiated() const override { return false; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 209 | NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; } |
| 210 | bool GetSSLInfo(SSLInfo* ssl_info) override { return false; } |
tbansal | f82cc8e | 2015-10-14 20:05:49 | [diff] [blame] | 211 | int64_t GetTotalReceivedBytes() const override { |
| 212 | NOTIMPLEMENTED(); |
| 213 | return 0; |
| 214 | } |
Paul Jensen | 0f49dec | 2017-12-12 23:39:58 | [diff] [blame] | 215 | void ApplySocketTag(const SocketTag& tag) override {} |
[email protected] | 9b5614a | 2010-08-25 20:29:45 | [diff] [blame] | 216 | |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 217 | private: |
Tsuyoshi Horo | 2ec06e00 | 2022-06-09 01:38:59 | [diff] [blame] | 218 | bool connected_ = false; |
| 219 | bool has_unread_data_ = false; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 220 | NetLogWithSource net_log_; |
Tsuyoshi Horo | 2ec06e00 | 2022-06-09 01:38:59 | [diff] [blame] | 221 | bool was_used_to_convey_data_ = false; |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 222 | }; |
| 223 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 224 | class TestConnectJob; |
| 225 | |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 226 | class MockClientSocketFactory : public ClientSocketFactory { |
| 227 | public: |
Tsuyoshi Horo | 2ec06e00 | 2022-06-09 01:38:59 | [diff] [blame] | 228 | MockClientSocketFactory() = default; |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 229 | |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 230 | std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket( |
[email protected] | 5370c01 | 2011-06-29 03:47:04 | [diff] [blame] | 231 | DatagramSocket::BindType bind_type, |
[email protected] | 98b0e58 | 2011-06-22 14:31:41 | [diff] [blame] | 232 | NetLog* net_log, |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 233 | const NetLogSource& source) override { |
[email protected] | 98b0e58 | 2011-06-22 14:31:41 | [diff] [blame] | 234 | NOTREACHED(); |
David Benjamin | 24725be | 2019-07-24 20:57:18 | [diff] [blame] | 235 | return nullptr; |
[email protected] | 98b0e58 | 2011-06-22 14:31:41 | [diff] [blame] | 236 | } |
| 237 | |
Helen Li | d5bb922 | 2018-04-12 15:33:09 | [diff] [blame] | 238 | std::unique_ptr<TransportClientSocket> CreateTransportClientSocket( |
[email protected] | 0a0b768 | 2010-08-25 17:08:07 | [diff] [blame] | 239 | const AddressList& addresses, |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 240 | std::unique_ptr< |
| 241 | SocketPerformanceWatcher> /* socket_performance_watcher */, |
Eric Roman | 2bc7716 | 2020-09-16 18:30:45 | [diff] [blame] | 242 | NetworkQualityEstimator* /* network_quality_estimator */, |
[email protected] | 0a0b768 | 2010-08-25 17:08:07 | [diff] [blame] | 243 | NetLog* /* net_log */, |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 244 | const NetLogSource& /*source*/) override { |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 245 | allocation_count_++; |
Helen Li | d5bb922 | 2018-04-12 15:33:09 | [diff] [blame] | 246 | return nullptr; |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 247 | } |
| 248 | |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 249 | std::unique_ptr<SSLClientSocket> CreateSSLClientSocket( |
David Benjamin | 24725be | 2019-07-24 20:57:18 | [diff] [blame] | 250 | SSLClientContext* context, |
Matt Menke | 841fc41 | 2019-03-05 23:20:12 | [diff] [blame] | 251 | std::unique_ptr<StreamSocket> stream_socket, |
[email protected] | 4f4de7e6 | 2010-11-12 19:55:27 | [diff] [blame] | 252 | const HostPortPair& host_and_port, |
David Benjamin | 24725be | 2019-07-24 20:57:18 | [diff] [blame] | 253 | const SSLConfig& ssl_config) override { |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 254 | NOTIMPLEMENTED(); |
David Benjamin | 24725be | 2019-07-24 20:57:18 | [diff] [blame] | 255 | return nullptr; |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 256 | } |
Matt Menke | fd95692 | 2019-02-04 23:44:03 | [diff] [blame] | 257 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 258 | void WaitForSignal(TestConnectJob* job) { waiting_jobs_.push_back(job); } |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 259 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 260 | void SignalJobs(); |
| 261 | |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 262 | void SignalJob(size_t job); |
| 263 | |
| 264 | void SetJobLoadState(size_t job, LoadState load_state); |
| 265 | |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 266 | // Sets the HasConnectionEstablished value of the specified job to true, |
| 267 | // without invoking the callback. |
| 268 | void SetJobHasEstablishedConnection(size_t job); |
| 269 | |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 270 | int allocation_count() const { return allocation_count_; } |
| 271 | |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 272 | private: |
Tsuyoshi Horo | 2ec06e00 | 2022-06-09 01:38:59 | [diff] [blame] | 273 | int allocation_count_ = 0; |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 274 | std::vector<TestConnectJob*> waiting_jobs_; |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 275 | }; |
| 276 | |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 277 | class TestConnectJob : public ConnectJob { |
| 278 | public: |
| 279 | enum JobType { |
| 280 | kMockJob, |
| 281 | kMockFailingJob, |
| 282 | kMockPendingJob, |
| 283 | kMockPendingFailingJob, |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 284 | kMockWaitingJob, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 285 | |
| 286 | // Certificate errors return a socket in addition to an error code. |
| 287 | kMockCertErrorJob, |
| 288 | kMockPendingCertErrorJob, |
| 289 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 290 | kMockAdditionalErrorStateJob, |
| 291 | kMockPendingAdditionalErrorStateJob, |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 292 | kMockUnreadDataJob, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 293 | |
| 294 | kMockAuthChallengeOnceJob, |
| 295 | kMockAuthChallengeTwiceJob, |
| 296 | kMockAuthChallengeOnceFailingJob, |
| 297 | kMockAuthChallengeTwiceFailingJob, |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 298 | }; |
| 299 | |
[email protected] | 994d493 | 2010-07-12 17:55:13 | [diff] [blame] | 300 | // The kMockPendingJob uses a slight delay before allowing the connect |
| 301 | // to complete. |
| 302 | static const int kPendingConnectDelay = 2; |
| 303 | |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 304 | TestConnectJob(JobType job_type, |
Matt Menke | 16f5c2e5 | 2019-03-25 21:50:40 | [diff] [blame] | 305 | RequestPriority request_priority, |
| 306 | SocketTag socket_tag, |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 307 | base::TimeDelta timeout_duration, |
Matt Menke | a6f99ad | 2019-03-08 02:26:43 | [diff] [blame] | 308 | const CommonConnectJobParams* common_connect_job_params, |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 309 | ConnectJob::Delegate* delegate, |
Matt Menke | a6f99ad | 2019-03-08 02:26:43 | [diff] [blame] | 310 | MockClientSocketFactory* client_socket_factory) |
Matt Menke | 16f5c2e5 | 2019-03-25 21:50:40 | [diff] [blame] | 311 | : ConnectJob(request_priority, |
| 312 | socket_tag, |
Matt Menke | 1a6c92d | 2019-02-23 00:25:38 | [diff] [blame] | 313 | timeout_duration, |
Matt Menke | a6f99ad | 2019-03-08 02:26:43 | [diff] [blame] | 314 | common_connect_job_params, |
Matt Menke | 1a6c92d | 2019-02-23 00:25:38 | [diff] [blame] | 315 | delegate, |
| 316 | nullptr /* net_log */, |
| 317 | NetLogSourceType::TRANSPORT_CONNECT_JOB, |
| 318 | NetLogEventType::TRANSPORT_CONNECT_JOB_CONNECT), |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 319 | job_type_(job_type), |
Tsuyoshi Horo | 2ec06e00 | 2022-06-09 01:38:59 | [diff] [blame] | 320 | client_socket_factory_(client_socket_factory) {} |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 321 | |
Peter Boström | 407869b | 2021-10-07 04:42:48 | [diff] [blame] | 322 | TestConnectJob(const TestConnectJob&) = delete; |
| 323 | TestConnectJob& operator=(const TestConnectJob&) = delete; |
| 324 | |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 325 | void Signal() { |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 326 | DoConnect(waiting_success_, true /* async */, false /* recoverable */); |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 327 | } |
| 328 | |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 329 | void set_load_state(LoadState load_state) { load_state_ = load_state; } |
| 330 | |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 331 | void set_has_established_connection() { |
| 332 | DCHECK(!has_established_connection_); |
| 333 | has_established_connection_ = true; |
| 334 | } |
| 335 | |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 336 | // From ConnectJob: |
| 337 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 338 | LoadState GetLoadState() const override { return load_state_; } |
[email protected] | 4645135 | 2009-09-01 14:54:21 | [diff] [blame] | 339 | |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 340 | bool HasEstablishedConnection() const override { |
| 341 | return has_established_connection_; |
| 342 | } |
| 343 | |
dalyk | edd30d98 | 2019-12-16 15:31:10 | [diff] [blame] | 344 | ResolveErrorInfo GetResolveErrorInfo() const override { |
| 345 | return ResolveErrorInfo(OK); |
| 346 | } |
| 347 | |
Matt Menke | 6f84d1f1 | 2019-04-11 19:26:47 | [diff] [blame] | 348 | bool IsSSLError() const override { return store_additional_error_state_; } |
| 349 | |
| 350 | scoped_refptr<SSLCertRequestInfo> GetCertRequestInfo() override { |
| 351 | if (store_additional_error_state_) |
| 352 | return base::MakeRefCounted<SSLCertRequestInfo>(); |
| 353 | return nullptr; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 354 | } |
| 355 | |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 356 | private: |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 357 | // From ConnectJob: |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 358 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 359 | int ConnectInternal() override { |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 360 | AddressList ignored; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 361 | client_socket_factory_->CreateTransportClientSocket( |
Eric Roman | 2bc7716 | 2020-09-16 18:30:45 | [diff] [blame] | 362 | ignored, nullptr, nullptr, nullptr, NetLogSource()); |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 363 | switch (job_type_) { |
| 364 | case kMockJob: |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 365 | return DoConnect(true /* successful */, false /* sync */, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 366 | false /* cert_error */); |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 367 | case kMockFailingJob: |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 368 | return DoConnect(false /* error */, false /* sync */, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 369 | false /* cert_error */); |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 370 | case kMockPendingJob: |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 371 | set_load_state(LOAD_STATE_CONNECTING); |
[email protected] | 6b17538 | 2009-10-13 06:47:47 | [diff] [blame] | 372 | |
| 373 | // Depending on execution timings, posting a delayed task can result |
| 374 | // in the task getting executed the at the earliest possible |
| 375 | // opportunity or only after returning once from the message loop and |
| 376 | // then a second call into the message loop. In order to make behavior |
| 377 | // more deterministic, we change the default delay to 2ms. This should |
| 378 | // always require us to wait for the second call into the message loop. |
| 379 | // |
| 380 | // N.B. The correct fix for this and similar timing problems is to |
| 381 | // abstract time for the purpose of unittests. Unfortunately, we have |
| 382 | // a lot of third-party components that directly call the various |
| 383 | // time functions, so this change would be rather invasive. |
Sean Maher | 5b9af51f | 2022-11-21 15:32:47 | [diff] [blame] | 384 | base::SingleThreadTaskRunner::GetCurrentDefault()->PostDelayedTask( |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 385 | FROM_HERE, |
kylechar | f4fe517 | 2019-02-15 18:53:49 | [diff] [blame] | 386 | base::BindOnce(base::IgnoreResult(&TestConnectJob::DoConnect), |
| 387 | weak_factory_.GetWeakPtr(), true /* successful */, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 388 | true /* async */, false /* cert_error */), |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 389 | base::Milliseconds(kPendingConnectDelay)); |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 390 | return ERR_IO_PENDING; |
| 391 | case kMockPendingFailingJob: |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 392 | set_load_state(LOAD_STATE_CONNECTING); |
Sean Maher | 5b9af51f | 2022-11-21 15:32:47 | [diff] [blame] | 393 | base::SingleThreadTaskRunner::GetCurrentDefault()->PostDelayedTask( |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 394 | FROM_HERE, |
kylechar | f4fe517 | 2019-02-15 18:53:49 | [diff] [blame] | 395 | base::BindOnce(base::IgnoreResult(&TestConnectJob::DoConnect), |
| 396 | weak_factory_.GetWeakPtr(), false /* error */, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 397 | true /* async */, false /* cert_error */), |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 398 | base::Milliseconds(2)); |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 399 | return ERR_IO_PENDING; |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 400 | case kMockWaitingJob: |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 401 | set_load_state(LOAD_STATE_CONNECTING); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 402 | client_socket_factory_->WaitForSignal(this); |
| 403 | waiting_success_ = true; |
| 404 | return ERR_IO_PENDING; |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 405 | case kMockCertErrorJob: |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 406 | return DoConnect(false /* error */, false /* sync */, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 407 | true /* cert_error */); |
| 408 | case kMockPendingCertErrorJob: |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 409 | set_load_state(LOAD_STATE_CONNECTING); |
Sean Maher | 5b9af51f | 2022-11-21 15:32:47 | [diff] [blame] | 410 | base::SingleThreadTaskRunner::GetCurrentDefault()->PostDelayedTask( |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 411 | FROM_HERE, |
kylechar | f4fe517 | 2019-02-15 18:53:49 | [diff] [blame] | 412 | base::BindOnce(base::IgnoreResult(&TestConnectJob::DoConnect), |
| 413 | weak_factory_.GetWeakPtr(), false /* error */, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 414 | true /* async */, true /* cert_error */), |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 415 | base::Milliseconds(2)); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 416 | return ERR_IO_PENDING; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 417 | case kMockAdditionalErrorStateJob: |
| 418 | store_additional_error_state_ = true; |
| 419 | return DoConnect(false /* error */, false /* sync */, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 420 | false /* cert_error */); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 421 | case kMockPendingAdditionalErrorStateJob: |
| 422 | set_load_state(LOAD_STATE_CONNECTING); |
| 423 | store_additional_error_state_ = true; |
Sean Maher | 5b9af51f | 2022-11-21 15:32:47 | [diff] [blame] | 424 | base::SingleThreadTaskRunner::GetCurrentDefault()->PostDelayedTask( |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 425 | FROM_HERE, |
kylechar | f4fe517 | 2019-02-15 18:53:49 | [diff] [blame] | 426 | base::BindOnce(base::IgnoreResult(&TestConnectJob::DoConnect), |
| 427 | weak_factory_.GetWeakPtr(), false /* error */, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 428 | true /* async */, false /* cert_error */), |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 429 | base::Milliseconds(2)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 430 | return ERR_IO_PENDING; |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 431 | case kMockUnreadDataJob: { |
| 432 | int ret = DoConnect(true /* successful */, false /* sync */, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 433 | false /* cert_error */); |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 434 | static_cast<MockClientSocket*>(socket())->set_has_unread_data(true); |
| 435 | return ret; |
| 436 | } |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 437 | case kMockAuthChallengeOnceJob: |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 438 | set_load_state(LOAD_STATE_CONNECTING); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 439 | DoAdvanceAuthChallenge(1, true /* succeed_after_last_challenge */); |
| 440 | return ERR_IO_PENDING; |
| 441 | case kMockAuthChallengeTwiceJob: |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 442 | set_load_state(LOAD_STATE_CONNECTING); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 443 | DoAdvanceAuthChallenge(2, true /* succeed_after_last_challenge */); |
| 444 | return ERR_IO_PENDING; |
| 445 | case kMockAuthChallengeOnceFailingJob: |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 446 | set_load_state(LOAD_STATE_CONNECTING); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 447 | DoAdvanceAuthChallenge(1, false /* succeed_after_last_challenge */); |
| 448 | return ERR_IO_PENDING; |
| 449 | case kMockAuthChallengeTwiceFailingJob: |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 450 | set_load_state(LOAD_STATE_CONNECTING); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 451 | DoAdvanceAuthChallenge(2, false /* succeed_after_last_challenge */); |
| 452 | return ERR_IO_PENDING; |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 453 | default: |
| 454 | NOTREACHED(); |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 455 | SetSocket(std::unique_ptr<StreamSocket>(), absl::nullopt); |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 456 | return ERR_FAILED; |
| 457 | } |
| 458 | } |
| 459 | |
Lily Chen | 02ef29a | 2018-11-30 16:31:43 | [diff] [blame] | 460 | void ChangePriorityInternal(RequestPriority priority) override {} |
| 461 | |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 462 | int DoConnect(bool succeed, bool was_async, bool cert_error) { |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 463 | int result = OK; |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 464 | has_established_connection_ = true; |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 465 | if (succeed) { |
Cammie Smith Barnes | aa2a8b5 | 2020-12-17 19:33:19 | [diff] [blame] | 466 | SetSocket(std::make_unique<MockClientSocket>(net_log().net_log()), |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 467 | absl::nullopt); |
Bence Béky | bdbb0e7 | 2018-08-07 21:42:59 | [diff] [blame] | 468 | socket()->Connect(CompletionOnceCallback()); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 469 | } else if (cert_error) { |
Cammie Smith Barnes | aa2a8b5 | 2020-12-17 19:33:19 | [diff] [blame] | 470 | SetSocket(std::make_unique<MockClientSocket>(net_log().net_log()), |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 471 | absl::nullopt); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 472 | result = ERR_CERT_COMMON_NAME_INVALID; |
[email protected] | 6e713f0 | 2009-08-06 02:56:40 | [diff] [blame] | 473 | } else { |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 474 | result = ERR_CONNECTION_FAILED; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 475 | SetSocket(std::unique_ptr<StreamSocket>(), absl::nullopt); |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 476 | } |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 477 | |
| 478 | if (was_async) |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 479 | NotifyDelegateOfCompletion(result); |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 480 | return result; |
| 481 | } |
| 482 | |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 483 | void DoAdvanceAuthChallenge(int remaining_challenges, |
| 484 | bool succeed_after_last_challenge) { |
Sean Maher | 5b9af51f | 2022-11-21 15:32:47 | [diff] [blame] | 485 | base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask( |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 486 | FROM_HERE, |
| 487 | base::BindOnce(&TestConnectJob::InvokeNextProxyAuthCallback, |
| 488 | weak_factory_.GetWeakPtr(), remaining_challenges, |
| 489 | succeed_after_last_challenge)); |
| 490 | } |
| 491 | |
| 492 | void InvokeNextProxyAuthCallback(int remaining_challenges, |
| 493 | bool succeed_after_last_challenge) { |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 494 | set_load_state(LOAD_STATE_ESTABLISHING_PROXY_TUNNEL); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 495 | if (remaining_challenges == 0) { |
| 496 | DoConnect(succeed_after_last_challenge, true /* was_async */, |
| 497 | false /* cert_error */); |
| 498 | return; |
| 499 | } |
| 500 | |
| 501 | // Integration tests make sure HttpResponseInfo and HttpAuthController work. |
| 502 | // The auth tests here are just focused on ConnectJob bookkeeping. |
| 503 | HttpResponseInfo info; |
| 504 | NotifyDelegateOfProxyAuth( |
| 505 | info, nullptr /* http_auth_controller */, |
| 506 | base::BindOnce(&TestConnectJob::DoAdvanceAuthChallenge, |
| 507 | weak_factory_.GetWeakPtr(), remaining_challenges - 1, |
| 508 | succeed_after_last_challenge)); |
| 509 | } |
| 510 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 511 | bool waiting_success_; |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 512 | const JobType job_type_; |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 513 | const raw_ptr<MockClientSocketFactory> client_socket_factory_; |
Tsuyoshi Horo | 2ec06e00 | 2022-06-09 01:38:59 | [diff] [blame] | 514 | LoadState load_state_ = LOAD_STATE_IDLE; |
| 515 | bool has_established_connection_ = false; |
| 516 | bool store_additional_error_state_ = false; |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 517 | |
Jeremy Roman | d54000b2 | 2019-07-08 18:40:16 | [diff] [blame] | 518 | base::WeakPtrFactory<TestConnectJob> weak_factory_{this}; |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 519 | }; |
| 520 | |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 521 | class TestConnectJobFactory : public ConnectJobFactory { |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 522 | public: |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 523 | explicit TestConnectJobFactory(MockClientSocketFactory* client_socket_factory) |
| 524 | : client_socket_factory_(client_socket_factory) {} |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 525 | |
Peter Boström | 293b134 | 2021-09-22 17:31:43 | [diff] [blame] | 526 | TestConnectJobFactory(const TestConnectJobFactory&) = delete; |
| 527 | TestConnectJobFactory& operator=(const TestConnectJobFactory&) = delete; |
| 528 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 529 | ~TestConnectJobFactory() override = default; |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 530 | |
| 531 | void set_job_type(TestConnectJob::JobType job_type) { job_type_ = job_type; } |
| 532 | |
[email protected] | 51fdc7c | 2012-04-10 19:19:48 | [diff] [blame] | 533 | void set_job_types(std::list<TestConnectJob::JobType>* job_types) { |
| 534 | job_types_ = job_types; |
| 535 | CHECK(!job_types_->empty()); |
| 536 | } |
| 537 | |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 538 | void set_timeout_duration(base::TimeDelta timeout_duration) { |
| 539 | timeout_duration_ = timeout_duration; |
| 540 | } |
| 541 | |
[email protected] | 3f55aa1 | 2011-12-07 02:03:33 | [diff] [blame] | 542 | // ConnectJobFactory implementation. |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 543 | |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 544 | std::unique_ptr<ConnectJob> CreateConnectJob( |
Eric Orth | c98a3e6 | 2021-07-02 17:46:37 | [diff] [blame] | 545 | Endpoint endpoint, |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 546 | const ProxyServer& proxy_server, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 547 | const absl::optional<NetworkTrafficAnnotationTag>& proxy_annotation_tag, |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 548 | const SSLConfig* ssl_config_for_origin, |
| 549 | const SSLConfig* ssl_config_for_proxy, |
| 550 | bool force_tunnel, |
| 551 | PrivacyMode privacy_mode, |
| 552 | const OnHostResolutionCallback& resolution_callback, |
Matt Menke | 16f5c2e5 | 2019-03-25 21:50:40 | [diff] [blame] | 553 | RequestPriority request_priority, |
| 554 | SocketTag socket_tag, |
Brianna Goldstein | abb3aac | 2022-10-07 12:06:00 | [diff] [blame] | 555 | const NetworkAnonymizationKey& network_anonymization_key, |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 556 | SecureDnsPolicy secure_dns_policy, |
| 557 | const CommonConnectJobParams* common_connect_job_params, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 558 | ConnectJob::Delegate* delegate) const override { |
[email protected] | 51fdc7c | 2012-04-10 19:19:48 | [diff] [blame] | 559 | EXPECT_TRUE(!job_types_ || !job_types_->empty()); |
| 560 | TestConnectJob::JobType job_type = job_type_; |
| 561 | if (job_types_ && !job_types_->empty()) { |
| 562 | job_type = job_types_->front(); |
| 563 | job_types_->pop_front(); |
| 564 | } |
Matt Menke | a6f99ad | 2019-03-08 02:26:43 | [diff] [blame] | 565 | return std::make_unique<TestConnectJob>( |
Matt Menke | 16f5c2e5 | 2019-03-25 21:50:40 | [diff] [blame] | 566 | job_type, request_priority, socket_tag, timeout_duration_, |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 567 | common_connect_job_params, delegate, client_socket_factory_); |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | private: |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 571 | TestConnectJob::JobType job_type_ = TestConnectJob::kMockJob; |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 572 | raw_ptr<std::list<TestConnectJob::JobType>> job_types_ = nullptr; |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 573 | base::TimeDelta timeout_duration_; |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 574 | const raw_ptr<MockClientSocketFactory> client_socket_factory_; |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 575 | }; |
| 576 | |
[email protected] | a937a06d | 2009-08-19 21:19:24 | [diff] [blame] | 577 | } // namespace |
| 578 | |
[email protected] | a937a06d | 2009-08-19 21:19:24 | [diff] [blame] | 579 | namespace { |
| 580 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 581 | void MockClientSocketFactory::SignalJobs() { |
Tsuyoshi Horo | 17ef47d0 | 2022-06-30 10:58:27 | [diff] [blame] | 582 | for (auto* waiting_job : waiting_jobs_) { |
| 583 | waiting_job->Signal(); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 584 | } |
| 585 | waiting_jobs_.clear(); |
| 586 | } |
| 587 | |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 588 | void MockClientSocketFactory::SignalJob(size_t job) { |
| 589 | ASSERT_LT(job, waiting_jobs_.size()); |
| 590 | waiting_jobs_[job]->Signal(); |
| 591 | waiting_jobs_.erase(waiting_jobs_.begin() + job); |
| 592 | } |
| 593 | |
| 594 | void MockClientSocketFactory::SetJobLoadState(size_t job, |
| 595 | LoadState load_state) { |
| 596 | ASSERT_LT(job, waiting_jobs_.size()); |
| 597 | waiting_jobs_[job]->set_load_state(load_state); |
| 598 | } |
| 599 | |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 600 | void MockClientSocketFactory::SetJobHasEstablishedConnection(size_t job) { |
| 601 | ASSERT_LT(job, waiting_jobs_.size()); |
| 602 | waiting_jobs_[job]->set_has_established_connection(); |
| 603 | } |
| 604 | |
Gabriel Charette | 694c3c33 | 2019-08-19 14:53:05 | [diff] [blame] | 605 | class ClientSocketPoolBaseTest : public TestWithTaskEnvironment { |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 606 | protected: |
Alex Clarke | 0def209 | 2018-12-10 12:01:45 | [diff] [blame] | 607 | ClientSocketPoolBaseTest() |
Gabriel Charette | 694c3c33 | 2019-08-19 14:53:05 | [diff] [blame] | 608 | : TestWithTaskEnvironment( |
| 609 | base::test::TaskEnvironment::TimeSource::MOCK_TIME), |
Matt Menke | 870e19ab | 2019-04-23 16:23:03 | [diff] [blame] | 610 | params_(ClientSocketPool::SocketParams::CreateForHttpForTesting()) { |
[email protected] | 636b825 | 2011-04-08 19:56:54 | [diff] [blame] | 611 | connect_backup_jobs_enabled_ = |
Matt Menke | 16f5c2e5 | 2019-03-25 21:50:40 | [diff] [blame] | 612 | TransportClientSocketPool::connect_backup_jobs_enabled(); |
| 613 | TransportClientSocketPool::set_connect_backup_jobs_enabled(true); |
[email protected] | 636b825 | 2011-04-08 19:56:54 | [diff] [blame] | 614 | } |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 615 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 616 | ~ClientSocketPoolBaseTest() override { |
Matt Menke | 16f5c2e5 | 2019-03-25 21:50:40 | [diff] [blame] | 617 | TransportClientSocketPool::set_connect_backup_jobs_enabled( |
[email protected] | 636b825 | 2011-04-08 19:56:54 | [diff] [blame] | 618 | connect_backup_jobs_enabled_); |
| 619 | } |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 620 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 621 | void CreatePool(int max_sockets, |
| 622 | int max_sockets_per_group, |
| 623 | bool enable_backup_connect_jobs = false) { |
Tarun Bansal | a763509 | 2019-02-20 10:00:59 | [diff] [blame] | 624 | CreatePoolWithIdleTimeouts(max_sockets, max_sockets_per_group, |
| 625 | kUnusedIdleSocketTimeout, |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 626 | ClientSocketPool::used_idle_socket_timeout(), |
| 627 | enable_backup_connect_jobs); |
[email protected] | 9bf28db | 2009-08-29 01:35:16 | [diff] [blame] | 628 | } |
| 629 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 630 | void CreatePoolWithIdleTimeouts( |
| 631 | int max_sockets, |
| 632 | int max_sockets_per_group, |
| 633 | base::TimeDelta unused_idle_socket_timeout, |
| 634 | base::TimeDelta used_idle_socket_timeout, |
| 635 | bool enable_backup_connect_jobs = false, |
| 636 | ProxyServer proxy_server = ProxyServer::Direct()) { |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 637 | DCHECK(!pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 638 | std::unique_ptr<TestConnectJobFactory> connect_job_factory = |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 639 | std::make_unique<TestConnectJobFactory>(&client_socket_factory_); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 640 | connect_job_factory_ = connect_job_factory.get(); |
| 641 | pool_ = TransportClientSocketPool::CreateForTesting( |
| 642 | max_sockets, max_sockets_per_group, unused_idle_socket_timeout, |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 643 | used_idle_socket_timeout, proxy_server, /*is_for_websockets=*/false, |
| 644 | &common_connect_job_params_, std::move(connect_job_factory), |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 645 | nullptr /* ssl_config_service */, enable_backup_connect_jobs); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 646 | } |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 647 | |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 648 | int StartRequestWithIgnoreLimits( |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 649 | const ClientSocketPool::GroupId& group_id, |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 650 | RequestPriority priority, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 651 | ClientSocketPool::RespectLimits respect_limits) { |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 652 | return test_base_.StartRequestUsingPool(pool_.get(), group_id, priority, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 653 | respect_limits, params_); |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 654 | } |
| 655 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 656 | int StartRequest(const ClientSocketPool::GroupId& group_id, |
| 657 | RequestPriority priority) { |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 658 | return StartRequestWithIgnoreLimits( |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 659 | group_id, priority, ClientSocketPool::RespectLimits::ENABLED); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 660 | } |
| 661 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 662 | int GetOrderOfRequest(size_t index) const { |
| 663 | return test_base_.GetOrderOfRequest(index); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 664 | } |
| 665 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 666 | bool ReleaseOneConnection(ClientSocketPoolTest::KeepAlive keep_alive) { |
| 667 | return test_base_.ReleaseOneConnection(keep_alive); |
| 668 | } |
| 669 | |
| 670 | void ReleaseAllConnections(ClientSocketPoolTest::KeepAlive keep_alive) { |
| 671 | test_base_.ReleaseAllConnections(keep_alive); |
| 672 | } |
| 673 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 674 | // Expects a single NetLogEventType::SOCKET_POOL_CLOSING_SOCKET in |net_log_|. |
| 675 | // It should be logged for the provided source and have the indicated reason. |
| 676 | void ExpectSocketClosedWithReason(NetLogSource expected_source, |
| 677 | const char* expected_reason) { |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 678 | auto entries = net_log_observer_.GetEntriesForSourceWithType( |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 679 | expected_source, NetLogEventType::SOCKET_POOL_CLOSING_SOCKET, |
| 680 | NetLogEventPhase::NONE); |
| 681 | ASSERT_EQ(1u, entries.size()); |
| 682 | ASSERT_TRUE(entries[0].HasParams()); |
| 683 | ASSERT_TRUE(entries[0].params.is_dict()); |
Matt Menke | ca721da | 2022-06-01 04:47:29 | [diff] [blame] | 684 | const std::string* reason = |
| 685 | entries[0].params.GetDict().FindString("reason"); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 686 | ASSERT_TRUE(reason); |
| 687 | EXPECT_EQ(expected_reason, *reason); |
| 688 | } |
| 689 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 690 | TestSocketRequest* request(int i) { return test_base_.request(i); } |
| 691 | size_t requests_size() const { return test_base_.requests_size(); } |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 692 | std::vector<std::unique_ptr<TestSocketRequest>>* requests() { |
olli.raula | 9d66b7d | 2015-11-23 08:30:42 | [diff] [blame] | 693 | return test_base_.requests(); |
| 694 | } |
rdsmith | 29dbad1 | 2017-02-17 02:22:18 | [diff] [blame] | 695 | // Only counts the requests that get sockets asynchronously; |
| 696 | // synchronous completions are not registered by this count. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 697 | size_t completion_count() const { return test_base_.completion_count(); } |
| 698 | |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 699 | const CommonConnectJobParams common_connect_job_params_{ |
| 700 | nullptr /* client_socket_factory */, |
| 701 | nullptr /* host_resolver */, |
| 702 | nullptr /* http_auth_cache */, |
| 703 | nullptr /* http_auth_handler_factory */, |
| 704 | nullptr /* spdy_session_pool */, |
| 705 | nullptr /* quic_supported_versions */, |
| 706 | nullptr /* quic_stream_factory */, |
| 707 | nullptr /* proxy_delegate */, |
| 708 | nullptr /* http_user_agent_settings */, |
| 709 | nullptr /* ssl_client_context */, |
| 710 | nullptr /* socket_performance_watcher_factory */, |
| 711 | nullptr /* network_quality_estimator */, |
Matt Reichhoff | 36a1fd6 | 2021-10-12 22:52:20 | [diff] [blame] | 712 | NetLog::Get(), |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 713 | nullptr /* websocket_endpoint_lock_manager */}; |
[email protected] | 636b825 | 2011-04-08 19:56:54 | [diff] [blame] | 714 | bool connect_backup_jobs_enabled_; |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 715 | MockClientSocketFactory client_socket_factory_; |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 716 | RecordingNetLogObserver net_log_observer_; |
Tom Sepez | 5bb7697a | 2023-01-16 20:48:52 | [diff] [blame] | 717 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 718 | // These parameters are never actually used to create a TransportConnectJob. |
Matt Menke | 84d11e56 | 2019-03-27 00:11:19 | [diff] [blame] | 719 | scoped_refptr<ClientSocketPool::SocketParams> params_; |
Tom Sepez | 5bb7697a | 2023-01-16 20:48:52 | [diff] [blame] | 720 | |
| 721 | // Must outlive `connect_job_factory_` |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 722 | std::unique_ptr<TransportClientSocketPool> pool_; |
Tom Sepez | 5bb7697a | 2023-01-16 20:48:52 | [diff] [blame] | 723 | |
| 724 | raw_ptr<TestConnectJobFactory> connect_job_factory_; |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 725 | ClientSocketPoolTest test_base_; |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 726 | }; |
| 727 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 728 | TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 729 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 730 | |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 731 | TestCompletionCallback callback; |
[email protected] | a512f598 | 2009-08-18 16:01:06 | [diff] [blame] | 732 | ClientSocketHandle handle; |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 733 | NetLogWithSource net_log_with_source = |
| 734 | NetLogWithSource::Make(NetLogSourceType::NONE); |
| 735 | |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 736 | TestLoadTimingInfoNotConnected(handle); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 737 | |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 738 | EXPECT_EQ(OK, handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 739 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 740 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 741 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 742 | pool_.get(), net_log_with_source)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 743 | EXPECT_TRUE(handle.is_initialized()); |
| 744 | EXPECT_TRUE(handle.socket()); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 745 | TestLoadTimingInfoConnectedNotReused(handle); |
| 746 | |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 747 | handle.Reset(); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 748 | TestLoadTimingInfoNotConnected(handle); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 749 | |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 750 | auto entries = |
| 751 | net_log_observer_.GetEntriesForSource(net_log_with_source.source()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 752 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 753 | EXPECT_EQ(5u, entries.size()); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 754 | EXPECT_TRUE(LogContainsEvent( |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 755 | entries, 0, NetLogEventType::TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 756 | NetLogEventPhase::NONE)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 757 | EXPECT_TRUE(LogContainsBeginEvent(entries, 1, NetLogEventType::SOCKET_POOL)); |
| 758 | EXPECT_TRUE(LogContainsEvent( |
| 759 | entries, 2, NetLogEventType::SOCKET_POOL_BOUND_TO_CONNECT_JOB, |
| 760 | NetLogEventPhase::NONE)); |
| 761 | EXPECT_TRUE(LogContainsEvent(entries, 3, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 762 | NetLogEventType::SOCKET_POOL_BOUND_TO_SOCKET, |
| 763 | NetLogEventPhase::NONE)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 764 | EXPECT_TRUE(LogContainsEndEvent(entries, 4, NetLogEventType::SOCKET_POOL)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 765 | } |
| 766 | |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 767 | TEST_F(ClientSocketPoolBaseTest, InitConnectionFailure) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 768 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 769 | |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 770 | connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 771 | NetLogWithSource net_log_with_source = |
| 772 | NetLogWithSource::Make(NetLogSourceType::NONE); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 773 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 774 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 775 | TestCompletionCallback callback; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 776 | // Set the additional error state members to ensure that they get cleared. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 777 | handle.set_is_ssl_error(true); |
Matt Menke | 39b7c5a | 2019-04-10 19:47:51 | [diff] [blame] | 778 | handle.set_ssl_cert_request_info(base::MakeRefCounted<SSLCertRequestInfo>()); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 779 | EXPECT_EQ( |
| 780 | ERR_CONNECTION_FAILED, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 781 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 782 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 783 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 784 | pool_.get(), net_log_with_source)); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 785 | EXPECT_FALSE(handle.socket()); |
| 786 | EXPECT_FALSE(handle.is_ssl_error()); |
Matt Menke | 39b7c5a | 2019-04-10 19:47:51 | [diff] [blame] | 787 | EXPECT_FALSE(handle.ssl_cert_request_info()); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 788 | TestLoadTimingInfoNotConnected(handle); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 789 | |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 790 | auto entries = |
| 791 | net_log_observer_.GetEntriesForSource(net_log_with_source.source()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 792 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 793 | EXPECT_EQ(4u, entries.size()); |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 794 | EXPECT_TRUE(LogContainsEvent( |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 795 | entries, 0, NetLogEventType::TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 796 | NetLogEventPhase::NONE)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 797 | EXPECT_TRUE(LogContainsBeginEvent(entries, 1, NetLogEventType::SOCKET_POOL)); |
| 798 | EXPECT_TRUE(LogContainsEvent( |
| 799 | entries, 2, NetLogEventType::SOCKET_POOL_BOUND_TO_CONNECT_JOB, |
| 800 | NetLogEventPhase::NONE)); |
| 801 | EXPECT_TRUE(LogContainsEndEvent(entries, 3, NetLogEventType::SOCKET_POOL)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 802 | } |
| 803 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 804 | // Test releasing an open socket into the socket pool, telling the socket pool |
| 805 | // to close the socket. |
| 806 | TEST_F(ClientSocketPoolBaseTest, ReleaseAndCloseConnection) { |
| 807 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 808 | |
| 809 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(OK)); |
| 810 | ASSERT_TRUE(request(0)->handle()->socket()); |
| 811 | net::NetLogSource source = request(0)->handle()->socket()->NetLog().source(); |
| 812 | ReleaseOneConnection(ClientSocketPoolTest::NO_KEEP_ALIVE); |
| 813 | |
| 814 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 815 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 816 | |
| 817 | ExpectSocketClosedWithReason( |
| 818 | source, TransportClientSocketPool::kClosedConnectionReturnedToPool); |
| 819 | } |
| 820 | |
| 821 | TEST_F(ClientSocketPoolBaseTest, SocketWithUnreadDataReturnedToPool) { |
| 822 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 823 | connect_job_factory_->set_job_type(TestConnectJob::kMockUnreadDataJob); |
| 824 | |
| 825 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(OK)); |
| 826 | ASSERT_TRUE(request(0)->handle()->socket()); |
| 827 | net::NetLogSource source = request(0)->handle()->socket()->NetLog().source(); |
| 828 | EXPECT_TRUE(request(0)->handle()->socket()->IsConnected()); |
| 829 | EXPECT_FALSE(request(0)->handle()->socket()->IsConnectedAndIdle()); |
| 830 | ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE); |
| 831 | |
| 832 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 833 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 834 | |
| 835 | ExpectSocketClosedWithReason( |
| 836 | source, TransportClientSocketPool::kDataReceivedUnexpectedly); |
| 837 | } |
| 838 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 839 | // Make sure different groups do not share sockets. |
| 840 | TEST_F(ClientSocketPoolBaseTest, GroupSeparation) { |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 841 | base::test::ScopedFeatureList feature_list; |
| 842 | feature_list.InitAndEnableFeature( |
| 843 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 844 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 845 | CreatePool(1000 /* max_sockets */, 2 /* max_sockets_per_group */); |
| 846 | |
| 847 | const HostPortPair kHostPortPairs[] = { |
| 848 | {"a", 80}, |
| 849 | {"a", 443}, |
| 850 | {"b", 80}, |
| 851 | }; |
| 852 | |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 853 | const char* const kSchemes[] = { |
| 854 | url::kHttpScheme, |
| 855 | url::kHttpsScheme, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 856 | }; |
| 857 | |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 858 | const PrivacyMode kPrivacyModes[] = {PrivacyMode::PRIVACY_MODE_DISABLED, |
| 859 | PrivacyMode::PRIVACY_MODE_ENABLED}; |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 860 | |
Matt Menke | 4807a9a | 2020-11-21 00:14:41 | [diff] [blame] | 861 | const SchemefulSite kSiteA(GURL("http://a.test/")); |
| 862 | const SchemefulSite kSiteB(GURL("http://b.test/")); |
Brianna Goldstein | a7593fca | 2022-09-28 02:59:32 | [diff] [blame] | 863 | const NetworkAnonymizationKey kNetworkAnonymizationKeys[] = { |
| 864 | NetworkAnonymizationKey(kSiteA, kSiteA, /*is_cross_site=*/false), |
| 865 | NetworkAnonymizationKey(kSiteB, kSiteB, /*is_cross_site=*/false), |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 866 | }; |
| 867 | |
Ben Schwartz | 3ff4dc1e6 | 2021-04-27 21:15:23 | [diff] [blame] | 868 | const SecureDnsPolicy kSecureDnsPolicys[] = {SecureDnsPolicy::kAllow, |
| 869 | SecureDnsPolicy::kDisable}; |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 870 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 871 | int total_idle_sockets = 0; |
| 872 | |
| 873 | // Walk through each GroupId, making sure that requesting a socket for one |
| 874 | // group does not return a previously connected socket for another group. |
| 875 | for (const auto& host_port_pair : kHostPortPairs) { |
| 876 | SCOPED_TRACE(host_port_pair.ToString()); |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 877 | for (const char* scheme : kSchemes) { |
| 878 | SCOPED_TRACE(scheme); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 879 | for (const auto& privacy_mode : kPrivacyModes) { |
| 880 | SCOPED_TRACE(privacy_mode); |
Brianna Goldstein | a7593fca | 2022-09-28 02:59:32 | [diff] [blame] | 881 | for (const auto& network_anonymization_key : |
| 882 | kNetworkAnonymizationKeys) { |
| 883 | SCOPED_TRACE(network_anonymization_key.ToDebugString()); |
Ben Schwartz | 3ff4dc1e6 | 2021-04-27 21:15:23 | [diff] [blame] | 884 | for (const auto& secure_dns_policy : kSecureDnsPolicys) { |
| 885 | SCOPED_TRACE(static_cast<int>(secure_dns_policy)); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 886 | |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 887 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 888 | |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 889 | ClientSocketPool::GroupId group_id( |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 890 | url::SchemeHostPort(scheme, host_port_pair.host(), |
| 891 | host_port_pair.port()), |
Brianna Goldstein | a7593fca | 2022-09-28 02:59:32 | [diff] [blame] | 892 | privacy_mode, network_anonymization_key, secure_dns_policy); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 893 | |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 894 | EXPECT_FALSE(pool_->HasGroupForTesting(group_id)); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 895 | |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 896 | TestCompletionCallback callback; |
| 897 | ClientSocketHandle handle; |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 898 | |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 899 | // Since the group is empty, requesting a socket should not complete |
| 900 | // synchronously. |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 901 | EXPECT_THAT(handle.Init(group_id, params_, absl::nullopt, |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 902 | DEFAULT_PRIORITY, SocketTag(), |
| 903 | ClientSocketPool::RespectLimits::ENABLED, |
| 904 | callback.callback(), |
| 905 | ClientSocketPool::ProxyAuthCallback(), |
| 906 | pool_.get(), NetLogWithSource()), |
| 907 | IsError(ERR_IO_PENDING)); |
| 908 | EXPECT_TRUE(pool_->HasGroupForTesting(group_id)); |
| 909 | EXPECT_EQ(total_idle_sockets, pool_->IdleSocketCount()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 910 | |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 911 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 912 | EXPECT_TRUE(handle.socket()); |
| 913 | EXPECT_TRUE(pool_->HasGroupForTesting(group_id)); |
| 914 | EXPECT_EQ(total_idle_sockets, pool_->IdleSocketCount()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 915 | |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 916 | // Return socket to pool. |
| 917 | handle.Reset(); |
| 918 | EXPECT_EQ(total_idle_sockets + 1, pool_->IdleSocketCount()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 919 | |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 920 | // Requesting a socket again should return the same socket as |
| 921 | // before, so should complete synchronously. |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 922 | EXPECT_THAT(handle.Init(group_id, params_, absl::nullopt, |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 923 | DEFAULT_PRIORITY, SocketTag(), |
| 924 | ClientSocketPool::RespectLimits::ENABLED, |
| 925 | callback.callback(), |
| 926 | ClientSocketPool::ProxyAuthCallback(), |
| 927 | pool_.get(), NetLogWithSource()), |
| 928 | IsOk()); |
| 929 | EXPECT_TRUE(handle.socket()); |
| 930 | EXPECT_EQ(total_idle_sockets, pool_->IdleSocketCount()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 931 | |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 932 | // Return socket to pool again. |
| 933 | handle.Reset(); |
| 934 | EXPECT_EQ(total_idle_sockets + 1, pool_->IdleSocketCount()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 935 | |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 936 | ++total_idle_sockets; |
| 937 | } |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 938 | } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 939 | } |
| 940 | } |
| 941 | } |
| 942 | } |
| 943 | |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 944 | TEST_F(ClientSocketPoolBaseTest, TotalLimit) { |
| 945 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 946 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 947 | // TODO(eroman): Check that the NetLog contains this event. |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 948 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 949 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 950 | EXPECT_THAT(StartRequest(TestGroupId("b"), DEFAULT_PRIORITY), IsOk()); |
| 951 | EXPECT_THAT(StartRequest(TestGroupId("c"), DEFAULT_PRIORITY), IsOk()); |
| 952 | EXPECT_THAT(StartRequest(TestGroupId("d"), DEFAULT_PRIORITY), IsOk()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 953 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 954 | EXPECT_EQ(static_cast<int>(requests_size()), |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 955 | client_socket_factory_.allocation_count()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 956 | EXPECT_EQ(requests_size() - kDefaultMaxSockets, completion_count()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 957 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 958 | EXPECT_THAT(StartRequest(TestGroupId("e"), DEFAULT_PRIORITY), |
| 959 | IsError(ERR_IO_PENDING)); |
| 960 | EXPECT_THAT(StartRequest(TestGroupId("f"), DEFAULT_PRIORITY), |
| 961 | IsError(ERR_IO_PENDING)); |
| 962 | EXPECT_THAT(StartRequest(TestGroupId("g"), DEFAULT_PRIORITY), |
| 963 | IsError(ERR_IO_PENDING)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 964 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 965 | ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 966 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 967 | EXPECT_EQ(static_cast<int>(requests_size()), |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 968 | client_socket_factory_.allocation_count()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 969 | EXPECT_EQ(requests_size() - kDefaultMaxSockets, completion_count()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 970 | |
| 971 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 972 | EXPECT_EQ(2, GetOrderOfRequest(2)); |
| 973 | EXPECT_EQ(3, GetOrderOfRequest(3)); |
| 974 | EXPECT_EQ(4, GetOrderOfRequest(4)); |
| 975 | EXPECT_EQ(5, GetOrderOfRequest(5)); |
| 976 | EXPECT_EQ(6, GetOrderOfRequest(6)); |
| 977 | EXPECT_EQ(7, GetOrderOfRequest(7)); |
[email protected] | 75439d3b | 2009-07-23 22:11:17 | [diff] [blame] | 978 | |
| 979 | // Make sure we test order of all requests made. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 980 | EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(8)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | TEST_F(ClientSocketPoolBaseTest, TotalLimitReachedNewGroup) { |
| 984 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 985 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 986 | // TODO(eroman): Check that the NetLog contains this event. |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 987 | |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 988 | // Reach all limits: max total sockets, and max sockets per group. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 989 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 990 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 991 | EXPECT_THAT(StartRequest(TestGroupId("b"), DEFAULT_PRIORITY), IsOk()); |
| 992 | EXPECT_THAT(StartRequest(TestGroupId("b"), DEFAULT_PRIORITY), IsOk()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 993 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 994 | EXPECT_EQ(static_cast<int>(requests_size()), |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 995 | client_socket_factory_.allocation_count()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 996 | EXPECT_EQ(requests_size() - kDefaultMaxSockets, completion_count()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 997 | |
| 998 | // Now create a new group and verify that we don't starve it. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 999 | EXPECT_THAT(StartRequest(TestGroupId("c"), DEFAULT_PRIORITY), |
| 1000 | IsError(ERR_IO_PENDING)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1001 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1002 | ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1003 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1004 | EXPECT_EQ(static_cast<int>(requests_size()), |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1005 | client_socket_factory_.allocation_count()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1006 | EXPECT_EQ(requests_size() - kDefaultMaxSockets, completion_count()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1007 | |
| 1008 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 1009 | EXPECT_EQ(2, GetOrderOfRequest(2)); |
| 1010 | EXPECT_EQ(3, GetOrderOfRequest(3)); |
| 1011 | EXPECT_EQ(4, GetOrderOfRequest(4)); |
| 1012 | EXPECT_EQ(5, GetOrderOfRequest(5)); |
[email protected] | 75439d3b | 2009-07-23 22:11:17 | [diff] [blame] | 1013 | |
| 1014 | // Make sure we test order of all requests made. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1015 | EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(6)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | TEST_F(ClientSocketPoolBaseTest, TotalLimitRespectsPriority) { |
| 1019 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1020 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1021 | EXPECT_THAT(StartRequest(TestGroupId("b"), LOWEST), IsOk()); |
| 1022 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsOk()); |
| 1023 | EXPECT_THAT(StartRequest(TestGroupId("b"), HIGHEST), IsOk()); |
| 1024 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsOk()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1025 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1026 | EXPECT_EQ(static_cast<int>(requests_size()), |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1027 | client_socket_factory_.allocation_count()); |
| 1028 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1029 | EXPECT_THAT(StartRequest(TestGroupId("c"), LOWEST), IsError(ERR_IO_PENDING)); |
| 1030 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsError(ERR_IO_PENDING)); |
| 1031 | EXPECT_THAT(StartRequest(TestGroupId("b"), HIGHEST), IsError(ERR_IO_PENDING)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1032 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1033 | ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1034 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1035 | EXPECT_EQ(requests_size() - kDefaultMaxSockets, completion_count()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1036 | |
| 1037 | // First 4 requests don't have to wait, and finish in order. |
| 1038 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 1039 | EXPECT_EQ(2, GetOrderOfRequest(2)); |
| 1040 | EXPECT_EQ(3, GetOrderOfRequest(3)); |
| 1041 | EXPECT_EQ(4, GetOrderOfRequest(4)); |
| 1042 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1043 | // Request ("b", HIGHEST) has the highest priority, then (TestGroupId("a"), |
| 1044 | // MEDIUM), and then ("c", LOWEST). |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1045 | EXPECT_EQ(7, GetOrderOfRequest(5)); |
| 1046 | EXPECT_EQ(6, GetOrderOfRequest(6)); |
| 1047 | EXPECT_EQ(5, GetOrderOfRequest(7)); |
[email protected] | 75439d3b | 2009-07-23 22:11:17 | [diff] [blame] | 1048 | |
| 1049 | // Make sure we test order of all requests made. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1050 | EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(9)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1051 | } |
| 1052 | |
rdsmith | 29dbad1 | 2017-02-17 02:22:18 | [diff] [blame] | 1053 | // Test reprioritizing a request before completion doesn't interfere with |
| 1054 | // its completion. |
| 1055 | TEST_F(ClientSocketPoolBaseTest, ReprioritizeOne) { |
| 1056 | CreatePool(kDefaultMaxSockets, 1); |
| 1057 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1058 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(OK)); |
| 1059 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsError(ERR_IO_PENDING)); |
rdsmith | 29dbad1 | 2017-02-17 02:22:18 | [diff] [blame] | 1060 | EXPECT_TRUE(request(0)->handle()->socket()); |
| 1061 | EXPECT_FALSE(request(1)->handle()->socket()); |
| 1062 | |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 1063 | request(1)->handle()->SetPriority(HIGHEST); |
rdsmith | 29dbad1 | 2017-02-17 02:22:18 | [diff] [blame] | 1064 | |
| 1065 | ReleaseOneConnection(ClientSocketPoolTest::NO_KEEP_ALIVE); |
| 1066 | |
| 1067 | EXPECT_TRUE(request(1)->handle()->socket()); |
| 1068 | } |
| 1069 | |
| 1070 | // Reprioritize a request up past another one and make sure that changes the |
| 1071 | // completion order. |
| 1072 | TEST_F(ClientSocketPoolBaseTest, ReprioritizeUpReorder) { |
| 1073 | CreatePool(kDefaultMaxSockets, 1); |
| 1074 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1075 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(OK)); |
| 1076 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsError(ERR_IO_PENDING)); |
| 1077 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(ERR_IO_PENDING)); |
rdsmith | 29dbad1 | 2017-02-17 02:22:18 | [diff] [blame] | 1078 | EXPECT_TRUE(request(0)->handle()->socket()); |
| 1079 | EXPECT_FALSE(request(1)->handle()->socket()); |
| 1080 | EXPECT_FALSE(request(2)->handle()->socket()); |
| 1081 | |
| 1082 | request(2)->handle()->SetPriority(HIGHEST); |
| 1083 | |
| 1084 | ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
| 1085 | |
| 1086 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 1087 | EXPECT_EQ(3, GetOrderOfRequest(2)); |
| 1088 | EXPECT_EQ(2, GetOrderOfRequest(3)); |
| 1089 | } |
| 1090 | |
| 1091 | // Reprioritize a request without changing relative priorities and check |
| 1092 | // that the order doesn't change. |
| 1093 | TEST_F(ClientSocketPoolBaseTest, ReprioritizeUpNoReorder) { |
| 1094 | CreatePool(kDefaultMaxSockets, 1); |
| 1095 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1096 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(OK)); |
| 1097 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsError(ERR_IO_PENDING)); |
| 1098 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOW), IsError(ERR_IO_PENDING)); |
rdsmith | 29dbad1 | 2017-02-17 02:22:18 | [diff] [blame] | 1099 | EXPECT_TRUE(request(0)->handle()->socket()); |
| 1100 | EXPECT_FALSE(request(1)->handle()->socket()); |
| 1101 | EXPECT_FALSE(request(2)->handle()->socket()); |
| 1102 | |
| 1103 | request(2)->handle()->SetPriority(MEDIUM); |
| 1104 | |
| 1105 | ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
| 1106 | |
| 1107 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 1108 | EXPECT_EQ(2, GetOrderOfRequest(2)); |
| 1109 | EXPECT_EQ(3, GetOrderOfRequest(3)); |
| 1110 | } |
| 1111 | |
| 1112 | // Reprioritize a request past down another one and make sure that changes the |
| 1113 | // completion order. |
| 1114 | TEST_F(ClientSocketPoolBaseTest, ReprioritizeDownReorder) { |
| 1115 | CreatePool(kDefaultMaxSockets, 1); |
| 1116 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1117 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(OK)); |
| 1118 | EXPECT_THAT(StartRequest(TestGroupId("a"), HIGHEST), IsError(ERR_IO_PENDING)); |
| 1119 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsError(ERR_IO_PENDING)); |
rdsmith | 29dbad1 | 2017-02-17 02:22:18 | [diff] [blame] | 1120 | EXPECT_TRUE(request(0)->handle()->socket()); |
| 1121 | EXPECT_FALSE(request(1)->handle()->socket()); |
| 1122 | EXPECT_FALSE(request(2)->handle()->socket()); |
| 1123 | |
| 1124 | request(1)->handle()->SetPriority(LOW); |
| 1125 | |
| 1126 | ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
| 1127 | |
| 1128 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 1129 | EXPECT_EQ(3, GetOrderOfRequest(2)); |
| 1130 | EXPECT_EQ(2, GetOrderOfRequest(3)); |
| 1131 | } |
| 1132 | |
| 1133 | // Reprioritize a request to the same level as another and confirm it is |
| 1134 | // put after the old request. |
| 1135 | TEST_F(ClientSocketPoolBaseTest, ReprioritizeResetFIFO) { |
| 1136 | CreatePool(kDefaultMaxSockets, 1); |
| 1137 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1138 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(OK)); |
| 1139 | EXPECT_THAT(StartRequest(TestGroupId("a"), HIGHEST), IsError(ERR_IO_PENDING)); |
| 1140 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsError(ERR_IO_PENDING)); |
rdsmith | 29dbad1 | 2017-02-17 02:22:18 | [diff] [blame] | 1141 | EXPECT_TRUE(request(0)->handle()->socket()); |
| 1142 | EXPECT_FALSE(request(1)->handle()->socket()); |
| 1143 | EXPECT_FALSE(request(2)->handle()->socket()); |
| 1144 | |
| 1145 | request(1)->handle()->SetPriority(MEDIUM); |
| 1146 | |
| 1147 | ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
| 1148 | |
| 1149 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 1150 | EXPECT_EQ(3, GetOrderOfRequest(2)); |
| 1151 | EXPECT_EQ(2, GetOrderOfRequest(3)); |
| 1152 | } |
| 1153 | |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1154 | TEST_F(ClientSocketPoolBaseTest, TotalLimitRespectsGroupLimit) { |
| 1155 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1156 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1157 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsOk()); |
| 1158 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOW), IsOk()); |
| 1159 | EXPECT_THAT(StartRequest(TestGroupId("b"), HIGHEST), IsOk()); |
| 1160 | EXPECT_THAT(StartRequest(TestGroupId("b"), MEDIUM), IsOk()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1161 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1162 | EXPECT_EQ(static_cast<int>(requests_size()), |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1163 | client_socket_factory_.allocation_count()); |
| 1164 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1165 | EXPECT_THAT(StartRequest(TestGroupId("c"), MEDIUM), IsError(ERR_IO_PENDING)); |
| 1166 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOW), IsError(ERR_IO_PENDING)); |
| 1167 | EXPECT_THAT(StartRequest(TestGroupId("b"), HIGHEST), IsError(ERR_IO_PENDING)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1168 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1169 | ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1170 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1171 | EXPECT_EQ(static_cast<int>(requests_size()), |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1172 | client_socket_factory_.allocation_count()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1173 | EXPECT_EQ(requests_size() - kDefaultMaxSockets, completion_count()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1174 | |
| 1175 | // First 4 requests don't have to wait, and finish in order. |
| 1176 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 1177 | EXPECT_EQ(2, GetOrderOfRequest(2)); |
| 1178 | EXPECT_EQ(3, GetOrderOfRequest(3)); |
| 1179 | EXPECT_EQ(4, GetOrderOfRequest(4)); |
| 1180 | |
| 1181 | // Request ("b", 7) has the highest priority, but we can't make new socket for |
| 1182 | // group "b", because it has reached the per-group limit. Then we make |
| 1183 | // socket for ("c", 6), because it has higher priority than ("a", 4), |
| 1184 | // and we still can't make a socket for group "b". |
| 1185 | EXPECT_EQ(5, GetOrderOfRequest(5)); |
| 1186 | EXPECT_EQ(6, GetOrderOfRequest(6)); |
| 1187 | EXPECT_EQ(7, GetOrderOfRequest(7)); |
[email protected] | 75439d3b | 2009-07-23 22:11:17 | [diff] [blame] | 1188 | |
| 1189 | // Make sure we test order of all requests made. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1190 | EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(8)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | // Make sure that we count connecting sockets against the total limit. |
| 1194 | TEST_F(ClientSocketPoolBaseTest, TotalLimitCountsConnectingSockets) { |
| 1195 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1196 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1197 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 1198 | EXPECT_THAT(StartRequest(TestGroupId("b"), DEFAULT_PRIORITY), IsOk()); |
| 1199 | EXPECT_THAT(StartRequest(TestGroupId("c"), DEFAULT_PRIORITY), IsOk()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1200 | |
| 1201 | // Create one asynchronous request. |
| 1202 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1203 | EXPECT_THAT(StartRequest(TestGroupId("d"), DEFAULT_PRIORITY), |
| 1204 | IsError(ERR_IO_PENDING)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1205 | |
[email protected] | 6b17538 | 2009-10-13 06:47:47 | [diff] [blame] | 1206 | // We post all of our delayed tasks with a 2ms delay. I.e. they don't |
| 1207 | // actually become pending until 2ms after they have been created. In order |
| 1208 | // to flush all tasks, we need to wait so that we know there are no |
| 1209 | // soon-to-be-pending tasks waiting. |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 1210 | FastForwardBy(base::Milliseconds(10)); |
[email protected] | 6b17538 | 2009-10-13 06:47:47 | [diff] [blame] | 1211 | |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1212 | // The next synchronous request should wait for its turn. |
| 1213 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1214 | EXPECT_THAT(StartRequest(TestGroupId("e"), DEFAULT_PRIORITY), |
| 1215 | IsError(ERR_IO_PENDING)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1216 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1217 | ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1218 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1219 | EXPECT_EQ(static_cast<int>(requests_size()), |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1220 | client_socket_factory_.allocation_count()); |
| 1221 | |
| 1222 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 1223 | EXPECT_EQ(2, GetOrderOfRequest(2)); |
| 1224 | EXPECT_EQ(3, GetOrderOfRequest(3)); |
| 1225 | EXPECT_EQ(4, GetOrderOfRequest(4)); |
[email protected] | 75439d3b | 2009-07-23 22:11:17 | [diff] [blame] | 1226 | EXPECT_EQ(5, GetOrderOfRequest(5)); |
| 1227 | |
| 1228 | // Make sure we test order of all requests made. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1229 | EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(6)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1230 | } |
| 1231 | |
[email protected] | 6427fe2 | 2010-04-16 22:27:41 | [diff] [blame] | 1232 | TEST_F(ClientSocketPoolBaseTest, CorrectlyCountStalledGroups) { |
| 1233 | CreatePool(kDefaultMaxSockets, kDefaultMaxSockets); |
| 1234 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 1235 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1236 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 1237 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 1238 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 1239 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
[email protected] | 6427fe2 | 2010-04-16 22:27:41 | [diff] [blame] | 1240 | |
| 1241 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 1242 | |
| 1243 | EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count()); |
| 1244 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1245 | EXPECT_THAT(StartRequest(TestGroupId("b"), DEFAULT_PRIORITY), |
| 1246 | IsError(ERR_IO_PENDING)); |
| 1247 | EXPECT_THAT(StartRequest(TestGroupId("c"), DEFAULT_PRIORITY), |
| 1248 | IsError(ERR_IO_PENDING)); |
[email protected] | 6427fe2 | 2010-04-16 22:27:41 | [diff] [blame] | 1249 | |
| 1250 | EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count()); |
| 1251 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1252 | EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE)); |
[email protected] | 6427fe2 | 2010-04-16 22:27:41 | [diff] [blame] | 1253 | EXPECT_EQ(kDefaultMaxSockets + 1, client_socket_factory_.allocation_count()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1254 | EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE)); |
[email protected] | 6427fe2 | 2010-04-16 22:27:41 | [diff] [blame] | 1255 | EXPECT_EQ(kDefaultMaxSockets + 2, client_socket_factory_.allocation_count()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1256 | EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE)); |
| 1257 | EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE)); |
[email protected] | 6427fe2 | 2010-04-16 22:27:41 | [diff] [blame] | 1258 | EXPECT_EQ(kDefaultMaxSockets + 2, client_socket_factory_.allocation_count()); |
| 1259 | } |
| 1260 | |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 1261 | TEST_F(ClientSocketPoolBaseTest, StallAndThenCancelAndTriggerAvailableSocket) { |
| 1262 | CreatePool(kDefaultMaxSockets, kDefaultMaxSockets); |
| 1263 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 1264 | |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1265 | TestCompletionCallback callback; |
Peter Kasting | e20797db | 2022-08-18 19:44:14 | [diff] [blame] | 1266 | ClientSocketHandle stalled_handle; |
| 1267 | EXPECT_EQ(ERR_IO_PENDING, |
| 1268 | stalled_handle.Init( |
| 1269 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
| 1270 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 1271 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1272 | pool_.get(), NetLogWithSource())); |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 1273 | |
| 1274 | ClientSocketHandle handles[4]; |
Tsuyoshi Horo | 17ef47d0 | 2022-06-30 10:58:27 | [diff] [blame] | 1275 | for (auto& handle : handles) { |
| 1276 | EXPECT_EQ( |
| 1277 | ERR_IO_PENDING, |
| 1278 | handle.Init(TestGroupId("b"), params_, absl::nullopt, DEFAULT_PRIORITY, |
| 1279 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 1280 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1281 | pool_.get(), NetLogWithSource())); |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | // One will be stalled, cancel all the handles now. |
| 1285 | // This should hit the OnAvailableSocketSlot() code where we previously had |
| 1286 | // stalled groups, but no longer have any. |
Tsuyoshi Horo | 17ef47d0 | 2022-06-30 10:58:27 | [diff] [blame] | 1287 | for (auto& handle : handles) |
| 1288 | handle.Reset(); |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 1289 | } |
| 1290 | |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1291 | TEST_F(ClientSocketPoolBaseTest, CancelStalledSocketAtSocketLimit) { |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1292 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1293 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 1294 | |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1295 | { |
| 1296 | ClientSocketHandle handles[kDefaultMaxSockets]; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1297 | TestCompletionCallback callbacks[kDefaultMaxSockets]; |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1298 | for (int i = 0; i < kDefaultMaxSockets; ++i) { |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 1299 | EXPECT_EQ(OK, handles[i].Init(TestGroupId("a" + base::NumberToString(i)), |
| 1300 | params_, absl::nullopt, DEFAULT_PRIORITY, |
| 1301 | SocketTag(), |
| 1302 | ClientSocketPool::RespectLimits::ENABLED, |
| 1303 | callbacks[i].callback(), |
| 1304 | ClientSocketPool::ProxyAuthCallback(), |
| 1305 | pool_.get(), NetLogWithSource())); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | // Force a stalled group. |
| 1309 | ClientSocketHandle stalled_handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1310 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 1311 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1312 | stalled_handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1313 | TestGroupId("foo"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1314 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 1315 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1316 | pool_.get(), NetLogWithSource())); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1317 | |
| 1318 | // Cancel the stalled request. |
| 1319 | stalled_handle.Reset(); |
| 1320 | |
| 1321 | EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count()); |
| 1322 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 1323 | |
| 1324 | // Dropping out of scope will close all handles and return them to idle. |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1325 | } |
| 1326 | |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1327 | EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count()); |
| 1328 | EXPECT_EQ(kDefaultMaxSockets, pool_->IdleSocketCount()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1329 | } |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1330 | |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1331 | TEST_F(ClientSocketPoolBaseTest, CancelPendingSocketAtSocketLimit) { |
| 1332 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1333 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 1334 | |
| 1335 | { |
| 1336 | ClientSocketHandle handles[kDefaultMaxSockets]; |
| 1337 | for (int i = 0; i < kDefaultMaxSockets; ++i) { |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1338 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 1339 | EXPECT_EQ(ERR_IO_PENDING, |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 1340 | handles[i].Init( |
| 1341 | TestGroupId("a" + base::NumberToString(i)), params_, |
| 1342 | absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
| 1343 | ClientSocketPool::RespectLimits::ENABLED, |
| 1344 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1345 | pool_.get(), NetLogWithSource())); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | // Force a stalled group. |
| 1349 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 1350 | ClientSocketHandle stalled_handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1351 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 1352 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1353 | stalled_handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1354 | TestGroupId("foo"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1355 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 1356 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1357 | pool_.get(), NetLogWithSource())); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1358 | |
| 1359 | // Since it is stalled, it should have no connect jobs. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 1360 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("foo"))); |
| 1361 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 1362 | TestGroupId("foo"))); |
| 1363 | EXPECT_EQ(0u, pool_->NumUnassignedConnectJobsInGroupForTesting( |
| 1364 | TestGroupId("foo"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1365 | |
| 1366 | // Cancel the stalled request. |
| 1367 | handles[0].Reset(); |
| 1368 | |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1369 | // Now we should have a connect job. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 1370 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("foo"))); |
| 1371 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 1372 | TestGroupId("foo"))); |
| 1373 | EXPECT_EQ(0u, pool_->NumUnassignedConnectJobsInGroupForTesting( |
| 1374 | TestGroupId("foo"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1375 | |
| 1376 | // The stalled socket should connect. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1377 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1378 | |
| 1379 | EXPECT_EQ(kDefaultMaxSockets + 1, |
| 1380 | client_socket_factory_.allocation_count()); |
| 1381 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 1382 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("foo"))); |
| 1383 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 1384 | TestGroupId("foo"))); |
| 1385 | EXPECT_EQ(0u, pool_->NumUnassignedConnectJobsInGroupForTesting( |
| 1386 | TestGroupId("foo"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1387 | |
| 1388 | // Dropping out of scope will close all handles and return them to idle. |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1389 | } |
| 1390 | |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1391 | EXPECT_EQ(1, pool_->IdleSocketCount()); |
| 1392 | } |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1393 | |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1394 | TEST_F(ClientSocketPoolBaseTest, WaitForStalledSocketAtSocketLimit) { |
| 1395 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1396 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1397 | |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1398 | ClientSocketHandle stalled_handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1399 | TestCompletionCallback callback; |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1400 | { |
[email protected] | 51fdc7c | 2012-04-10 19:19:48 | [diff] [blame] | 1401 | EXPECT_FALSE(pool_->IsStalled()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1402 | ClientSocketHandle handles[kDefaultMaxSockets]; |
| 1403 | for (int i = 0; i < kDefaultMaxSockets; ++i) { |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1404 | EXPECT_EQ( |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1405 | OK, handles[i].Init( |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 1406 | TestGroupId(base::StringPrintf("take-2-%d", i)), params_, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1407 | absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1408 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
| 1409 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 1410 | NetLogWithSource())); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count()); |
| 1414 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
[email protected] | 51fdc7c | 2012-04-10 19:19:48 | [diff] [blame] | 1415 | EXPECT_FALSE(pool_->IsStalled()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1416 | |
| 1417 | // Now we will hit the socket limit. |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 1418 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1419 | stalled_handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1420 | TestGroupId("foo"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1421 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 1422 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1423 | pool_.get(), NetLogWithSource())); |
[email protected] | 51fdc7c | 2012-04-10 19:19:48 | [diff] [blame] | 1424 | EXPECT_TRUE(pool_->IsStalled()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1425 | |
| 1426 | // Dropping out of scope will close all handles and return them to idle. |
| 1427 | } |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1428 | |
| 1429 | // But if we wait for it, the released idle sockets will be closed in |
| 1430 | // preference of the waiting request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1431 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1432 | |
| 1433 | EXPECT_EQ(kDefaultMaxSockets + 1, client_socket_factory_.allocation_count()); |
| 1434 | EXPECT_EQ(3, pool_->IdleSocketCount()); |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | // Regression test for http://crbug.com/40952. |
| 1438 | TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketAtSocketLimitDeleteGroup) { |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 1439 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, |
| 1440 | true /* enable_backup_connect_jobs */); |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1441 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 1442 | |
| 1443 | for (int i = 0; i < kDefaultMaxSockets; ++i) { |
| 1444 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1445 | TestCompletionCallback callback; |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 1446 | EXPECT_EQ( |
| 1447 | OK, |
| 1448 | handle.Init(TestGroupId("a" + base::NumberToString(i)), params_, |
| 1449 | absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
| 1450 | ClientSocketPool::RespectLimits::ENABLED, |
| 1451 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1452 | pool_.get(), NetLogWithSource())); |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | // Flush all the DoReleaseSocket tasks. |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 1456 | base::RunLoop().RunUntilIdle(); |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1457 | |
| 1458 | // Stall a group. Set a pending job so it'll trigger a backup job if we don't |
| 1459 | // reuse a socket. |
| 1460 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 1461 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1462 | TestCompletionCallback callback; |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1463 | |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 1464 | // "a0" is special here, since it should be the first entry in the sorted map, |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1465 | // which is the one which we would close an idle socket for. We shouldn't |
| 1466 | // close an idle socket though, since we should reuse the idle socket. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1467 | EXPECT_EQ(OK, handle.Init( |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 1468 | TestGroupId("a0"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1469 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1470 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1471 | pool_.get(), NetLogWithSource())); |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1472 | |
| 1473 | EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count()); |
| 1474 | EXPECT_EQ(kDefaultMaxSockets - 1, pool_->IdleSocketCount()); |
| 1475 | } |
| 1476 | |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 1477 | TEST_F(ClientSocketPoolBaseTest, PendingRequests) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1478 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1479 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1480 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 1481 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 1482 | EXPECT_THAT(StartRequest(TestGroupId("a"), IDLE), IsError(ERR_IO_PENDING)); |
| 1483 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(ERR_IO_PENDING)); |
| 1484 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsError(ERR_IO_PENDING)); |
| 1485 | EXPECT_THAT(StartRequest(TestGroupId("a"), HIGHEST), IsError(ERR_IO_PENDING)); |
| 1486 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOW), IsError(ERR_IO_PENDING)); |
| 1487 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(ERR_IO_PENDING)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1488 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1489 | ReleaseAllConnections(ClientSocketPoolTest::KEEP_ALIVE); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1490 | EXPECT_EQ(kDefaultMaxSocketsPerGroup, |
| 1491 | client_socket_factory_.allocation_count()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1492 | EXPECT_EQ(requests_size() - kDefaultMaxSocketsPerGroup, |
| 1493 | completion_count()); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1494 | |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1495 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 1496 | EXPECT_EQ(2, GetOrderOfRequest(2)); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 1497 | EXPECT_EQ(8, GetOrderOfRequest(3)); |
| 1498 | EXPECT_EQ(6, GetOrderOfRequest(4)); |
| 1499 | EXPECT_EQ(4, GetOrderOfRequest(5)); |
| 1500 | EXPECT_EQ(3, GetOrderOfRequest(6)); |
| 1501 | EXPECT_EQ(5, GetOrderOfRequest(7)); |
| 1502 | EXPECT_EQ(7, GetOrderOfRequest(8)); |
[email protected] | 75439d3b | 2009-07-23 22:11:17 | [diff] [blame] | 1503 | |
| 1504 | // Make sure we test order of all requests made. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1505 | EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(9)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1506 | } |
| 1507 | |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 1508 | TEST_F(ClientSocketPoolBaseTest, PendingRequests_NoKeepAlive) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1509 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1510 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1511 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 1512 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 1513 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(ERR_IO_PENDING)); |
| 1514 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsError(ERR_IO_PENDING)); |
| 1515 | EXPECT_THAT(StartRequest(TestGroupId("a"), HIGHEST), IsError(ERR_IO_PENDING)); |
| 1516 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOW), IsError(ERR_IO_PENDING)); |
| 1517 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(ERR_IO_PENDING)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1518 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1519 | ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1520 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1521 | for (size_t i = kDefaultMaxSocketsPerGroup; i < requests_size(); ++i) |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1522 | EXPECT_THAT(request(i)->WaitForResult(), IsOk()); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1523 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1524 | EXPECT_EQ(static_cast<int>(requests_size()), |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1525 | client_socket_factory_.allocation_count()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1526 | EXPECT_EQ(requests_size() - kDefaultMaxSocketsPerGroup, |
| 1527 | completion_count()); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1528 | } |
| 1529 | |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1530 | TEST_F(ClientSocketPoolBaseTest, ResetAndCloseSocket) { |
| 1531 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1532 | |
| 1533 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 1534 | ClientSocketHandle handle; |
| 1535 | TestCompletionCallback callback; |
| 1536 | EXPECT_EQ( |
| 1537 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1538 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1539 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 1540 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1541 | pool_.get(), NetLogWithSource())); |
| 1542 | |
| 1543 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 1544 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1545 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 1546 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
| 1547 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
| 1548 | |
| 1549 | handle.ResetAndCloseSocket(); |
| 1550 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1551 | } |
| 1552 | |
Matt Menke | 99251ea4 | 2019-04-25 22:59:02 | [diff] [blame] | 1553 | // This test will start up a socket request and then call Reset() on the handle. |
| 1554 | // The pending ConnectJob should not be destroyed. |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1555 | TEST_F(ClientSocketPoolBaseTest, CancelRequestKeepsConnectJob) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1556 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1557 | |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 1558 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1559 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1560 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1561 | EXPECT_EQ( |
| 1562 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1563 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1564 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 1565 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1566 | pool_.get(), NetLogWithSource())); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1567 | handle.Reset(); |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1568 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1569 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 1570 | } |
| 1571 | |
Matt Menke | 99251ea4 | 2019-04-25 22:59:02 | [diff] [blame] | 1572 | // This test will start up a socket request and then call ResetAndCloseSocket() |
| 1573 | // on the handle. The pending ConnectJob or connected socket should be |
| 1574 | // destroyed. |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1575 | TEST_F(ClientSocketPoolBaseTest, CancelRequestAndCloseSocket) { |
| 1576 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1577 | |
Matt Menke | 99251ea4 | 2019-04-25 22:59:02 | [diff] [blame] | 1578 | // When true, the socket connects before it's canceled. |
| 1579 | for (bool cancel_when_callback_pending : {false, true}) { |
| 1580 | if (cancel_when_callback_pending) { |
| 1581 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 1582 | } else { |
| 1583 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 1584 | } |
| 1585 | ClientSocketHandle handle; |
| 1586 | TestCompletionCallback callback; |
| 1587 | EXPECT_EQ( |
| 1588 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1589 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | 99251ea4 | 2019-04-25 22:59:02 | [diff] [blame] | 1590 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 1591 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1592 | pool_.get(), NetLogWithSource())); |
| 1593 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1594 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 1595 | |
| 1596 | if (cancel_when_callback_pending) { |
| 1597 | client_socket_factory_.SignalJobs(); |
| 1598 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1599 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
| 1600 | } |
| 1601 | |
| 1602 | handle.ResetAndCloseSocket(); |
| 1603 | ASSERT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1604 | } |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1605 | } |
| 1606 | |
| 1607 | TEST_F(ClientSocketPoolBaseTest, |
| 1608 | CancelRequestAndCloseSocketWhenMoreRequestsThanConnectJobs) { |
| 1609 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1610 | |
Matt Menke | 99251ea4 | 2019-04-25 22:59:02 | [diff] [blame] | 1611 | // When true, the sockets connect before they're canceled. |
| 1612 | for (bool cancel_when_callback_pending : {false, true}) { |
| 1613 | if (cancel_when_callback_pending) { |
| 1614 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 1615 | } else { |
| 1616 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 1617 | } |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1618 | |
Matt Menke | 99251ea4 | 2019-04-25 22:59:02 | [diff] [blame] | 1619 | std::vector<std::unique_ptr<ClientSocketHandle>> handles; |
| 1620 | TestCompletionCallback callback; |
| 1621 | // Make |kDefaultMaxSockets + 1| socket requests. |
| 1622 | for (int i = 0; i < kDefaultMaxSocketsPerGroup + 1; ++i) { |
| 1623 | std::unique_ptr<ClientSocketHandle> handle = |
| 1624 | std::make_unique<ClientSocketHandle>(); |
| 1625 | EXPECT_EQ(ERR_IO_PENDING, |
| 1626 | handle->Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1627 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | 99251ea4 | 2019-04-25 22:59:02 | [diff] [blame] | 1628 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 1629 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1630 | pool_.get(), NetLogWithSource())); |
| 1631 | handles.push_back(std::move(handle)); |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1632 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Matt Menke | 99251ea4 | 2019-04-25 22:59:02 | [diff] [blame] | 1633 | EXPECT_EQ( |
| 1634 | static_cast<size_t>(std::min(i + 1, kDefaultMaxSocketsPerGroup)), |
| 1635 | pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 1636 | } |
| 1637 | |
| 1638 | if (cancel_when_callback_pending) { |
| 1639 | client_socket_factory_.SignalJobs(); |
| 1640 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1641 | EXPECT_EQ(kDefaultMaxSocketsPerGroup, |
| 1642 | pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
| 1643 | } |
| 1644 | |
| 1645 | // Calling ResetAndCloseSocket() on a handle should not cancel a ConnectJob |
| 1646 | // or close a socket, since there are more requests than ConnectJobs or |
| 1647 | // sockets. |
| 1648 | handles[kDefaultMaxSocketsPerGroup]->ResetAndCloseSocket(); |
| 1649 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1650 | if (cancel_when_callback_pending) { |
| 1651 | EXPECT_EQ(kDefaultMaxSocketsPerGroup, |
| 1652 | pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
| 1653 | } else { |
| 1654 | EXPECT_EQ(static_cast<size_t>(kDefaultMaxSocketsPerGroup), |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1655 | pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 1656 | } |
Matt Menke | 99251ea4 | 2019-04-25 22:59:02 | [diff] [blame] | 1657 | |
| 1658 | // Calling ResetAndCloseSocket() on other handles should cancel a ConnectJob |
| 1659 | // or close a socket. |
| 1660 | for (int i = kDefaultMaxSocketsPerGroup - 1; i >= 0; --i) { |
| 1661 | handles[i]->ResetAndCloseSocket(); |
| 1662 | if (i > 0) { |
| 1663 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1664 | if (cancel_when_callback_pending) { |
| 1665 | EXPECT_EQ(i, |
| 1666 | pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
| 1667 | } else { |
| 1668 | EXPECT_EQ(static_cast<size_t>(i), |
| 1669 | pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 1670 | } |
| 1671 | } else { |
| 1672 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1673 | } |
| 1674 | } |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1675 | } |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1676 | } |
| 1677 | |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 1678 | TEST_F(ClientSocketPoolBaseTest, ConnectCancelConnect) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1679 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1680 | |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 1681 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
[email protected] | a512f598 | 2009-08-18 16:01:06 | [diff] [blame] | 1682 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1683 | TestCompletionCallback callback; |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1684 | |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1685 | EXPECT_EQ( |
| 1686 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1687 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1688 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 1689 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1690 | pool_.get(), NetLogWithSource())); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1691 | |
| 1692 | handle.Reset(); |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1693 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1694 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1695 | |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1696 | // This will create a second ConnectJob, since the other ConnectJob was |
| 1697 | // previously assigned to a request. |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1698 | TestCompletionCallback callback2; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1699 | EXPECT_EQ( |
| 1700 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1701 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1702 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1703 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1704 | pool_.get(), NetLogWithSource())); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1705 | |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1706 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1707 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 1708 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1709 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1710 | EXPECT_FALSE(callback.have_result()); |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1711 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1712 | // One ConnectJob completed, and its socket is now assigned to |handle|. |
| 1713 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
| 1714 | // The other ConnectJob should have either completed, or still be connecting. |
| 1715 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a")) + |
| 1716 | pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1717 | |
| 1718 | handle.Reset(); |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1719 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1720 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a")) + |
| 1721 | pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
| 1722 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1723 | } |
| 1724 | |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 1725 | TEST_F(ClientSocketPoolBaseTest, CancelRequest) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1726 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1727 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1728 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 1729 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 1730 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(ERR_IO_PENDING)); |
| 1731 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsError(ERR_IO_PENDING)); |
| 1732 | EXPECT_THAT(StartRequest(TestGroupId("a"), HIGHEST), IsError(ERR_IO_PENDING)); |
| 1733 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOW), IsError(ERR_IO_PENDING)); |
| 1734 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(ERR_IO_PENDING)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1735 | |
| 1736 | // Cancel a request. |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1737 | size_t index_to_cancel = kDefaultMaxSocketsPerGroup + 2; |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1738 | EXPECT_FALSE((*requests())[index_to_cancel]->handle()->is_initialized()); |
| 1739 | (*requests())[index_to_cancel]->handle()->Reset(); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1740 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1741 | ReleaseAllConnections(ClientSocketPoolTest::KEEP_ALIVE); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1742 | |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1743 | EXPECT_EQ(kDefaultMaxSocketsPerGroup, |
| 1744 | client_socket_factory_.allocation_count()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1745 | EXPECT_EQ(requests_size() - kDefaultMaxSocketsPerGroup - 1, |
| 1746 | completion_count()); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1747 | |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1748 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 1749 | EXPECT_EQ(2, GetOrderOfRequest(2)); |
| 1750 | EXPECT_EQ(5, GetOrderOfRequest(3)); |
| 1751 | EXPECT_EQ(3, GetOrderOfRequest(4)); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1752 | EXPECT_EQ(ClientSocketPoolTest::kRequestNotFound, |
| 1753 | GetOrderOfRequest(5)); // Canceled request. |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1754 | EXPECT_EQ(4, GetOrderOfRequest(6)); |
| 1755 | EXPECT_EQ(6, GetOrderOfRequest(7)); |
[email protected] | 75439d3b | 2009-07-23 22:11:17 | [diff] [blame] | 1756 | |
| 1757 | // Make sure we test order of all requests made. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1758 | EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(8)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1759 | } |
| 1760 | |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1761 | // Function to be used as a callback on socket request completion. It first |
| 1762 | // disconnects the successfully connected socket from the first request, and |
| 1763 | // then reuses the ClientSocketHandle to request another socket. |
| 1764 | // |
| 1765 | // |nested_callback| is called with the result of the second socket request. |
| 1766 | void RequestSocketOnComplete(ClientSocketHandle* handle, |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 1767 | TransportClientSocketPool* pool, |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1768 | TestConnectJobFactory* test_connect_job_factory, |
| 1769 | TestConnectJob::JobType next_job_type, |
Bence Béky | a4a5093 | 2018-08-10 13:39:41 | [diff] [blame] | 1770 | TestCompletionCallback* nested_callback, |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1771 | int first_request_result) { |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1772 | EXPECT_THAT(first_request_result, IsOk()); |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1773 | |
| 1774 | test_connect_job_factory->set_job_type(next_job_type); |
| 1775 | |
| 1776 | // Don't allow reuse of the socket. Disconnect it and then release it. |
| 1777 | if (handle->socket()) |
| 1778 | handle->socket()->Disconnect(); |
| 1779 | handle->Reset(); |
| 1780 | |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1781 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1782 | int rv = handle->Init( |
Matt Menke | 870e19ab | 2019-04-23 16:23:03 | [diff] [blame] | 1783 | TestGroupId("a"), |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1784 | ClientSocketPool::SocketParams::CreateForHttpForTesting(), absl::nullopt, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1785 | LOWEST, SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 870e19ab | 2019-04-23 16:23:03 | [diff] [blame] | 1786 | nested_callback->callback(), ClientSocketPool::ProxyAuthCallback(), pool, |
| 1787 | NetLogWithSource()); |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1788 | if (rv != ERR_IO_PENDING) { |
| 1789 | DCHECK_EQ(TestConnectJob::kMockJob, next_job_type); |
Bence Béky | a4a5093 | 2018-08-10 13:39:41 | [diff] [blame] | 1790 | nested_callback->callback().Run(rv); |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1791 | } else { |
| 1792 | DCHECK_EQ(TestConnectJob::kMockPendingJob, next_job_type); |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1793 | } |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1794 | } |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1795 | |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1796 | // Tests the case where a second socket is requested in a completion callback, |
| 1797 | // and the second socket connects asynchronously. Reuses the same |
| 1798 | // ClientSocketHandle for the second socket, after disconnecting the first. |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 1799 | TEST_F(ClientSocketPoolBaseTest, RequestPendingJobTwice) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1800 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1801 | |
[email protected] | 0b7648c | 2009-07-06 20:14:01 | [diff] [blame] | 1802 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
[email protected] | a512f598 | 2009-08-18 16:01:06 | [diff] [blame] | 1803 | ClientSocketHandle handle; |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1804 | TestCompletionCallback second_result_callback; |
| 1805 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1806 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Paul Jensen | 8d6f87ec | 2018-01-13 00:46:54 | [diff] [blame] | 1807 | ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1808 | base::BindOnce(&RequestSocketOnComplete, &handle, pool_.get(), |
| 1809 | connect_job_factory_, TestConnectJob::kMockPendingJob, |
| 1810 | &second_result_callback), |
| 1811 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1812 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1813 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1814 | EXPECT_THAT(second_result_callback.WaitForResult(), IsOk()); |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 1815 | } |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1816 | |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1817 | // Tests the case where a second socket is requested in a completion callback, |
| 1818 | // and the second socket connects synchronously. Reuses the same |
| 1819 | // ClientSocketHandle for the second socket, after disconnecting the first. |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 1820 | TEST_F(ClientSocketPoolBaseTest, RequestPendingJobThenSynchronous) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1821 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1822 | |
[email protected] | 0b7648c | 2009-07-06 20:14:01 | [diff] [blame] | 1823 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
[email protected] | a512f598 | 2009-08-18 16:01:06 | [diff] [blame] | 1824 | ClientSocketHandle handle; |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1825 | TestCompletionCallback second_result_callback; |
| 1826 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1827 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Paul Jensen | 8d6f87ec | 2018-01-13 00:46:54 | [diff] [blame] | 1828 | ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1829 | base::BindOnce(&RequestSocketOnComplete, &handle, pool_.get(), |
| 1830 | connect_job_factory_, TestConnectJob::kMockPendingJob, |
| 1831 | &second_result_callback), |
| 1832 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1833 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 1834 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1835 | EXPECT_THAT(second_result_callback.WaitForResult(), IsOk()); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | // Make sure that pending requests get serviced after active requests get |
| 1839 | // cancelled. |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 1840 | TEST_F(ClientSocketPoolBaseTest, CancelActiveRequestWithPendingRequests) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1841 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1842 | |
[email protected] | 0b7648c | 2009-07-06 20:14:01 | [diff] [blame] | 1843 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1844 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1845 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 1846 | IsError(ERR_IO_PENDING)); |
| 1847 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 1848 | IsError(ERR_IO_PENDING)); |
| 1849 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 1850 | IsError(ERR_IO_PENDING)); |
| 1851 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 1852 | IsError(ERR_IO_PENDING)); |
| 1853 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 1854 | IsError(ERR_IO_PENDING)); |
| 1855 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 1856 | IsError(ERR_IO_PENDING)); |
| 1857 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 1858 | IsError(ERR_IO_PENDING)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1859 | |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1860 | // Now, kDefaultMaxSocketsPerGroup requests should be active. |
| 1861 | // Let's cancel them. |
| 1862 | for (int i = 0; i < kDefaultMaxSocketsPerGroup; ++i) { |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1863 | ASSERT_FALSE(request(i)->handle()->is_initialized()); |
| 1864 | request(i)->handle()->Reset(); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1865 | } |
| 1866 | |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1867 | // Let's wait for the rest to complete now. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1868 | for (size_t i = kDefaultMaxSocketsPerGroup; i < requests_size(); ++i) { |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1869 | EXPECT_THAT(request(i)->WaitForResult(), IsOk()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1870 | request(i)->handle()->Reset(); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1871 | } |
| 1872 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1873 | EXPECT_EQ(requests_size() - kDefaultMaxSocketsPerGroup, |
| 1874 | completion_count()); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | // Make sure that pending requests get serviced after active requests fail. |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 1878 | TEST_F(ClientSocketPoolBaseTest, FailingActiveRequestWithPendingRequests) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1879 | const size_t kMaxSockets = 5; |
| 1880 | CreatePool(kMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1881 | |
[email protected] | 0b7648c | 2009-07-06 20:14:01 | [diff] [blame] | 1882 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1883 | |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1884 | const size_t kNumberOfRequests = 2 * kDefaultMaxSocketsPerGroup + 1; |
| 1885 | ASSERT_LE(kNumberOfRequests, kMaxSockets); // Otherwise the test will hang. |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1886 | |
| 1887 | // Queue up all the requests |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1888 | for (size_t i = 0; i < kNumberOfRequests; ++i) |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1889 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 1890 | IsError(ERR_IO_PENDING)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1891 | |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1892 | for (size_t i = 0; i < kNumberOfRequests; ++i) |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1893 | EXPECT_THAT(request(i)->WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1894 | } |
| 1895 | |
mmenke | 9d72fe4 | 2017-05-18 22:36:07 | [diff] [blame] | 1896 | // Make sure that pending requests that complete synchronously get serviced |
| 1897 | // after active requests fail. See https://crbug.com/723748 |
| 1898 | TEST_F(ClientSocketPoolBaseTest, HandleMultipleSyncFailuresAfterAsyncFailure) { |
| 1899 | const size_t kNumberOfRequests = 10; |
| 1900 | const size_t kMaxSockets = 1; |
| 1901 | CreatePool(kMaxSockets, kMaxSockets); |
| 1902 | |
| 1903 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); |
| 1904 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1905 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 1906 | IsError(ERR_IO_PENDING)); |
mmenke | 9d72fe4 | 2017-05-18 22:36:07 | [diff] [blame] | 1907 | |
| 1908 | connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); |
| 1909 | |
| 1910 | // Queue up all the other requests |
| 1911 | for (size_t i = 1; i < kNumberOfRequests; ++i) |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1912 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 1913 | IsError(ERR_IO_PENDING)); |
mmenke | 9d72fe4 | 2017-05-18 22:36:07 | [diff] [blame] | 1914 | |
| 1915 | // Make sure all requests fail, instead of hanging. |
| 1916 | for (size_t i = 0; i < kNumberOfRequests; ++i) |
| 1917 | EXPECT_THAT(request(i)->WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
| 1918 | } |
| 1919 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 1920 | TEST_F(ClientSocketPoolBaseTest, CancelActiveRequestThenRequestSocket) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1921 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 1922 | |
| 1923 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 1924 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1925 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1926 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1927 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1928 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1929 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
| 1930 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1931 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 1932 | |
| 1933 | // Cancel the active request. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1934 | handle.Reset(); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 1935 | |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1936 | rv = handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1937 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1938 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1939 | pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1940 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1941 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 1942 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1943 | EXPECT_FALSE(handle.is_reused()); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 1944 | TestLoadTimingInfoConnectedNotReused(handle); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 1945 | EXPECT_EQ(2, client_socket_factory_.allocation_count()); |
| 1946 | } |
| 1947 | |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 1948 | TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketsForced) { |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 1949 | const char kReason[] = "Really nifty reason"; |
| 1950 | |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 1951 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1952 | ClientSocketHandle handle; |
| 1953 | TestCompletionCallback callback; |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 1954 | int rv = |
| 1955 | handle.Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, SocketTag(), |
| 1956 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
| 1957 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 1958 | NetLogWithSource::Make(NetLogSourceType::NONE)); |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 1959 | EXPECT_THAT(rv, IsOk()); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 1960 | ASSERT_TRUE(handle.socket()); |
| 1961 | NetLogSource source = handle.socket()->NetLog().source(); |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 1962 | handle.Reset(); |
| 1963 | EXPECT_EQ(1, pool_->IdleSocketCount()); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 1964 | pool_->CloseIdleSockets(kReason); |
| 1965 | ExpectSocketClosedWithReason(source, kReason); |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 1966 | } |
| 1967 | |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 1968 | TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketsInGroupForced) { |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 1969 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1970 | TestCompletionCallback callback; |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 1971 | NetLogWithSource net_log_with_source = |
| 1972 | NetLogWithSource::Make(NetLogSourceType::NONE); |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 1973 | ClientSocketHandle handle1; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1974 | int rv = handle1.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1975 | TestGroupId("a"), params_, absl::nullopt, LOWEST, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1976 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 1977 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), net_log_with_source); |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 1978 | EXPECT_THAT(rv, IsOk()); |
| 1979 | ClientSocketHandle handle2; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1980 | rv = handle2.Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1981 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1982 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 1983 | pool_.get(), net_log_with_source); |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 1984 | ClientSocketHandle handle3; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1985 | rv = handle3.Init(TestGroupId("b"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1986 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1987 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 1988 | pool_.get(), net_log_with_source); |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 1989 | EXPECT_THAT(rv, IsOk()); |
| 1990 | handle1.Reset(); |
| 1991 | handle2.Reset(); |
| 1992 | handle3.Reset(); |
| 1993 | EXPECT_EQ(3, pool_->IdleSocketCount()); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 1994 | pool_->CloseIdleSocketsInGroup(TestGroupId("a"), "Very good reason"); |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 1995 | EXPECT_EQ(1, pool_->IdleSocketCount()); |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 1996 | } |
| 1997 | |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 1998 | TEST_F(ClientSocketPoolBaseTest, CleanUpUnusableIdleSockets) { |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 1999 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 2000 | ClientSocketHandle handle; |
| 2001 | TestCompletionCallback callback; |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2002 | NetLogWithSource net_log_with_source = |
| 2003 | NetLogWithSource::Make(NetLogSourceType::NONE); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2004 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2005 | TestGroupId("a"), params_, absl::nullopt, LOWEST, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2006 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2007 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), net_log_with_source); |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 2008 | EXPECT_THAT(rv, IsOk()); |
| 2009 | StreamSocket* socket = handle.socket(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 2010 | ASSERT_TRUE(socket); |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 2011 | handle.Reset(); |
| 2012 | EXPECT_EQ(1, pool_->IdleSocketCount()); |
| 2013 | |
| 2014 | // Disconnect socket now to make the socket unusable. |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 2015 | NetLogSource source = socket->NetLog().source(); |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 2016 | socket->Disconnect(); |
| 2017 | ClientSocketHandle handle2; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2018 | rv = handle2.Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2019 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2020 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2021 | pool_.get(), net_log_with_source); |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 2022 | EXPECT_THAT(rv, IsOk()); |
| 2023 | EXPECT_FALSE(handle2.is_reused()); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 2024 | |
| 2025 | // This is admittedly not an accurate error in this case, but normally code |
| 2026 | // doesn't secretly keep a raw pointers to sockets returned to the socket pool |
| 2027 | // and close them out of band, so discovering an idle socket was closed when |
| 2028 | // trying to reuse it normally means it was closed by the remote side. |
| 2029 | ExpectSocketClosedWithReason( |
| 2030 | source, TransportClientSocketPool::kRemoteSideClosedConnection); |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 2031 | } |
| 2032 | |
[email protected] | 2b7523d | 2009-07-29 20:29:23 | [diff] [blame] | 2033 | // Regression test for http://crbug.com/17985. |
| 2034 | TEST_F(ClientSocketPoolBaseTest, GroupWithPendingRequestsIsNotEmpty) { |
| 2035 | const int kMaxSockets = 3; |
| 2036 | const int kMaxSocketsPerGroup = 2; |
| 2037 | CreatePool(kMaxSockets, kMaxSocketsPerGroup); |
| 2038 | |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 2039 | const RequestPriority kHighPriority = HIGHEST; |
[email protected] | 2b7523d | 2009-07-29 20:29:23 | [diff] [blame] | 2040 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2041 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 2042 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
[email protected] | 2b7523d | 2009-07-29 20:29:23 | [diff] [blame] | 2043 | |
| 2044 | // This is going to be a pending request in an otherwise empty group. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2045 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 2046 | IsError(ERR_IO_PENDING)); |
[email protected] | 2b7523d | 2009-07-29 20:29:23 | [diff] [blame] | 2047 | |
| 2048 | // Reach the maximum socket limit. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2049 | EXPECT_THAT(StartRequest(TestGroupId("b"), DEFAULT_PRIORITY), IsOk()); |
[email protected] | 2b7523d | 2009-07-29 20:29:23 | [diff] [blame] | 2050 | |
| 2051 | // Create a stalled group with high priorities. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2052 | EXPECT_THAT(StartRequest(TestGroupId("c"), kHighPriority), |
| 2053 | IsError(ERR_IO_PENDING)); |
| 2054 | EXPECT_THAT(StartRequest(TestGroupId("c"), kHighPriority), |
| 2055 | IsError(ERR_IO_PENDING)); |
[email protected] | 2b7523d | 2009-07-29 20:29:23 | [diff] [blame] | 2056 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2057 | // Release the first two sockets from TestGroupId("a"). Because this is a |
| 2058 | // keepalive, the first release will unblock the pending request for |
| 2059 | // TestGroupId("a"). The second release will unblock a request for "c", |
| 2060 | // because it is the next high priority socket. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2061 | EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE)); |
| 2062 | EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE)); |
[email protected] | 2b7523d | 2009-07-29 20:29:23 | [diff] [blame] | 2063 | |
| 2064 | // Closing idle sockets should not get us into trouble, but in the bug |
| 2065 | // we were hitting a CHECK here. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2066 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 2067 | pool_->CloseIdleSockets("Very good reason"); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 2068 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 2069 | // Run the released socket wakeups. |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 2070 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2b7523d | 2009-07-29 20:29:23 | [diff] [blame] | 2071 | } |
| 2072 | |
[email protected] | 4d3b05d | 2010-01-27 21:27:29 | [diff] [blame] | 2073 | TEST_F(ClientSocketPoolBaseTest, BasicAsynchronous) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 2074 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2075 | |
| 2076 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2077 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2078 | TestCompletionCallback callback; |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2079 | NetLogWithSource net_log_with_source = |
| 2080 | NetLogWithSource::Make(NetLogSourceType::NONE); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2081 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2082 | TestGroupId("a"), params_, absl::nullopt, LOWEST, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2083 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2084 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), net_log_with_source); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2085 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2086 | EXPECT_EQ(LOAD_STATE_CONNECTING, |
| 2087 | pool_->GetLoadState(TestGroupId("a"), &handle)); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 2088 | TestLoadTimingInfoNotConnected(handle); |
| 2089 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2090 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2091 | EXPECT_TRUE(handle.is_initialized()); |
| 2092 | EXPECT_TRUE(handle.socket()); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 2093 | TestLoadTimingInfoConnectedNotReused(handle); |
| 2094 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2095 | handle.Reset(); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 2096 | TestLoadTimingInfoNotConnected(handle); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 2097 | |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2098 | auto entries = |
| 2099 | net_log_observer_.GetEntriesForSource(net_log_with_source.source()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2100 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2101 | EXPECT_EQ(5u, entries.size()); |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 2102 | EXPECT_TRUE(LogContainsEvent( |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2103 | entries, 0, NetLogEventType::TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2104 | NetLogEventPhase::NONE)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2105 | EXPECT_TRUE(LogContainsBeginEvent(entries, 1, NetLogEventType::SOCKET_POOL)); |
| 2106 | EXPECT_TRUE(LogContainsEvent( |
| 2107 | entries, 2, NetLogEventType::SOCKET_POOL_BOUND_TO_CONNECT_JOB, |
| 2108 | NetLogEventPhase::NONE)); |
| 2109 | EXPECT_TRUE(LogContainsEvent(entries, 3, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2110 | NetLogEventType::SOCKET_POOL_BOUND_TO_SOCKET, |
| 2111 | NetLogEventPhase::NONE)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2112 | EXPECT_TRUE(LogContainsEndEvent(entries, 4, NetLogEventType::SOCKET_POOL)); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2113 | } |
| 2114 | |
[email protected] | 4d3b05d | 2010-01-27 21:27:29 | [diff] [blame] | 2115 | TEST_F(ClientSocketPoolBaseTest, |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2116 | InitConnectionAsynchronousFailure) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 2117 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2118 | |
| 2119 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2120 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2121 | TestCompletionCallback callback; |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2122 | NetLogWithSource net_log_with_source = |
| 2123 | NetLogWithSource::Make(NetLogSourceType::NONE); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2124 | // Set the additional error state members to ensure that they get cleared. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2125 | handle.set_is_ssl_error(true); |
Matt Menke | 39b7c5a | 2019-04-10 19:47:51 | [diff] [blame] | 2126 | handle.set_ssl_cert_request_info(base::MakeRefCounted<SSLCertRequestInfo>()); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2127 | EXPECT_EQ( |
| 2128 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2129 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2130 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2131 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2132 | pool_.get(), net_log_with_source)); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2133 | EXPECT_EQ(LOAD_STATE_CONNECTING, |
| 2134 | pool_->GetLoadState(TestGroupId("a"), &handle)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2135 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2136 | EXPECT_FALSE(handle.is_ssl_error()); |
Matt Menke | 39b7c5a | 2019-04-10 19:47:51 | [diff] [blame] | 2137 | EXPECT_FALSE(handle.ssl_cert_request_info()); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 2138 | |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2139 | auto entries = |
| 2140 | net_log_observer_.GetEntriesForSource(net_log_with_source.source()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2141 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2142 | EXPECT_EQ(4u, entries.size()); |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 2143 | EXPECT_TRUE(LogContainsEvent( |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2144 | entries, 0, NetLogEventType::TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2145 | NetLogEventPhase::NONE)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2146 | EXPECT_TRUE(LogContainsBeginEvent(entries, 1, NetLogEventType::SOCKET_POOL)); |
| 2147 | EXPECT_TRUE(LogContainsEvent( |
| 2148 | entries, 2, NetLogEventType::SOCKET_POOL_BOUND_TO_CONNECT_JOB, |
| 2149 | NetLogEventPhase::NONE)); |
| 2150 | EXPECT_TRUE(LogContainsEndEvent(entries, 3, NetLogEventType::SOCKET_POOL)); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2151 | } |
| 2152 | |
mmenke | 6be122f | 2015-03-09 22:22:47 | [diff] [blame] | 2153 | // Check that an async ConnectJob failure does not result in creation of a new |
| 2154 | // ConnectJob when there's another pending request also waiting on its own |
| 2155 | // ConnectJob. See http://crbug.com/463960. |
| 2156 | TEST_F(ClientSocketPoolBaseTest, AsyncFailureWithPendingRequestWithJob) { |
| 2157 | CreatePool(2, 2); |
| 2158 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); |
| 2159 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2160 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 2161 | IsError(ERR_IO_PENDING)); |
| 2162 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 2163 | IsError(ERR_IO_PENDING)); |
mmenke | 6be122f | 2015-03-09 22:22:47 | [diff] [blame] | 2164 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2165 | EXPECT_THAT(request(0)->WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
| 2166 | EXPECT_THAT(request(1)->WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
mmenke | 6be122f | 2015-03-09 22:22:47 | [diff] [blame] | 2167 | |
| 2168 | EXPECT_EQ(2, client_socket_factory_.allocation_count()); |
| 2169 | } |
| 2170 | |
[email protected] | 4d3b05d | 2010-01-27 21:27:29 | [diff] [blame] | 2171 | TEST_F(ClientSocketPoolBaseTest, TwoRequestsCancelOne) { |
[email protected] | b22b516 | 2010-03-16 07:53:10 | [diff] [blame] | 2172 | // TODO(eroman): Add back the log expectations! Removed them because the |
| 2173 | // ordering is difficult, and some may fire during destructor. |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 2174 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2175 | |
| 2176 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2177 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2178 | TestCompletionCallback callback; |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2179 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2180 | TestCompletionCallback callback2; |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2181 | |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2182 | EXPECT_EQ( |
| 2183 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2184 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2185 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2186 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2187 | pool_.get(), NetLogWithSource())); |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2188 | RecordingNetLogObserver log2; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 2189 | EXPECT_EQ( |
| 2190 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2191 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2192 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2193 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2194 | pool_.get(), NetLogWithSource())); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2195 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2196 | handle.Reset(); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2197 | |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 2198 | |
| 2199 | // At this point, request 2 is just waiting for the connect job to finish. |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 2200 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2201 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2202 | handle2.Reset(); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 2203 | |
| 2204 | // Now request 2 has actually finished. |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 2205 | // TODO(eroman): Add back log expectations. |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2206 | } |
| 2207 | |
[email protected] | 4d3b05d | 2010-01-27 21:27:29 | [diff] [blame] | 2208 | TEST_F(ClientSocketPoolBaseTest, CancelRequestLimitsJobs) { |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 2209 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 2210 | |
[email protected] | 17a0c6c | 2009-08-04 00:07:04 | [diff] [blame] | 2211 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 2212 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2213 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(ERR_IO_PENDING)); |
| 2214 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOW), IsError(ERR_IO_PENDING)); |
| 2215 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsError(ERR_IO_PENDING)); |
| 2216 | EXPECT_THAT(StartRequest(TestGroupId("a"), HIGHEST), IsError(ERR_IO_PENDING)); |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 2217 | |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 2218 | EXPECT_EQ(kDefaultMaxSocketsPerGroup, |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2219 | static_cast<int>( |
| 2220 | pool_->NumConnectJobsInGroupForTesting(TestGroupId("a")))); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2221 | (*requests())[2]->handle()->Reset(); |
| 2222 | (*requests())[3]->handle()->Reset(); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 2223 | EXPECT_EQ(kDefaultMaxSocketsPerGroup, |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2224 | static_cast<int>( |
| 2225 | pool_->NumConnectJobsInGroupForTesting(TestGroupId("a")))); |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 2226 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2227 | (*requests())[1]->handle()->Reset(); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 2228 | EXPECT_EQ(kDefaultMaxSocketsPerGroup, |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2229 | static_cast<int>( |
| 2230 | pool_->NumConnectJobsInGroupForTesting(TestGroupId("a")))); |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 2231 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2232 | (*requests())[0]->handle()->Reset(); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 2233 | EXPECT_EQ(kDefaultMaxSocketsPerGroup, |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2234 | static_cast<int>( |
| 2235 | pool_->NumConnectJobsInGroupForTesting(TestGroupId("a")))); |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 2236 | } |
| 2237 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2238 | // When requests and ConnectJobs are not coupled, the request will get serviced |
| 2239 | // by whatever comes first. |
[email protected] | 4d3b05d | 2010-01-27 21:27:29 | [diff] [blame] | 2240 | TEST_F(ClientSocketPoolBaseTest, ReleaseSockets) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 2241 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2242 | |
| 2243 | // Start job 1 (async OK) |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 2244 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2245 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2246 | std::vector<TestSocketRequest*> request_order; |
| 2247 | size_t completion_count; // unused |
| 2248 | TestSocketRequest req1(&request_order, &completion_count); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2249 | int rv = req1.handle()->Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2250 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2251 | ClientSocketPool::RespectLimits::ENABLED, req1.callback(), |
| 2252 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2253 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2254 | EXPECT_THAT(req1.WaitForResult(), IsOk()); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2255 | |
| 2256 | // Job 1 finished OK. Start job 2 (also async OK). Request 3 is pending |
| 2257 | // without a job. |
| 2258 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 2259 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2260 | TestSocketRequest req2(&request_order, &completion_count); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2261 | rv = req2.handle()->Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2262 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2263 | ClientSocketPool::RespectLimits::ENABLED, req2.callback(), |
| 2264 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2265 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2266 | TestSocketRequest req3(&request_order, &completion_count); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2267 | rv = req3.handle()->Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2268 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2269 | ClientSocketPool::RespectLimits::ENABLED, req3.callback(), |
| 2270 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2271 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2272 | |
| 2273 | // Both Requests 2 and 3 are pending. We release socket 1 which should |
| 2274 | // service request 2. Request 3 should still be waiting. |
[email protected] | a6c59f6 | 2009-07-29 16:33:33 | [diff] [blame] | 2275 | req1.handle()->Reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 2276 | // Run the released socket wakeups. |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 2277 | base::RunLoop().RunUntilIdle(); |
[email protected] | a6c59f6 | 2009-07-29 16:33:33 | [diff] [blame] | 2278 | ASSERT_TRUE(req2.handle()->socket()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2279 | EXPECT_THAT(req2.WaitForResult(), IsOk()); |
[email protected] | a6c59f6 | 2009-07-29 16:33:33 | [diff] [blame] | 2280 | EXPECT_FALSE(req3.handle()->socket()); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2281 | |
| 2282 | // Signal job 2, which should service request 3. |
| 2283 | |
| 2284 | client_socket_factory_.SignalJobs(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2285 | EXPECT_THAT(req3.WaitForResult(), IsOk()); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2286 | |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 2287 | ASSERT_EQ(3u, request_order.size()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2288 | EXPECT_EQ(&req1, request_order[0]); |
| 2289 | EXPECT_EQ(&req2, request_order[1]); |
| 2290 | EXPECT_EQ(&req3, request_order[2]); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2291 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | // The requests are not coupled to the jobs. So, the requests should finish in |
| 2295 | // their priority / insertion order. |
[email protected] | 4d3b05d | 2010-01-27 21:27:29 | [diff] [blame] | 2296 | TEST_F(ClientSocketPoolBaseTest, PendingJobCompletionOrder) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 2297 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2298 | // First two jobs are async. |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 2299 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2300 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2301 | std::vector<TestSocketRequest*> request_order; |
| 2302 | size_t completion_count; // unused |
| 2303 | TestSocketRequest req1(&request_order, &completion_count); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2304 | int rv = req1.handle()->Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2305 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2306 | ClientSocketPool::RespectLimits::ENABLED, req1.callback(), |
| 2307 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2308 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2309 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2310 | TestSocketRequest req2(&request_order, &completion_count); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2311 | rv = req2.handle()->Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2312 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2313 | ClientSocketPool::RespectLimits::ENABLED, req2.callback(), |
| 2314 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2315 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2316 | |
| 2317 | // The pending job is sync. |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 2318 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2319 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2320 | TestSocketRequest req3(&request_order, &completion_count); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2321 | rv = req3.handle()->Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2322 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2323 | ClientSocketPool::RespectLimits::ENABLED, req3.callback(), |
| 2324 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2325 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2326 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2327 | EXPECT_THAT(req1.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
| 2328 | EXPECT_THAT(req2.WaitForResult(), IsOk()); |
| 2329 | EXPECT_THAT(req3.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2330 | |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 2331 | ASSERT_EQ(3u, request_order.size()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2332 | EXPECT_EQ(&req1, request_order[0]); |
| 2333 | EXPECT_EQ(&req2, request_order[1]); |
| 2334 | EXPECT_EQ(&req3, request_order[2]); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2335 | } |
| 2336 | |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2337 | // Test GetLoadState in the case there's only one socket request. |
| 2338 | TEST_F(ClientSocketPoolBaseTest, LoadStateOneRequest) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 2339 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2340 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2341 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2342 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2343 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2344 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2345 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2346 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
| 2347 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2348 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2349 | EXPECT_EQ(LOAD_STATE_CONNECTING, handle.GetLoadState()); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2350 | |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2351 | client_socket_factory_.SetJobLoadState(0, LOAD_STATE_SSL_HANDSHAKE); |
| 2352 | EXPECT_EQ(LOAD_STATE_SSL_HANDSHAKE, handle.GetLoadState()); |
| 2353 | |
| 2354 | // No point in completing the connection, since ClientSocketHandles only |
| 2355 | // expect the LoadState to be checked while connecting. |
| 2356 | } |
| 2357 | |
| 2358 | // Test GetLoadState in the case there are two socket requests. |
| 2359 | TEST_F(ClientSocketPoolBaseTest, LoadStateTwoRequests) { |
| 2360 | CreatePool(2, 2); |
| 2361 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 2362 | |
| 2363 | ClientSocketHandle handle; |
| 2364 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2365 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2366 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2367 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
| 2368 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2369 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
haavardm | 835c1d6 | 2015-04-22 08:18:00 | [diff] [blame] | 2370 | client_socket_factory_.SetJobLoadState(0, LOAD_STATE_RESOLVING_HOST); |
| 2371 | |
| 2372 | ClientSocketHandle handle2; |
| 2373 | TestCompletionCallback callback2; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2374 | rv = handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2375 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2376 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2377 | pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2378 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
haavardm | 835c1d6 | 2015-04-22 08:18:00 | [diff] [blame] | 2379 | client_socket_factory_.SetJobLoadState(1, LOAD_STATE_RESOLVING_HOST); |
| 2380 | |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 2381 | // Each handle should reflect the state of its own job. |
haavardm | 835c1d6 | 2015-04-22 08:18:00 | [diff] [blame] | 2382 | EXPECT_EQ(LOAD_STATE_RESOLVING_HOST, handle.GetLoadState()); |
| 2383 | EXPECT_EQ(LOAD_STATE_RESOLVING_HOST, handle2.GetLoadState()); |
| 2384 | |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 2385 | // Update the state of the first job. |
haavardm | 835c1d6 | 2015-04-22 08:18:00 | [diff] [blame] | 2386 | client_socket_factory_.SetJobLoadState(0, LOAD_STATE_CONNECTING); |
| 2387 | |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 2388 | // Only the state of the first request should have changed. |
haavardm | 835c1d6 | 2015-04-22 08:18:00 | [diff] [blame] | 2389 | EXPECT_EQ(LOAD_STATE_CONNECTING, handle.GetLoadState()); |
haavardm | 835c1d6 | 2015-04-22 08:18:00 | [diff] [blame] | 2390 | EXPECT_EQ(LOAD_STATE_RESOLVING_HOST, handle2.GetLoadState()); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 2391 | |
| 2392 | // Update the state of the second job. |
| 2393 | client_socket_factory_.SetJobLoadState(1, LOAD_STATE_SSL_HANDSHAKE); |
| 2394 | |
| 2395 | // Only the state of the second request should have changed. |
| 2396 | EXPECT_EQ(LOAD_STATE_CONNECTING, handle.GetLoadState()); |
| 2397 | EXPECT_EQ(LOAD_STATE_SSL_HANDSHAKE, handle2.GetLoadState()); |
| 2398 | |
| 2399 | // Second job connects and the first request gets the socket. The |
| 2400 | // second handle switches to the state of the remaining ConnectJob. |
| 2401 | client_socket_factory_.SignalJob(1); |
| 2402 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 2403 | EXPECT_EQ(LOAD_STATE_CONNECTING, handle2.GetLoadState()); |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2404 | } |
| 2405 | |
| 2406 | // Test GetLoadState in the case the per-group limit is reached. |
| 2407 | TEST_F(ClientSocketPoolBaseTest, LoadStateGroupLimit) { |
| 2408 | CreatePool(2, 1); |
| 2409 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 2410 | |
| 2411 | ClientSocketHandle handle; |
| 2412 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2413 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2414 | TestGroupId("a"), params_, absl::nullopt, MEDIUM, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2415 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
| 2416 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2417 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2418 | EXPECT_EQ(LOAD_STATE_CONNECTING, handle.GetLoadState()); |
| 2419 | |
| 2420 | // Request another socket from the same pool, buth with a higher priority. |
| 2421 | // The first request should now be stalled at the socket group limit. |
| 2422 | ClientSocketHandle handle2; |
| 2423 | TestCompletionCallback callback2; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2424 | rv = handle2.Init(TestGroupId("a"), params_, absl::nullopt, HIGHEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2425 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2426 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2427 | pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2428 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2429 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_AVAILABLE_SOCKET, handle.GetLoadState()); |
| 2430 | EXPECT_EQ(LOAD_STATE_CONNECTING, handle2.GetLoadState()); |
| 2431 | |
| 2432 | // The first handle should remain stalled as the other socket goes through |
| 2433 | // the connect process. |
| 2434 | |
| 2435 | client_socket_factory_.SetJobLoadState(0, LOAD_STATE_SSL_HANDSHAKE); |
| 2436 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_AVAILABLE_SOCKET, handle.GetLoadState()); |
| 2437 | EXPECT_EQ(LOAD_STATE_SSL_HANDSHAKE, handle2.GetLoadState()); |
| 2438 | |
| 2439 | client_socket_factory_.SignalJob(0); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2440 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2441 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_AVAILABLE_SOCKET, handle.GetLoadState()); |
| 2442 | |
| 2443 | // Closing the second socket should cause the stalled handle to finally get a |
| 2444 | // ConnectJob. |
| 2445 | handle2.socket()->Disconnect(); |
| 2446 | handle2.Reset(); |
| 2447 | EXPECT_EQ(LOAD_STATE_CONNECTING, handle.GetLoadState()); |
| 2448 | } |
| 2449 | |
| 2450 | // Test GetLoadState in the case the per-pool limit is reached. |
| 2451 | TEST_F(ClientSocketPoolBaseTest, LoadStatePoolLimit) { |
| 2452 | CreatePool(2, 2); |
| 2453 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 2454 | |
| 2455 | ClientSocketHandle handle; |
| 2456 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2457 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2458 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2459 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
| 2460 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2461 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2462 | |
| 2463 | // Request for socket from another pool. |
| 2464 | ClientSocketHandle handle2; |
| 2465 | TestCompletionCallback callback2; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2466 | rv = handle2.Init(TestGroupId("b"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2467 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2468 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2469 | pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2470 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2471 | |
| 2472 | // Request another socket from the first pool. Request should stall at the |
| 2473 | // socket pool limit. |
| 2474 | ClientSocketHandle handle3; |
| 2475 | TestCompletionCallback callback3; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2476 | rv = handle3.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2477 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2478 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2479 | pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2480 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2481 | |
| 2482 | // The third handle should remain stalled as the other sockets in its group |
| 2483 | // goes through the connect process. |
| 2484 | |
| 2485 | EXPECT_EQ(LOAD_STATE_CONNECTING, handle.GetLoadState()); |
| 2486 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_STALLED_SOCKET_POOL, handle3.GetLoadState()); |
| 2487 | |
| 2488 | client_socket_factory_.SetJobLoadState(0, LOAD_STATE_SSL_HANDSHAKE); |
| 2489 | EXPECT_EQ(LOAD_STATE_SSL_HANDSHAKE, handle.GetLoadState()); |
| 2490 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_STALLED_SOCKET_POOL, handle3.GetLoadState()); |
| 2491 | |
| 2492 | client_socket_factory_.SignalJob(0); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2493 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2494 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_STALLED_SOCKET_POOL, handle3.GetLoadState()); |
| 2495 | |
| 2496 | // Closing a socket should allow the stalled handle to finally get a new |
| 2497 | // ConnectJob. |
| 2498 | handle.socket()->Disconnect(); |
| 2499 | handle.Reset(); |
| 2500 | EXPECT_EQ(LOAD_STATE_CONNECTING, handle3.GetLoadState()); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2501 | } |
| 2502 | |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 2503 | TEST_F(ClientSocketPoolBaseTest, CertError) { |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2504 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 2505 | connect_job_factory_->set_job_type(TestConnectJob::kMockCertErrorJob); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2506 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2507 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2508 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2509 | EXPECT_EQ( |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 2510 | ERR_CERT_COMMON_NAME_INVALID, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2511 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2512 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2513 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2514 | pool_.get(), NetLogWithSource())); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2515 | EXPECT_TRUE(handle.is_initialized()); |
| 2516 | EXPECT_TRUE(handle.socket()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2517 | } |
| 2518 | |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 2519 | TEST_F(ClientSocketPoolBaseTest, AsyncCertError) { |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2520 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 2521 | |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 2522 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingCertErrorJob); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2523 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2524 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2525 | EXPECT_EQ( |
| 2526 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2527 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2528 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2529 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2530 | pool_.get(), NetLogWithSource())); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2531 | EXPECT_EQ(LOAD_STATE_CONNECTING, |
| 2532 | pool_->GetLoadState(TestGroupId("a"), &handle)); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 2533 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CERT_COMMON_NAME_INVALID)); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2534 | EXPECT_TRUE(handle.is_initialized()); |
| 2535 | EXPECT_TRUE(handle.socket()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2536 | } |
| 2537 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2538 | TEST_F(ClientSocketPoolBaseTest, AdditionalErrorStateSynchronous) { |
| 2539 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 2540 | connect_job_factory_->set_job_type( |
| 2541 | TestConnectJob::kMockAdditionalErrorStateJob); |
| 2542 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2543 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2544 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2545 | EXPECT_EQ( |
| 2546 | ERR_CONNECTION_FAILED, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2547 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2548 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2549 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2550 | pool_.get(), NetLogWithSource())); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2551 | EXPECT_FALSE(handle.is_initialized()); |
| 2552 | EXPECT_FALSE(handle.socket()); |
| 2553 | EXPECT_TRUE(handle.is_ssl_error()); |
Matt Menke | 39b7c5a | 2019-04-10 19:47:51 | [diff] [blame] | 2554 | EXPECT_TRUE(handle.ssl_cert_request_info()); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2555 | } |
| 2556 | |
| 2557 | TEST_F(ClientSocketPoolBaseTest, AdditionalErrorStateAsynchronous) { |
| 2558 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 2559 | |
| 2560 | connect_job_factory_->set_job_type( |
| 2561 | TestConnectJob::kMockPendingAdditionalErrorStateJob); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2562 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2563 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2564 | EXPECT_EQ( |
| 2565 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2566 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2567 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2568 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2569 | pool_.get(), NetLogWithSource())); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2570 | EXPECT_EQ(LOAD_STATE_CONNECTING, |
| 2571 | pool_->GetLoadState(TestGroupId("a"), &handle)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2572 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2573 | EXPECT_FALSE(handle.is_initialized()); |
| 2574 | EXPECT_FALSE(handle.socket()); |
| 2575 | EXPECT_TRUE(handle.is_ssl_error()); |
Matt Menke | 39b7c5a | 2019-04-10 19:47:51 | [diff] [blame] | 2576 | EXPECT_TRUE(handle.ssl_cert_request_info()); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2577 | } |
| 2578 | |
martijn | 003cd61 | 2016-05-19 22:24:38 | [diff] [blame] | 2579 | // Make sure we can reuse sockets. |
| 2580 | TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSocketsReuse) { |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2581 | CreatePoolWithIdleTimeouts( |
| 2582 | kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2583 | base::TimeDelta(), // Time out unused sockets immediately. |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 2584 | base::Days(1)); // Don't time out used sockets. |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2585 | |
| 2586 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 2587 | |
| 2588 | ClientSocketHandle handle; |
| 2589 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2590 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2591 | TestGroupId("a"), params_, absl::nullopt, LOWEST, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2592 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
| 2593 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2594 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2595 | EXPECT_EQ(LOAD_STATE_CONNECTING, |
| 2596 | pool_->GetLoadState(TestGroupId("a"), &handle)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2597 | ASSERT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2598 | |
| 2599 | // Use and release the socket. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2600 | EXPECT_EQ(1, handle.socket()->Write(nullptr, 1, CompletionOnceCallback(), |
Ramin Halavati | 0a08cc8 | 2018-02-06 07:46:38 | [diff] [blame] | 2601 | TRAFFIC_ANNOTATION_FOR_TESTS)); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 2602 | TestLoadTimingInfoConnectedNotReused(handle); |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2603 | handle.Reset(); |
| 2604 | |
| 2605 | // Should now have one idle socket. |
| 2606 | ASSERT_EQ(1, pool_->IdleSocketCount()); |
| 2607 | |
| 2608 | // Request a new socket. This should reuse the old socket and complete |
| 2609 | // synchronously. |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2610 | NetLogWithSource net_log_with_source = |
| 2611 | NetLogWithSource::Make(NetLogSourceType::NONE); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2612 | rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2613 | TestGroupId("a"), params_, absl::nullopt, LOWEST, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2614 | ClientSocketPool::RespectLimits::ENABLED, CompletionOnceCallback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2615 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), net_log_with_source); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2616 | ASSERT_THAT(rv, IsOk()); |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2617 | EXPECT_TRUE(handle.is_reused()); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 2618 | TestLoadTimingInfoConnectedReused(handle); |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2619 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2620 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2621 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2622 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2623 | |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2624 | auto entries = |
| 2625 | net_log_observer_.GetEntriesForSource(net_log_with_source.source()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2626 | EXPECT_TRUE(LogContainsEvent( |
| 2627 | entries, 0, NetLogEventType::TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET, |
| 2628 | NetLogEventPhase::NONE)); |
| 2629 | EXPECT_TRUE(LogContainsBeginEvent(entries, 1, NetLogEventType::SOCKET_POOL)); |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2630 | EXPECT_TRUE(LogContainsEntryWithType( |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2631 | entries, 2, NetLogEventType::SOCKET_POOL_REUSED_AN_EXISTING_SOCKET)); |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2632 | } |
| 2633 | |
martijn | 003cd61 | 2016-05-19 22:24:38 | [diff] [blame] | 2634 | // Make sure we cleanup old unused sockets. |
Eric Roman | b49715e | 2018-04-24 22:41:17 | [diff] [blame] | 2635 | TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSocketsNoReuse) { |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2636 | CreatePoolWithIdleTimeouts( |
| 2637 | kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, |
| 2638 | base::TimeDelta(), // Time out unused sockets immediately |
| 2639 | base::TimeDelta()); // Time out used sockets immediately |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2640 | |
| 2641 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 2642 | |
| 2643 | // Startup two mock pending connect jobs, which will sit in the MessageLoop. |
| 2644 | |
| 2645 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2646 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2647 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2648 | TestGroupId("a"), params_, absl::nullopt, LOWEST, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2649 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
| 2650 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2651 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2652 | EXPECT_EQ(LOAD_STATE_CONNECTING, |
| 2653 | pool_->GetLoadState(TestGroupId("a"), &handle)); |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2654 | |
| 2655 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2656 | TestCompletionCallback callback2; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2657 | rv = handle2.Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2658 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2659 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2660 | pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2661 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2662 | EXPECT_EQ(LOAD_STATE_CONNECTING, |
| 2663 | pool_->GetLoadState(TestGroupId("a"), &handle2)); |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2664 | |
| 2665 | // Cancel one of the requests. Wait for the other, which will get the first |
| 2666 | // job. Release the socket. Run the loop again to make sure the second |
| 2667 | // socket is sitting idle and the first one is released (since ReleaseSocket() |
| 2668 | // just posts a DoReleaseSocket() task). |
| 2669 | |
| 2670 | handle.Reset(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2671 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 2672 | // Get the NetLogSource for the socket, so the time out reason can be checked |
| 2673 | // at the end of the test. |
| 2674 | NetLogSource net_log_source2 = handle2.socket()->NetLog().source(); |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2675 | // Use the socket. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2676 | EXPECT_EQ(1, handle2.socket()->Write(nullptr, 1, CompletionOnceCallback(), |
Ramin Halavati | 0a08cc8 | 2018-02-06 07:46:38 | [diff] [blame] | 2677 | TRAFFIC_ANNOTATION_FOR_TESTS)); |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2678 | handle2.Reset(); |
| 2679 | |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2680 | // We post all of our delayed tasks with a 2ms delay. I.e. they don't |
| 2681 | // actually become pending until 2ms after they have been created. In order |
| 2682 | // to flush all tasks, we need to wait so that we know there are no |
| 2683 | // soon-to-be-pending tasks waiting. |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 2684 | FastForwardBy(base::Milliseconds(10)); |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2685 | |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2686 | // Both sockets should now be idle. |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2687 | ASSERT_EQ(2, pool_->IdleSocketCount()); |
| 2688 | |
| 2689 | // Request a new socket. This should cleanup the unused and timed out ones. |
| 2690 | // A new socket will be created rather than reusing the idle one. |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2691 | NetLogWithSource net_log_with_source = |
| 2692 | NetLogWithSource::Make(NetLogSourceType::NONE); |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2693 | TestCompletionCallback callback3; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2694 | rv = handle.Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2695 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2696 | callback3.callback(), ClientSocketPool::ProxyAuthCallback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2697 | pool_.get(), net_log_with_source); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2698 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2699 | ASSERT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2700 | EXPECT_FALSE(handle.is_reused()); |
| 2701 | |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2702 | // Make sure the idle socket is closed. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2703 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2704 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2705 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2706 | |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2707 | auto entries = |
| 2708 | net_log_observer_.GetEntriesForSource(net_log_with_source.source()); |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2709 | EXPECT_FALSE(LogContainsEntryWithType( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2710 | entries, 1, NetLogEventType::SOCKET_POOL_REUSED_AN_EXISTING_SOCKET)); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 2711 | ExpectSocketClosedWithReason( |
| 2712 | net_log_source2, TransportClientSocketPool::kIdleTimeLimitExpired); |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2713 | } |
| 2714 | |
[email protected] | 2041cf34 | 2010-02-19 03:15:59 | [diff] [blame] | 2715 | // Make sure that we process all pending requests even when we're stalling |
[email protected] | 4f2abec | 2010-02-03 18:10:16 | [diff] [blame] | 2716 | // because of multiple releasing disconnected sockets. |
| 2717 | TEST_F(ClientSocketPoolBaseTest, MultipleReleasingDisconnectedSockets) { |
| 2718 | CreatePoolWithIdleTimeouts( |
| 2719 | kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, |
| 2720 | base::TimeDelta(), // Time out unused sockets immediately. |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 2721 | base::Days(1)); // Don't time out used sockets. |
[email protected] | 4f2abec | 2010-02-03 18:10:16 | [diff] [blame] | 2722 | |
| 2723 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 2724 | |
| 2725 | // Startup 4 connect jobs. Two of them will be pending. |
| 2726 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2727 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2728 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2729 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2730 | TestGroupId("a"), params_, absl::nullopt, LOWEST, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2731 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
| 2732 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2733 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 4f2abec | 2010-02-03 18:10:16 | [diff] [blame] | 2734 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2735 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2736 | TestCompletionCallback callback2; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2737 | rv = handle2.Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2738 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2739 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2740 | pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2741 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 4f2abec | 2010-02-03 18:10:16 | [diff] [blame] | 2742 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2743 | ClientSocketHandle handle3; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2744 | TestCompletionCallback callback3; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2745 | rv = handle3.Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2746 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2747 | callback3.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2748 | pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2749 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4f2abec | 2010-02-03 18:10:16 | [diff] [blame] | 2750 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2751 | ClientSocketHandle handle4; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2752 | TestCompletionCallback callback4; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2753 | rv = handle4.Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2754 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2755 | callback4.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2756 | pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2757 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4f2abec | 2010-02-03 18:10:16 | [diff] [blame] | 2758 | |
| 2759 | // Release two disconnected sockets. |
| 2760 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2761 | handle.socket()->Disconnect(); |
| 2762 | handle.Reset(); |
| 2763 | handle2.socket()->Disconnect(); |
| 2764 | handle2.Reset(); |
[email protected] | 4f2abec | 2010-02-03 18:10:16 | [diff] [blame] | 2765 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2766 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2767 | EXPECT_FALSE(handle3.is_reused()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2768 | EXPECT_THAT(callback4.WaitForResult(), IsOk()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2769 | EXPECT_FALSE(handle4.is_reused()); |
[email protected] | 4f2abec | 2010-02-03 18:10:16 | [diff] [blame] | 2770 | } |
| 2771 | |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 2772 | // Regression test for http://crbug.com/42267. |
| 2773 | // When DoReleaseSocket() is processed for one socket, it is blocked because the |
| 2774 | // other stalled groups all have releasing sockets, so no progress can be made. |
| 2775 | TEST_F(ClientSocketPoolBaseTest, SocketLimitReleasingSockets) { |
| 2776 | CreatePoolWithIdleTimeouts( |
| 2777 | 4 /* socket limit */, 4 /* socket limit per group */, |
| 2778 | base::TimeDelta(), // Time out unused sockets immediately. |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 2779 | base::Days(1)); // Don't time out used sockets. |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 2780 | |
| 2781 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 2782 | |
| 2783 | // Max out the socket limit with 2 per group. |
| 2784 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2785 | ClientSocketHandle handle_a[4]; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2786 | TestCompletionCallback callback_a[4]; |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2787 | ClientSocketHandle handle_b[4]; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2788 | TestCompletionCallback callback_b[4]; |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 2789 | |
| 2790 | for (int i = 0; i < 2; ++i) { |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2791 | EXPECT_EQ(OK, handle_a[i].Init(TestGroupId("a"), params_, absl::nullopt, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2792 | LOWEST, SocketTag(), |
| 2793 | ClientSocketPool::RespectLimits::ENABLED, |
| 2794 | callback_a[i].callback(), |
| 2795 | ClientSocketPool::ProxyAuthCallback(), |
| 2796 | pool_.get(), NetLogWithSource())); |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2797 | EXPECT_EQ(OK, handle_b[i].Init(TestGroupId("b"), params_, absl::nullopt, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2798 | LOWEST, SocketTag(), |
| 2799 | ClientSocketPool::RespectLimits::ENABLED, |
| 2800 | callback_b[i].callback(), |
| 2801 | ClientSocketPool::ProxyAuthCallback(), |
| 2802 | pool_.get(), NetLogWithSource())); |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 2803 | } |
[email protected] | b89f7e4 | 2010-05-20 20:37:00 | [diff] [blame] | 2804 | |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 2805 | // Make 4 pending requests, 2 per group. |
| 2806 | |
| 2807 | for (int i = 2; i < 4; ++i) { |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2808 | EXPECT_EQ( |
| 2809 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2810 | handle_a[i].Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2811 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2812 | callback_a[i].callback(), |
| 2813 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 2814 | NetLogWithSource())); |
| 2815 | EXPECT_EQ( |
| 2816 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2817 | handle_b[i].Init(TestGroupId("b"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2818 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2819 | callback_b[i].callback(), |
| 2820 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 2821 | NetLogWithSource())); |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 2822 | } |
| 2823 | |
| 2824 | // Release b's socket first. The order is important, because in |
| 2825 | // DoReleaseSocket(), we'll process b's released socket, and since both b and |
| 2826 | // a are stalled, but 'a' is lower lexicographically, we'll process group 'a' |
| 2827 | // first, which has a releasing socket, so it refuses to start up another |
| 2828 | // ConnectJob. So, we used to infinite loop on this. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2829 | handle_b[0].socket()->Disconnect(); |
| 2830 | handle_b[0].Reset(); |
| 2831 | handle_a[0].socket()->Disconnect(); |
| 2832 | handle_a[0].Reset(); |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 2833 | |
| 2834 | // Used to get stuck here. |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 2835 | base::RunLoop().RunUntilIdle(); |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 2836 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2837 | handle_b[1].socket()->Disconnect(); |
| 2838 | handle_b[1].Reset(); |
| 2839 | handle_a[1].socket()->Disconnect(); |
| 2840 | handle_a[1].Reset(); |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 2841 | |
| 2842 | for (int i = 2; i < 4; ++i) { |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2843 | EXPECT_THAT(callback_b[i].WaitForResult(), IsOk()); |
| 2844 | EXPECT_THAT(callback_a[i].WaitForResult(), IsOk()); |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 2845 | } |
| 2846 | } |
| 2847 | |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 2848 | TEST_F(ClientSocketPoolBaseTest, |
| 2849 | ReleasingDisconnectedSocketsMaintainsPriorityOrder) { |
| 2850 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 2851 | |
| 2852 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 2853 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2854 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 2855 | IsError(ERR_IO_PENDING)); |
| 2856 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 2857 | IsError(ERR_IO_PENDING)); |
| 2858 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 2859 | IsError(ERR_IO_PENDING)); |
| 2860 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 2861 | IsError(ERR_IO_PENDING)); |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 2862 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2863 | EXPECT_THAT((*requests())[0]->WaitForResult(), IsOk()); |
| 2864 | EXPECT_THAT((*requests())[1]->WaitForResult(), IsOk()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2865 | EXPECT_EQ(2u, completion_count()); |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 2866 | |
| 2867 | // Releases one connection. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2868 | EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::NO_KEEP_ALIVE)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2869 | EXPECT_THAT((*requests())[2]->WaitForResult(), IsOk()); |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 2870 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2871 | EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::NO_KEEP_ALIVE)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2872 | EXPECT_THAT((*requests())[3]->WaitForResult(), IsOk()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2873 | EXPECT_EQ(4u, completion_count()); |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 2874 | |
| 2875 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 2876 | EXPECT_EQ(2, GetOrderOfRequest(2)); |
| 2877 | EXPECT_EQ(3, GetOrderOfRequest(3)); |
| 2878 | EXPECT_EQ(4, GetOrderOfRequest(4)); |
| 2879 | |
| 2880 | // Make sure we test order of all requests made. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2881 | EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(5)); |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 2882 | } |
| 2883 | |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2884 | class TestReleasingSocketRequest : public TestCompletionCallbackBase { |
[email protected] | 4f1e498 | 2010-03-02 18:31:04 | [diff] [blame] | 2885 | public: |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2886 | TestReleasingSocketRequest(TransportClientSocketPool* pool, |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2887 | int expected_result, |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2888 | bool reset_releasing_handle) |
| 2889 | : pool_(pool), |
| 2890 | expected_result_(expected_result), |
Bence Béky | 8ddc249 | 2018-06-13 01:02:04 | [diff] [blame] | 2891 | reset_releasing_handle_(reset_releasing_handle) {} |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2892 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 2893 | ~TestReleasingSocketRequest() override = default; |
[email protected] | 4f1e498 | 2010-03-02 18:31:04 | [diff] [blame] | 2894 | |
| 2895 | ClientSocketHandle* handle() { return &handle_; } |
| 2896 | |
Bence Béky | 8ddc249 | 2018-06-13 01:02:04 | [diff] [blame] | 2897 | CompletionOnceCallback callback() { |
| 2898 | return base::BindOnce(&TestReleasingSocketRequest::OnComplete, |
| 2899 | base::Unretained(this)); |
| 2900 | } |
[email protected] | 4f1e498 | 2010-03-02 18:31:04 | [diff] [blame] | 2901 | |
| 2902 | private: |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2903 | void OnComplete(int result) { |
| 2904 | SetResult(result); |
| 2905 | if (reset_releasing_handle_) |
| 2906 | handle_.Reset(); |
| 2907 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2908 | EXPECT_EQ( |
| 2909 | expected_result_, |
Matt Menke | 870e19ab | 2019-04-23 16:23:03 | [diff] [blame] | 2910 | handle2_.Init( |
| 2911 | TestGroupId("a"), |
| 2912 | ClientSocketPool::SocketParams::CreateForHttpForTesting(), |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2913 | absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 870e19ab | 2019-04-23 16:23:03 | [diff] [blame] | 2914 | ClientSocketPool::RespectLimits::ENABLED, CompletionOnceCallback(), |
| 2915 | ClientSocketPool::ProxyAuthCallback(), pool_, NetLogWithSource())); |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2916 | } |
| 2917 | |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 2918 | const raw_ptr<TransportClientSocketPool> pool_; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2919 | int expected_result_; |
| 2920 | bool reset_releasing_handle_; |
[email protected] | 4f1e498 | 2010-03-02 18:31:04 | [diff] [blame] | 2921 | ClientSocketHandle handle_; |
| 2922 | ClientSocketHandle handle2_; |
[email protected] | 4f1e498 | 2010-03-02 18:31:04 | [diff] [blame] | 2923 | }; |
| 2924 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2925 | |
| 2926 | TEST_F(ClientSocketPoolBaseTest, AdditionalErrorSocketsDontUseSlot) { |
| 2927 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 2928 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2929 | EXPECT_THAT(StartRequest(TestGroupId("b"), DEFAULT_PRIORITY), IsOk()); |
| 2930 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 2931 | EXPECT_THAT(StartRequest(TestGroupId("b"), DEFAULT_PRIORITY), IsOk()); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2932 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2933 | EXPECT_EQ(static_cast<int>(requests_size()), |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2934 | client_socket_factory_.allocation_count()); |
| 2935 | |
| 2936 | connect_job_factory_->set_job_type( |
| 2937 | TestConnectJob::kMockPendingAdditionalErrorStateJob); |
| 2938 | TestReleasingSocketRequest req(pool_.get(), OK, false); |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2939 | EXPECT_EQ(ERR_IO_PENDING, |
| 2940 | req.handle()->Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2941 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2942 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2943 | req.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2944 | pool_.get(), NetLogWithSource())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2945 | // The next job should complete synchronously |
| 2946 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 2947 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2948 | EXPECT_THAT(req.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2949 | EXPECT_FALSE(req.handle()->is_initialized()); |
| 2950 | EXPECT_FALSE(req.handle()->socket()); |
| 2951 | EXPECT_TRUE(req.handle()->is_ssl_error()); |
Matt Menke | 39b7c5a | 2019-04-10 19:47:51 | [diff] [blame] | 2952 | EXPECT_TRUE(req.handle()->ssl_cert_request_info()); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2953 | } |
| 2954 | |
[email protected] | b6501d3d | 2010-06-03 23:53:34 | [diff] [blame] | 2955 | // http://crbug.com/44724 regression test. |
| 2956 | // We start releasing the pool when we flush on network change. When that |
| 2957 | // happens, the only active references are in the ClientSocketHandles. When a |
| 2958 | // ConnectJob completes and calls back into the last ClientSocketHandle, that |
| 2959 | // callback can release the last reference and delete the pool. After the |
| 2960 | // callback finishes, we go back to the stack frame within the now-deleted pool. |
| 2961 | // Executing any code that refers to members of the now-deleted pool can cause |
| 2962 | // crashes. |
| 2963 | TEST_F(ClientSocketPoolBaseTest, CallbackThatReleasesPool) { |
| 2964 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 2965 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); |
| 2966 | |
| 2967 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2968 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2969 | EXPECT_EQ( |
| 2970 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2971 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2972 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2973 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2974 | pool_.get(), NetLogWithSource())); |
[email protected] | b6501d3d | 2010-06-03 23:53:34 | [diff] [blame] | 2975 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 2976 | pool_->FlushWithError(ERR_NETWORK_CHANGED, "Network changed"); |
[email protected] | b6501d3d | 2010-06-03 23:53:34 | [diff] [blame] | 2977 | |
| 2978 | // We'll call back into this now. |
| 2979 | callback.WaitForResult(); |
| 2980 | } |
| 2981 | |
[email protected] | a7e3857 | 2010-06-07 18:22:24 | [diff] [blame] | 2982 | TEST_F(ClientSocketPoolBaseTest, DoNotReuseSocketAfterFlush) { |
| 2983 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 2984 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 2985 | |
| 2986 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2987 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2988 | EXPECT_EQ( |
| 2989 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2990 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2991 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2992 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2993 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2994 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | a7e3857 | 2010-06-07 18:22:24 | [diff] [blame] | 2995 | EXPECT_EQ(ClientSocketHandle::UNUSED, handle.reuse_type()); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 2996 | NetLogSource source = handle.socket()->NetLog().source(); |
[email protected] | a7e3857 | 2010-06-07 18:22:24 | [diff] [blame] | 2997 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 2998 | pool_->FlushWithError(ERR_NETWORK_CHANGED, "Network changed"); |
[email protected] | a7e3857 | 2010-06-07 18:22:24 | [diff] [blame] | 2999 | |
| 3000 | handle.Reset(); |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 3001 | base::RunLoop().RunUntilIdle(); |
[email protected] | a7e3857 | 2010-06-07 18:22:24 | [diff] [blame] | 3002 | |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3003 | EXPECT_EQ( |
| 3004 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3005 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3006 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 3007 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3008 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3009 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | a7e3857 | 2010-06-07 18:22:24 | [diff] [blame] | 3010 | EXPECT_EQ(ClientSocketHandle::UNUSED, handle.reuse_type()); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 3011 | |
| 3012 | ExpectSocketClosedWithReason( |
| 3013 | source, TransportClientSocketPool::kSocketGenerationOutOfDate); |
[email protected] | a7e3857 | 2010-06-07 18:22:24 | [diff] [blame] | 3014 | } |
| 3015 | |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3016 | class ConnectWithinCallback : public TestCompletionCallbackBase { |
[email protected] | 06f9246 | 2010-08-31 19:24:14 | [diff] [blame] | 3017 | public: |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3018 | ConnectWithinCallback( |
| 3019 | const ClientSocketPool::GroupId& group_id, |
Matt Menke | 84d11e56 | 2019-03-27 00:11:19 | [diff] [blame] | 3020 | const scoped_refptr<ClientSocketPool::SocketParams>& params, |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3021 | TransportClientSocketPool* pool) |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3022 | : group_id_(group_id), params_(params), pool_(pool) {} |
[email protected] | 06f9246 | 2010-08-31 19:24:14 | [diff] [blame] | 3023 | |
Peter Boström | 293b134 | 2021-09-22 17:31:43 | [diff] [blame] | 3024 | ConnectWithinCallback(const ConnectWithinCallback&) = delete; |
| 3025 | ConnectWithinCallback& operator=(const ConnectWithinCallback&) = delete; |
| 3026 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 3027 | ~ConnectWithinCallback() override = default; |
[email protected] | 06f9246 | 2010-08-31 19:24:14 | [diff] [blame] | 3028 | |
| 3029 | int WaitForNestedResult() { |
| 3030 | return nested_callback_.WaitForResult(); |
| 3031 | } |
| 3032 | |
Bence Béky | 8ddc249 | 2018-06-13 01:02:04 | [diff] [blame] | 3033 | CompletionOnceCallback callback() { |
| 3034 | return base::BindOnce(&ConnectWithinCallback::OnComplete, |
| 3035 | base::Unretained(this)); |
| 3036 | } |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3037 | |
[email protected] | 06f9246 | 2010-08-31 19:24:14 | [diff] [blame] | 3038 | private: |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3039 | void OnComplete(int result) { |
| 3040 | SetResult(result); |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3041 | EXPECT_EQ( |
| 3042 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3043 | handle_.Init(group_id_, params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3044 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 3045 | nested_callback_.callback(), |
| 3046 | ClientSocketPool::ProxyAuthCallback(), pool_, |
| 3047 | NetLogWithSource())); |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3048 | } |
| 3049 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3050 | const ClientSocketPool::GroupId group_id_; |
Matt Menke | 84d11e56 | 2019-03-27 00:11:19 | [diff] [blame] | 3051 | const scoped_refptr<ClientSocketPool::SocketParams> params_; |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 3052 | const raw_ptr<TransportClientSocketPool> pool_; |
[email protected] | 06f9246 | 2010-08-31 19:24:14 | [diff] [blame] | 3053 | ClientSocketHandle handle_; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3054 | TestCompletionCallback nested_callback_; |
[email protected] | 06f9246 | 2010-08-31 19:24:14 | [diff] [blame] | 3055 | }; |
| 3056 | |
| 3057 | TEST_F(ClientSocketPoolBaseTest, AbortAllRequestsOnFlush) { |
| 3058 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 3059 | |
| 3060 | // First job will be waiting until it gets aborted. |
| 3061 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 3062 | |
| 3063 | ClientSocketHandle handle; |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3064 | ConnectWithinCallback callback(TestGroupId("a"), params_, pool_.get()); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3065 | EXPECT_EQ( |
| 3066 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3067 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3068 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 3069 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3070 | pool_.get(), NetLogWithSource())); |
[email protected] | 06f9246 | 2010-08-31 19:24:14 | [diff] [blame] | 3071 | |
| 3072 | // Second job will be started during the first callback, and will |
| 3073 | // asynchronously complete with OK. |
| 3074 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 3075 | pool_->FlushWithError(ERR_NETWORK_CHANGED, "Network changed"); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3076 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NETWORK_CHANGED)); |
| 3077 | EXPECT_THAT(callback.WaitForNestedResult(), IsOk()); |
[email protected] | 06f9246 | 2010-08-31 19:24:14 | [diff] [blame] | 3078 | } |
| 3079 | |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 3080 | TEST_F(ClientSocketPoolBaseTest, BackupSocketWaitsForHostResolution) { |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3081 | CreatePool(kDefaultMaxSockets, kDefaultMaxSockets, |
| 3082 | true /* enable_backup_connect_jobs */); |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 3083 | |
| 3084 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 3085 | ClientSocketHandle handle; |
| 3086 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3087 | EXPECT_EQ( |
| 3088 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3089 | handle.Init(TestGroupId("bar"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3090 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 3091 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3092 | pool_.get(), NetLogWithSource())); |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 3093 | // The backup timer fires but doesn't start a new ConnectJob while resolving |
| 3094 | // the hostname. |
| 3095 | client_socket_factory_.SetJobLoadState(0, LOAD_STATE_RESOLVING_HOST); |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 3096 | FastForwardBy( |
| 3097 | base::Milliseconds(ClientSocketPool::kMaxConnectRetryIntervalMs * 100)); |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 3098 | EXPECT_EQ(1, client_socket_factory_.allocation_count()); |
| 3099 | |
| 3100 | // Once the ConnectJob has finished resolving the hostname, the backup timer |
| 3101 | // will create a ConnectJob when it fires. |
| 3102 | client_socket_factory_.SetJobLoadState(0, LOAD_STATE_CONNECTING); |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 3103 | FastForwardBy( |
| 3104 | base::Milliseconds(ClientSocketPool::kMaxConnectRetryIntervalMs)); |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 3105 | EXPECT_EQ(2, client_socket_factory_.allocation_count()); |
| 3106 | } |
| 3107 | |
| 3108 | // Test that no backup socket is created when a ConnectJob connects before it |
| 3109 | // completes. |
| 3110 | TEST_F(ClientSocketPoolBaseTest, NoBackupSocketWhenConnected) { |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3111 | CreatePool(kDefaultMaxSockets, kDefaultMaxSockets, |
| 3112 | true /* enable_backup_connect_jobs */); |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 3113 | |
| 3114 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 3115 | ClientSocketHandle handle; |
| 3116 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3117 | EXPECT_EQ( |
| 3118 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3119 | handle.Init(TestGroupId("bar"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3120 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 3121 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3122 | pool_.get(), NetLogWithSource())); |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 3123 | // The backup timer fires but doesn't start a new ConnectJob while resolving |
| 3124 | // the hostname. |
| 3125 | client_socket_factory_.SetJobLoadState(0, LOAD_STATE_RESOLVING_HOST); |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 3126 | FastForwardBy( |
| 3127 | base::Milliseconds(ClientSocketPool::kMaxConnectRetryIntervalMs * 100)); |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 3128 | EXPECT_EQ(1, client_socket_factory_.allocation_count()); |
| 3129 | |
| 3130 | client_socket_factory_.SetJobLoadState(0, LOAD_STATE_SSL_HANDSHAKE); |
| 3131 | client_socket_factory_.SetJobHasEstablishedConnection(0); |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 3132 | FastForwardBy( |
| 3133 | base::Milliseconds(ClientSocketPool::kMaxConnectRetryIntervalMs * 100)); |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 3134 | EXPECT_EQ(1, client_socket_factory_.allocation_count()); |
| 3135 | } |
| 3136 | |
[email protected] | 25eea38 | 2010-07-10 23:55:26 | [diff] [blame] | 3137 | // Cancel a pending socket request while we're at max sockets, |
| 3138 | // and verify that the backup socket firing doesn't cause a crash. |
| 3139 | TEST_F(ClientSocketPoolBaseTest, BackupSocketCancelAtMaxSockets) { |
| 3140 | // Max 4 sockets globally, max 4 sockets per group. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3141 | CreatePool(kDefaultMaxSockets, kDefaultMaxSockets, |
| 3142 | true /* enable_backup_connect_jobs */); |
[email protected] | 25eea38 | 2010-07-10 23:55:26 | [diff] [blame] | 3143 | |
[email protected] | 4baaf9d | 2010-08-31 15:15:44 | [diff] [blame] | 3144 | // Create the first socket and set to ERR_IO_PENDING. This starts the backup |
| 3145 | // timer. |
[email protected] | 25eea38 | 2010-07-10 23:55:26 | [diff] [blame] | 3146 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 3147 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3148 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3149 | EXPECT_EQ( |
| 3150 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3151 | handle.Init(TestGroupId("bar"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3152 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 3153 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3154 | pool_.get(), NetLogWithSource())); |
[email protected] | 25eea38 | 2010-07-10 23:55:26 | [diff] [blame] | 3155 | |
| 3156 | // Start (MaxSockets - 1) connected sockets to reach max sockets. |
| 3157 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 3158 | ClientSocketHandle handles[kDefaultMaxSockets]; |
| 3159 | for (int i = 1; i < kDefaultMaxSockets; ++i) { |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3160 | EXPECT_EQ(OK, handles[i].Init(TestGroupId("bar"), params_, absl::nullopt, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3161 | DEFAULT_PRIORITY, SocketTag(), |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3162 | ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3163 | callback.callback(), |
| 3164 | ClientSocketPool::ProxyAuthCallback(), |
| 3165 | pool_.get(), NetLogWithSource())); |
[email protected] | 25eea38 | 2010-07-10 23:55:26 | [diff] [blame] | 3166 | } |
| 3167 | |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 3168 | base::RunLoop().RunUntilIdle(); |
[email protected] | 25eea38 | 2010-07-10 23:55:26 | [diff] [blame] | 3169 | |
| 3170 | // Cancel the pending request. |
| 3171 | handle.Reset(); |
| 3172 | |
| 3173 | // Wait for the backup timer to fire (add some slop to ensure it fires) |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 3174 | FastForwardBy( |
| 3175 | base::Milliseconds(ClientSocketPool::kMaxConnectRetryIntervalMs / 2 * 3)); |
[email protected] | 25eea38 | 2010-07-10 23:55:26 | [diff] [blame] | 3176 | |
[email protected] | 25eea38 | 2010-07-10 23:55:26 | [diff] [blame] | 3177 | EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count()); |
| 3178 | } |
| 3179 | |
[email protected] | 3f00be8 | 2010-09-27 19:50:02 | [diff] [blame] | 3180 | TEST_F(ClientSocketPoolBaseTest, CancelBackupSocketAfterCancelingAllRequests) { |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3181 | CreatePool(kDefaultMaxSockets, kDefaultMaxSockets, |
| 3182 | true /* enable_backup_connect_jobs */); |
[email protected] | 4baaf9d | 2010-08-31 15:15:44 | [diff] [blame] | 3183 | |
| 3184 | // Create the first socket and set to ERR_IO_PENDING. This starts the backup |
| 3185 | // timer. |
| 3186 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 3187 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3188 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3189 | EXPECT_EQ( |
| 3190 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3191 | handle.Init(TestGroupId("bar"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3192 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 3193 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3194 | pool_.get(), NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3195 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("bar"))); |
| 3196 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("bar"))); |
| 3197 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3198 | TestGroupId("bar"))); |
| 3199 | EXPECT_EQ( |
| 3200 | 0u, pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("bar"))); |
[email protected] | 4baaf9d | 2010-08-31 15:15:44 | [diff] [blame] | 3201 | |
| 3202 | // Cancel the socket request. This should cancel the backup timer. Wait for |
| 3203 | // the backup time to see if it indeed got canceled. |
| 3204 | handle.Reset(); |
| 3205 | // Wait for the backup timer to fire (add some slop to ensure it fires) |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 3206 | FastForwardBy( |
| 3207 | base::Milliseconds(ClientSocketPool::kMaxConnectRetryIntervalMs / 2 * 3)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3208 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("bar"))); |
| 3209 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("bar"))); |
[email protected] | 4baaf9d | 2010-08-31 15:15:44 | [diff] [blame] | 3210 | } |
| 3211 | |
[email protected] | 3f00be8 | 2010-09-27 19:50:02 | [diff] [blame] | 3212 | TEST_F(ClientSocketPoolBaseTest, CancelBackupSocketAfterFinishingAllRequests) { |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3213 | CreatePool(kDefaultMaxSockets, kDefaultMaxSockets, |
| 3214 | true /* enable_backup_connect_jobs */); |
[email protected] | 3f00be8 | 2010-09-27 19:50:02 | [diff] [blame] | 3215 | |
| 3216 | // Create the first socket and set to ERR_IO_PENDING. This starts the backup |
| 3217 | // timer. |
| 3218 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 3219 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3220 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3221 | EXPECT_EQ( |
| 3222 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3223 | handle.Init(TestGroupId("bar"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3224 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 3225 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3226 | pool_.get(), NetLogWithSource())); |
[email protected] | 3f00be8 | 2010-09-27 19:50:02 | [diff] [blame] | 3227 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3228 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3229 | TestCompletionCallback callback2; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3230 | EXPECT_EQ( |
| 3231 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3232 | handle2.Init(TestGroupId("bar"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3233 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3234 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3235 | pool_.get(), NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3236 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("bar"))); |
| 3237 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("bar"))); |
[email protected] | 3f00be8 | 2010-09-27 19:50:02 | [diff] [blame] | 3238 | |
| 3239 | // Cancel request 1 and then complete request 2. With the requests finished, |
| 3240 | // the backup timer should be cancelled. |
| 3241 | handle.Reset(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3242 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 3f00be8 | 2010-09-27 19:50:02 | [diff] [blame] | 3243 | // Wait for the backup timer to fire (add some slop to ensure it fires) |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 3244 | FastForwardBy( |
| 3245 | base::Milliseconds(ClientSocketPool::kMaxConnectRetryIntervalMs / 2 * 3)); |
[email protected] | 3f00be8 | 2010-09-27 19:50:02 | [diff] [blame] | 3246 | } |
| 3247 | |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3248 | // Test delayed socket binding for the case where we have two connects, |
| 3249 | // and while one is waiting on a connect, the other frees up. |
| 3250 | // The socket waiting on a connect should switch immediately to the freed |
| 3251 | // up socket. |
| 3252 | TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingWaitingForConnect) { |
| 3253 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 3254 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3255 | |
| 3256 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3257 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3258 | EXPECT_EQ( |
| 3259 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3260 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3261 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3262 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3263 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3264 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3265 | |
| 3266 | // No idle sockets, no pending jobs. |
| 3267 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3268 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3269 | |
| 3270 | // Create a second socket to the same host, but this one will wait. |
| 3271 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 3272 | ClientSocketHandle handle2; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3273 | EXPECT_EQ( |
| 3274 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3275 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3276 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3277 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3278 | pool_.get(), NetLogWithSource())); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3279 | // No idle sockets, and one connecting job. |
| 3280 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3281 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3282 | |
| 3283 | // Return the first handle to the pool. This will initiate the delayed |
| 3284 | // binding. |
| 3285 | handle1.Reset(); |
| 3286 | |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 3287 | base::RunLoop().RunUntilIdle(); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3288 | |
| 3289 | // Still no idle sockets, still one pending connect job. |
| 3290 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3291 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3292 | |
| 3293 | // The second socket connected, even though it was a Waiting Job. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3294 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3295 | |
| 3296 | // And we can see there is still one job waiting. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3297 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3298 | |
| 3299 | // Finally, signal the waiting Connect. |
| 3300 | client_socket_factory_.SignalJobs(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3301 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3302 | |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 3303 | base::RunLoop().RunUntilIdle(); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3304 | } |
| 3305 | |
| 3306 | // Test delayed socket binding when a group is at capacity and one |
| 3307 | // of the group's sockets frees up. |
| 3308 | TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingAtGroupCapacity) { |
| 3309 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 3310 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3311 | |
| 3312 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3313 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3314 | EXPECT_EQ( |
| 3315 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3316 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3317 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3318 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3319 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3320 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3321 | |
| 3322 | // No idle sockets, no pending jobs. |
| 3323 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3324 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3325 | |
| 3326 | // Create a second socket to the same host, but this one will wait. |
| 3327 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 3328 | ClientSocketHandle handle2; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3329 | EXPECT_EQ( |
| 3330 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3331 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3332 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3333 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3334 | pool_.get(), NetLogWithSource())); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3335 | // No idle sockets, and one connecting job. |
| 3336 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3337 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3338 | |
| 3339 | // Return the first handle to the pool. This will initiate the delayed |
| 3340 | // binding. |
| 3341 | handle1.Reset(); |
| 3342 | |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 3343 | base::RunLoop().RunUntilIdle(); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3344 | |
| 3345 | // Still no idle sockets, still one pending connect job. |
| 3346 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3347 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3348 | |
| 3349 | // The second socket connected, even though it was a Waiting Job. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3350 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3351 | |
| 3352 | // And we can see there is still one job waiting. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3353 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3354 | |
| 3355 | // Finally, signal the waiting Connect. |
| 3356 | client_socket_factory_.SignalJobs(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3357 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3358 | |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 3359 | base::RunLoop().RunUntilIdle(); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3360 | } |
| 3361 | |
| 3362 | // Test out the case where we have one socket connected, one |
| 3363 | // connecting, when the first socket finishes and goes idle. |
[email protected] | 2abfe90a | 2010-08-25 17:49:51 | [diff] [blame] | 3364 | // Although the second connection is pending, the second request |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3365 | // should complete, by taking the first socket's idle socket. |
| 3366 | TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingAtStall) { |
| 3367 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 3368 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3369 | |
| 3370 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3371 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3372 | EXPECT_EQ( |
| 3373 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3374 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3375 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3376 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3377 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3378 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3379 | |
| 3380 | // No idle sockets, no pending jobs. |
| 3381 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3382 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3383 | |
| 3384 | // Create a second socket to the same host, but this one will wait. |
| 3385 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 3386 | ClientSocketHandle handle2; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3387 | EXPECT_EQ( |
| 3388 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3389 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3390 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3391 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3392 | pool_.get(), NetLogWithSource())); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3393 | // No idle sockets, and one connecting job. |
| 3394 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3395 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3396 | |
| 3397 | // Return the first handle to the pool. This will initiate the delayed |
| 3398 | // binding. |
| 3399 | handle1.Reset(); |
| 3400 | |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 3401 | base::RunLoop().RunUntilIdle(); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3402 | |
| 3403 | // Still no idle sockets, still one pending connect job. |
| 3404 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3405 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3406 | |
| 3407 | // The second socket connected, even though it was a Waiting Job. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3408 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3409 | |
| 3410 | // And we can see there is still one job waiting. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3411 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3412 | |
| 3413 | // Finally, signal the waiting Connect. |
| 3414 | client_socket_factory_.SignalJobs(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3415 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3416 | |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 3417 | base::RunLoop().RunUntilIdle(); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3418 | } |
| 3419 | |
[email protected] | 2abfe90a | 2010-08-25 17:49:51 | [diff] [blame] | 3420 | // Cover the case where on an available socket slot, we have one pending |
| 3421 | // request that completes synchronously, thereby making the Group empty. |
| 3422 | TEST_F(ClientSocketPoolBaseTest, SynchronouslyProcessOnePendingRequest) { |
| 3423 | const int kUnlimitedSockets = 100; |
| 3424 | const int kOneSocketPerGroup = 1; |
| 3425 | CreatePool(kUnlimitedSockets, kOneSocketPerGroup); |
| 3426 | |
| 3427 | // Make the first request asynchronous fail. |
| 3428 | // This will free up a socket slot later. |
| 3429 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); |
| 3430 | |
| 3431 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3432 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3433 | EXPECT_EQ( |
| 3434 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3435 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3436 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3437 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3438 | pool_.get(), NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3439 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | 2abfe90a | 2010-08-25 17:49:51 | [diff] [blame] | 3440 | |
| 3441 | // Make the second request synchronously fail. This should make the Group |
| 3442 | // empty. |
| 3443 | connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); |
| 3444 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3445 | TestCompletionCallback callback2; |
[email protected] | 2abfe90a | 2010-08-25 17:49:51 | [diff] [blame] | 3446 | // It'll be ERR_IO_PENDING now, but the TestConnectJob will synchronously fail |
| 3447 | // when created. |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3448 | EXPECT_EQ( |
| 3449 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3450 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3451 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3452 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3453 | pool_.get(), NetLogWithSource())); |
[email protected] | 2abfe90a | 2010-08-25 17:49:51 | [diff] [blame] | 3454 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3455 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | 2abfe90a | 2010-08-25 17:49:51 | [diff] [blame] | 3456 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3457 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
| 3458 | EXPECT_THAT(callback2.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3459 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
[email protected] | 2abfe90a | 2010-08-25 17:49:51 | [diff] [blame] | 3460 | } |
| 3461 | |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 3462 | TEST_F(ClientSocketPoolBaseTest, PreferUsedSocketToUnusedSocket) { |
| 3463 | CreatePool(kDefaultMaxSockets, kDefaultMaxSockets); |
| 3464 | |
| 3465 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3466 | |
| 3467 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3468 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3469 | EXPECT_EQ( |
| 3470 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3471 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3472 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3473 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3474 | pool_.get(), NetLogWithSource())); |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 3475 | |
| 3476 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3477 | TestCompletionCallback callback2; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3478 | EXPECT_EQ( |
| 3479 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3480 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3481 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3482 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3483 | pool_.get(), NetLogWithSource())); |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 3484 | ClientSocketHandle handle3; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3485 | TestCompletionCallback callback3; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3486 | EXPECT_EQ( |
| 3487 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3488 | handle3.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3489 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3490 | callback3.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3491 | pool_.get(), NetLogWithSource())); |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 3492 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3493 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 3494 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 3495 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 3496 | |
| 3497 | // Use the socket. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 3498 | EXPECT_EQ(1, handle1.socket()->Write(nullptr, 1, CompletionOnceCallback(), |
Ramin Halavati | 0a08cc8 | 2018-02-06 07:46:38 | [diff] [blame] | 3499 | TRAFFIC_ANNOTATION_FOR_TESTS)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 3500 | EXPECT_EQ(1, handle3.socket()->Write(nullptr, 1, CompletionOnceCallback(), |
Ramin Halavati | 0a08cc8 | 2018-02-06 07:46:38 | [diff] [blame] | 3501 | TRAFFIC_ANNOTATION_FOR_TESTS)); |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 3502 | |
| 3503 | handle1.Reset(); |
| 3504 | handle2.Reset(); |
| 3505 | handle3.Reset(); |
| 3506 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3507 | EXPECT_EQ(OK, handle1.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3508 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3509 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3510 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3511 | pool_.get(), NetLogWithSource())); |
| 3512 | EXPECT_EQ(OK, handle2.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3513 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3514 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3515 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3516 | pool_.get(), NetLogWithSource())); |
| 3517 | EXPECT_EQ(OK, handle3.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3518 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3519 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3520 | callback3.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3521 | pool_.get(), NetLogWithSource())); |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 3522 | |
| 3523 | EXPECT_TRUE(handle1.socket()->WasEverUsed()); |
| 3524 | EXPECT_TRUE(handle2.socket()->WasEverUsed()); |
| 3525 | EXPECT_FALSE(handle3.socket()->WasEverUsed()); |
| 3526 | } |
| 3527 | |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3528 | TEST_F(ClientSocketPoolBaseTest, RequestSockets) { |
| 3529 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 3530 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3531 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3532 | TestCompletionCallback preconnect_callback; |
| 3533 | EXPECT_EQ(ERR_IO_PENDING, |
| 3534 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 3535 | preconnect_callback.callback(), |
| 3536 | NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3537 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3538 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 3539 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3540 | EXPECT_EQ(2u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3541 | TestGroupId("a"))); |
| 3542 | EXPECT_EQ(2u, |
| 3543 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3544 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3545 | |
| 3546 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3547 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3548 | EXPECT_EQ( |
| 3549 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3550 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3551 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3552 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3553 | pool_.get(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3554 | |
| 3555 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3556 | TestCompletionCallback callback2; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3557 | EXPECT_EQ( |
| 3558 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3559 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3560 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3561 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3562 | pool_.get(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3563 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3564 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3565 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3566 | TestGroupId("a"))); |
| 3567 | EXPECT_EQ(0u, |
| 3568 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3569 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3570 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3571 | EXPECT_THAT(preconnect_callback.WaitForResult(), IsOk()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3572 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 3573 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3574 | handle1.Reset(); |
| 3575 | handle2.Reset(); |
| 3576 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3577 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3578 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3579 | TestGroupId("a"))); |
| 3580 | EXPECT_EQ(0u, |
| 3581 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3582 | EXPECT_EQ(2u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3583 | } |
| 3584 | |
| 3585 | TEST_F(ClientSocketPoolBaseTest, RequestSocketsWhenAlreadyHaveAConnectJob) { |
| 3586 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 3587 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3588 | |
| 3589 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3590 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3591 | EXPECT_EQ( |
| 3592 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3593 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3594 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3595 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3596 | pool_.get(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3597 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3598 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 3599 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3600 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3601 | TestGroupId("a"))); |
| 3602 | EXPECT_EQ(0u, |
| 3603 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3604 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3605 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3606 | TestCompletionCallback preconnect_callback; |
| 3607 | EXPECT_EQ(ERR_IO_PENDING, |
| 3608 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 3609 | preconnect_callback.callback(), |
| 3610 | NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3611 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3612 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3613 | EXPECT_EQ(1u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3614 | TestGroupId("a"))); |
| 3615 | EXPECT_EQ(1u, |
| 3616 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3617 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3618 | |
| 3619 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3620 | TestCompletionCallback callback2; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3621 | EXPECT_EQ( |
| 3622 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3623 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3624 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3625 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3626 | pool_.get(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3627 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3628 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3629 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3630 | TestGroupId("a"))); |
| 3631 | EXPECT_EQ(0u, |
| 3632 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3633 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3634 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3635 | EXPECT_THAT(preconnect_callback.WaitForResult(), IsOk()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3636 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 3637 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3638 | handle1.Reset(); |
| 3639 | handle2.Reset(); |
| 3640 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3641 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3642 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3643 | TestGroupId("a"))); |
| 3644 | EXPECT_EQ(0u, |
| 3645 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3646 | EXPECT_EQ(2u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3647 | } |
| 3648 | |
| 3649 | TEST_F(ClientSocketPoolBaseTest, |
| 3650 | RequestSocketsWhenAlreadyHaveMultipleConnectJob) { |
| 3651 | CreatePool(4, 4); |
| 3652 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3653 | |
| 3654 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3655 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3656 | EXPECT_EQ( |
| 3657 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3658 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3659 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3660 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3661 | pool_.get(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3662 | |
| 3663 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3664 | TestCompletionCallback callback2; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3665 | EXPECT_EQ( |
| 3666 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3667 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3668 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3669 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3670 | pool_.get(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3671 | |
| 3672 | ClientSocketHandle handle3; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3673 | TestCompletionCallback callback3; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3674 | EXPECT_EQ( |
| 3675 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3676 | handle3.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3677 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3678 | callback3.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3679 | pool_.get(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3680 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3681 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 3682 | EXPECT_EQ(3u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3683 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3684 | TestGroupId("a"))); |
| 3685 | EXPECT_EQ(0u, |
| 3686 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3687 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3688 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3689 | EXPECT_EQ( |
| 3690 | OK, pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 3691 | CompletionOnceCallback(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3692 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3693 | EXPECT_EQ(3u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3694 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3695 | TestGroupId("a"))); |
| 3696 | EXPECT_EQ(0u, |
| 3697 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3698 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3699 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3700 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 3701 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 3702 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3703 | handle1.Reset(); |
| 3704 | handle2.Reset(); |
| 3705 | handle3.Reset(); |
| 3706 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3707 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3708 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3709 | TestGroupId("a"))); |
| 3710 | EXPECT_EQ(0u, |
| 3711 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3712 | EXPECT_EQ(3u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3713 | } |
| 3714 | |
| 3715 | TEST_F(ClientSocketPoolBaseTest, RequestSocketsAtMaxSocketLimit) { |
| 3716 | CreatePool(kDefaultMaxSockets, kDefaultMaxSockets); |
| 3717 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3718 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3719 | ASSERT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3720 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3721 | TestCompletionCallback preconnect_callback; |
| 3722 | EXPECT_EQ(ERR_IO_PENDING, |
| 3723 | pool_->RequestSockets( |
| 3724 | TestGroupId("a"), params_, absl::nullopt, kDefaultMaxSockets, |
| 3725 | preconnect_callback.callback(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3726 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3727 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 3728 | EXPECT_EQ(kDefaultMaxSockets, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3729 | static_cast<int>( |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3730 | pool_->NumConnectJobsInGroupForTesting(TestGroupId("a")))); |
| 3731 | EXPECT_EQ( |
| 3732 | kDefaultMaxSockets, |
| 3733 | static_cast<int>(pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3734 | TestGroupId("a")))); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 3735 | EXPECT_EQ(kDefaultMaxSockets, |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3736 | static_cast<int>(pool_->NumUnassignedConnectJobsInGroupForTesting( |
| 3737 | TestGroupId("a")))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3738 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3739 | ASSERT_FALSE(pool_->HasGroupForTesting(TestGroupId("b"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3740 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3741 | EXPECT_EQ(OK, |
| 3742 | pool_->RequestSockets(TestGroupId("b"), params_, absl::nullopt, |
| 3743 | kDefaultMaxSockets, CompletionOnceCallback(), |
| 3744 | NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3745 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3746 | ASSERT_FALSE(pool_->HasGroupForTesting(TestGroupId("b"))); |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3747 | |
| 3748 | EXPECT_THAT(preconnect_callback.WaitForResult(), IsOk()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3749 | } |
| 3750 | |
| 3751 | TEST_F(ClientSocketPoolBaseTest, RequestSocketsHitMaxSocketLimit) { |
| 3752 | CreatePool(kDefaultMaxSockets, kDefaultMaxSockets); |
| 3753 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3754 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3755 | ASSERT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3756 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3757 | TestCompletionCallback preconnect_callback1; |
| 3758 | EXPECT_EQ(ERR_IO_PENDING, |
| 3759 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, |
| 3760 | kDefaultMaxSockets - 1, |
| 3761 | preconnect_callback1.callback(), |
| 3762 | NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3763 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3764 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 3765 | EXPECT_EQ(kDefaultMaxSockets - 1, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3766 | static_cast<int>( |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3767 | pool_->NumConnectJobsInGroupForTesting(TestGroupId("a")))); |
| 3768 | EXPECT_EQ( |
| 3769 | kDefaultMaxSockets - 1, |
| 3770 | static_cast<int>(pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3771 | TestGroupId("a")))); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 3772 | EXPECT_EQ(kDefaultMaxSockets - 1, |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3773 | static_cast<int>(pool_->NumUnassignedConnectJobsInGroupForTesting( |
| 3774 | TestGroupId("a")))); |
[email protected] | 51fdc7c | 2012-04-10 19:19:48 | [diff] [blame] | 3775 | EXPECT_FALSE(pool_->IsStalled()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3776 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3777 | ASSERT_FALSE(pool_->HasGroupForTesting(TestGroupId("b"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3778 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3779 | TestCompletionCallback preconnect_callback2; |
| 3780 | EXPECT_EQ(ERR_IO_PENDING, |
| 3781 | pool_->RequestSockets( |
| 3782 | TestGroupId("b"), params_, absl::nullopt, kDefaultMaxSockets, |
| 3783 | preconnect_callback2.callback(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3784 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3785 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("b"))); |
| 3786 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("b"))); |
[email protected] | 51fdc7c | 2012-04-10 19:19:48 | [diff] [blame] | 3787 | EXPECT_FALSE(pool_->IsStalled()); |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3788 | |
| 3789 | EXPECT_THAT(preconnect_callback1.WaitForResult(), IsOk()); |
| 3790 | EXPECT_THAT(preconnect_callback2.WaitForResult(), IsOk()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3791 | } |
| 3792 | |
| 3793 | TEST_F(ClientSocketPoolBaseTest, RequestSocketsCountIdleSockets) { |
| 3794 | CreatePool(4, 4); |
| 3795 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3796 | |
| 3797 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3798 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3799 | EXPECT_EQ( |
| 3800 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3801 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3802 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3803 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3804 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3805 | ASSERT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3806 | handle1.Reset(); |
| 3807 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3808 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 3809 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3810 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3811 | TestGroupId("a"))); |
| 3812 | EXPECT_EQ(0u, |
| 3813 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3814 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3815 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3816 | TestCompletionCallback preconnect_callback; |
| 3817 | EXPECT_EQ(ERR_IO_PENDING, |
| 3818 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 3819 | preconnect_callback.callback(), |
| 3820 | NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3821 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3822 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3823 | EXPECT_EQ(1u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3824 | TestGroupId("a"))); |
| 3825 | EXPECT_EQ(1u, |
| 3826 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3827 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3828 | |
| 3829 | EXPECT_THAT(preconnect_callback.WaitForResult(), IsOk()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3830 | } |
| 3831 | |
| 3832 | TEST_F(ClientSocketPoolBaseTest, RequestSocketsCountActiveSockets) { |
| 3833 | CreatePool(4, 4); |
| 3834 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3835 | |
| 3836 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3837 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3838 | EXPECT_EQ( |
| 3839 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3840 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3841 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3842 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3843 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3844 | ASSERT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3845 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3846 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 3847 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3848 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3849 | TestGroupId("a"))); |
| 3850 | EXPECT_EQ(0u, |
| 3851 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3852 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3853 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3854 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3855 | TestCompletionCallback preconnect_callback; |
| 3856 | EXPECT_EQ(ERR_IO_PENDING, |
| 3857 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 3858 | preconnect_callback.callback(), |
| 3859 | NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3860 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3861 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3862 | EXPECT_EQ(1u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3863 | TestGroupId("a"))); |
| 3864 | EXPECT_EQ(1u, |
| 3865 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3866 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3867 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3868 | |
| 3869 | EXPECT_THAT(preconnect_callback.WaitForResult(), IsOk()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3870 | } |
| 3871 | |
| 3872 | TEST_F(ClientSocketPoolBaseTest, RequestSocketsSynchronous) { |
| 3873 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 3874 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 3875 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3876 | EXPECT_EQ( |
| 3877 | OK, pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, |
| 3878 | kDefaultMaxSocketsPerGroup, |
| 3879 | CompletionOnceCallback(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3880 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3881 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 3882 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3883 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3884 | TestGroupId("a"))); |
| 3885 | EXPECT_EQ(0u, |
| 3886 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 3887 | EXPECT_EQ(kDefaultMaxSocketsPerGroup, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3888 | static_cast<int>(pool_->IdleSocketCountInGroup(TestGroupId("a")))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3889 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3890 | EXPECT_EQ( |
| 3891 | OK, pool_->RequestSockets(TestGroupId("b"), params_, absl::nullopt, |
| 3892 | kDefaultMaxSocketsPerGroup, |
| 3893 | CompletionOnceCallback(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3894 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3895 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("b"))); |
| 3896 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3897 | TestGroupId("b"))); |
| 3898 | EXPECT_EQ(0u, |
| 3899 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("b"))); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 3900 | EXPECT_EQ(kDefaultMaxSocketsPerGroup, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3901 | static_cast<int>(pool_->IdleSocketCountInGroup(TestGroupId("b")))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3902 | } |
| 3903 | |
[email protected] | 3c819f52 | 2010-12-02 02:03:12 | [diff] [blame] | 3904 | TEST_F(ClientSocketPoolBaseTest, RequestSocketsSynchronousError) { |
| 3905 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 3906 | connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); |
| 3907 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3908 | EXPECT_EQ( |
| 3909 | OK, pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, |
| 3910 | kDefaultMaxSocketsPerGroup, |
| 3911 | CompletionOnceCallback(), NetLogWithSource())); |
[email protected] | 3c819f52 | 2010-12-02 02:03:12 | [diff] [blame] | 3912 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3913 | ASSERT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
[email protected] | fd2e53e | 2011-01-14 20:40:52 | [diff] [blame] | 3914 | |
| 3915 | connect_job_factory_->set_job_type( |
| 3916 | TestConnectJob::kMockAdditionalErrorStateJob); |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3917 | |
| 3918 | EXPECT_EQ( |
| 3919 | OK, pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, |
| 3920 | kDefaultMaxSocketsPerGroup, |
| 3921 | CompletionOnceCallback(), NetLogWithSource())); |
[email protected] | fd2e53e | 2011-01-14 20:40:52 | [diff] [blame] | 3922 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3923 | ASSERT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
[email protected] | 3c819f52 | 2010-12-02 02:03:12 | [diff] [blame] | 3924 | } |
| 3925 | |
[email protected] | 8159a1c | 2012-06-07 00:00:10 | [diff] [blame] | 3926 | TEST_F(ClientSocketPoolBaseTest, RequestSocketsMultipleTimesDoesNothing) { |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3927 | CreatePool(4, 4); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 3928 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3929 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3930 | TestCompletionCallback preconnect_callback; |
| 3931 | EXPECT_EQ(ERR_IO_PENDING, |
| 3932 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 3933 | preconnect_callback.callback(), |
| 3934 | NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3935 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3936 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 3937 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3938 | EXPECT_EQ(2u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3939 | TestGroupId("a"))); |
| 3940 | EXPECT_EQ(2u, |
| 3941 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3942 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3943 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3944 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3945 | EXPECT_EQ( |
| 3946 | OK, pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 3947 | CompletionOnceCallback(), NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3948 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3949 | EXPECT_EQ(2u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3950 | TestGroupId("a"))); |
| 3951 | EXPECT_EQ(2u, |
| 3952 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3953 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3954 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3955 | |
| 3956 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3957 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3958 | EXPECT_EQ( |
| 3959 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3960 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3961 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3962 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3963 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 3964 | |
| 3965 | client_socket_factory_.SignalJob(0); |
| 3966 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 3967 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3968 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3969 | EXPECT_EQ(1u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3970 | TestGroupId("a"))); |
| 3971 | EXPECT_EQ(1u, |
| 3972 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3973 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3974 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3975 | |
| 3976 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3977 | TestCompletionCallback callback2; |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 3978 | EXPECT_EQ( |
| 3979 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3980 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3981 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3982 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3983 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 3984 | client_socket_factory_.SignalJob(0); |
| 3985 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 3986 | EXPECT_THAT(preconnect_callback.WaitForResult(), IsOk()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3987 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3988 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3989 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3990 | TestGroupId("a"))); |
| 3991 | EXPECT_EQ(0u, |
| 3992 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3993 | EXPECT_EQ(2, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3994 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 8159a1c | 2012-06-07 00:00:10 | [diff] [blame] | 3995 | |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3996 | handle1.Reset(); |
| 3997 | handle2.Reset(); |
| 3998 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3999 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4000 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4001 | TestGroupId("a"))); |
| 4002 | EXPECT_EQ(0u, |
| 4003 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4004 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4005 | EXPECT_EQ(2u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4006 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 4007 | EXPECT_EQ( |
| 4008 | OK, pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 4009 | CompletionOnceCallback(), NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4010 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4011 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4012 | TestGroupId("a"))); |
| 4013 | EXPECT_EQ(0u, |
| 4014 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4015 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4016 | EXPECT_EQ(2u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4017 | } |
| 4018 | |
| 4019 | TEST_F(ClientSocketPoolBaseTest, RequestSocketsDifferentNumSockets) { |
| 4020 | CreatePool(4, 4); |
| 4021 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 4022 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 4023 | TestCompletionCallback preconnect_callback1; |
| 4024 | EXPECT_EQ(ERR_IO_PENDING, |
| 4025 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 1, |
| 4026 | preconnect_callback1.callback(), |
| 4027 | NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4028 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4029 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 4030 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4031 | EXPECT_EQ(1u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4032 | TestGroupId("a"))); |
| 4033 | EXPECT_EQ(1u, |
| 4034 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4035 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4036 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 4037 | TestCompletionCallback preconnect_callback2; |
| 4038 | EXPECT_EQ(ERR_IO_PENDING, |
| 4039 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 4040 | preconnect_callback2.callback(), |
| 4041 | NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4042 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4043 | EXPECT_EQ(2u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4044 | TestGroupId("a"))); |
| 4045 | EXPECT_EQ(2u, |
| 4046 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4047 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4048 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 4049 | TestCompletionCallback preconnect_callback3; |
| 4050 | EXPECT_EQ(ERR_IO_PENDING, |
| 4051 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 3, |
| 4052 | preconnect_callback3.callback(), |
| 4053 | NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4054 | EXPECT_EQ(3u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4055 | EXPECT_EQ(3u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4056 | TestGroupId("a"))); |
| 4057 | EXPECT_EQ(3u, |
| 4058 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4059 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4060 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 4061 | EXPECT_EQ( |
| 4062 | OK, pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 1, |
| 4063 | CompletionOnceCallback(), NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4064 | EXPECT_EQ(3u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4065 | EXPECT_EQ(3u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4066 | TestGroupId("a"))); |
| 4067 | EXPECT_EQ(3u, |
| 4068 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4069 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4070 | } |
| 4071 | |
| 4072 | TEST_F(ClientSocketPoolBaseTest, PreconnectJobsTakenByNormalRequests) { |
| 4073 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4074 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4075 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 4076 | TestCompletionCallback preconnect_callback; |
| 4077 | EXPECT_EQ(ERR_IO_PENDING, |
| 4078 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 1, |
| 4079 | preconnect_callback.callback(), |
| 4080 | NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4081 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4082 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 4083 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4084 | EXPECT_EQ(1u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4085 | TestGroupId("a"))); |
| 4086 | EXPECT_EQ(1u, |
| 4087 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4088 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4089 | |
| 4090 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 4091 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 4092 | EXPECT_EQ( |
| 4093 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4094 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4095 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4096 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4097 | pool_.get(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4098 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4099 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4100 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4101 | TestGroupId("a"))); |
| 4102 | EXPECT_EQ(0u, |
| 4103 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4104 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4105 | |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4106 | client_socket_factory_.SignalJobs(); |
| 4107 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 4108 | EXPECT_THAT(preconnect_callback.WaitForResult(), IsOk()); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4109 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4110 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4111 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4112 | TestGroupId("a"))); |
| 4113 | EXPECT_EQ(0u, |
| 4114 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4115 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4116 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4117 | |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 4118 | // Make sure if a preconnected socket is not fully connected when a request |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 4119 | // starts, it has a connect start time. |
| 4120 | TestLoadTimingInfoConnectedNotReused(handle1); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4121 | handle1.Reset(); |
| 4122 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4123 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4124 | } |
| 4125 | |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 4126 | // Checks that fully connected preconnect jobs have no connect times, and are |
| 4127 | // marked as reused. |
| 4128 | TEST_F(ClientSocketPoolBaseTest, ConnectedPreconnectJobsHaveNoConnectTimes) { |
| 4129 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 4130 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 4131 | |
| 4132 | EXPECT_EQ( |
| 4133 | OK, pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 1, |
| 4134 | CompletionOnceCallback(), NetLogWithSource())); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 4135 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4136 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 4137 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4138 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4139 | TestGroupId("a"))); |
| 4140 | EXPECT_EQ(0u, |
| 4141 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4142 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 4143 | |
| 4144 | ClientSocketHandle handle; |
| 4145 | TestCompletionCallback callback; |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4146 | EXPECT_EQ(OK, handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4147 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4148 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4149 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4150 | pool_.get(), NetLogWithSource())); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 4151 | |
| 4152 | // Make sure the idle socket was used. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4153 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 4154 | |
| 4155 | TestLoadTimingInfoConnectedReused(handle); |
| 4156 | handle.Reset(); |
| 4157 | TestLoadTimingInfoNotConnected(handle); |
| 4158 | } |
| 4159 | |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4160 | // http://crbug.com/64940 regression test. |
| 4161 | TEST_F(ClientSocketPoolBaseTest, PreconnectClosesIdleSocketRemovesGroup) { |
| 4162 | const int kMaxTotalSockets = 3; |
| 4163 | const int kMaxSocketsPerGroup = 2; |
| 4164 | CreatePool(kMaxTotalSockets, kMaxSocketsPerGroup); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4165 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4166 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 4167 | // Note that group id ordering matters here. "a" comes before "b", so |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4168 | // CloseOneIdleSocket() will try to close "a"'s idle socket. |
| 4169 | |
| 4170 | // Set up one idle socket in "a". |
| 4171 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 4172 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 4173 | EXPECT_EQ( |
| 4174 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4175 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4176 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4177 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4178 | pool_.get(), NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4179 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 4180 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4181 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4182 | TestGroupId("a"))); |
| 4183 | EXPECT_EQ(0u, |
| 4184 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4185 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4186 | |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4187 | client_socket_factory_.SignalJobs(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4188 | ASSERT_THAT(callback1.WaitForResult(), IsOk()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4189 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4190 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4191 | TestGroupId("a"))); |
| 4192 | EXPECT_EQ(0u, |
| 4193 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4194 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4195 | |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4196 | handle1.Reset(); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4197 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4198 | |
| 4199 | // Set up two active sockets in "b". |
| 4200 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 4201 | TestCompletionCallback callback2; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 4202 | EXPECT_EQ( |
| 4203 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4204 | handle1.Init(TestGroupId("b"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4205 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4206 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4207 | pool_.get(), NetLogWithSource())); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 4208 | EXPECT_EQ( |
| 4209 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4210 | handle2.Init(TestGroupId("b"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4211 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4212 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4213 | pool_.get(), NetLogWithSource())); |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4214 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4215 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("b"))); |
| 4216 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("b"))); |
| 4217 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4218 | TestGroupId("b"))); |
| 4219 | EXPECT_EQ(0u, |
| 4220 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("b"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4221 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("b"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4222 | |
| 4223 | client_socket_factory_.SignalJobs(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4224 | ASSERT_THAT(callback1.WaitForResult(), IsOk()); |
| 4225 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4226 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("b"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4227 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4228 | TestGroupId("b"))); |
| 4229 | EXPECT_EQ(0u, |
| 4230 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("b"))); |
| 4231 | EXPECT_EQ(2, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("b"))); |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4232 | |
| 4233 | // Now we have 1 idle socket in "a" and 2 active sockets in "b". This means |
| 4234 | // we've maxed out on sockets, since we set |kMaxTotalSockets| to 3. |
| 4235 | // Requesting 2 preconnected sockets for "a" should fail to allocate any more |
| 4236 | // sockets for "a", and "b" should still have 2 active sockets. |
| 4237 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 4238 | EXPECT_EQ( |
| 4239 | OK, pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 4240 | CompletionOnceCallback(), NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4241 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4242 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4243 | TestGroupId("a"))); |
| 4244 | EXPECT_EQ(0u, |
| 4245 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4246 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4247 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
| 4248 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("b"))); |
| 4249 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4250 | TestGroupId("b"))); |
| 4251 | EXPECT_EQ(0u, |
| 4252 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("b"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4253 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("b"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4254 | EXPECT_EQ(2, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("b"))); |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4255 | |
| 4256 | // Now release the 2 active sockets for "b". This will give us 1 idle socket |
| 4257 | // in "a" and 2 idle sockets in "b". Requesting 2 preconnected sockets for |
| 4258 | // "a" should result in closing 1 for "b". |
| 4259 | handle1.Reset(); |
| 4260 | handle2.Reset(); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4261 | EXPECT_EQ(2u, pool_->IdleSocketCountInGroup(TestGroupId("b"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4262 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("b"))); |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4263 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 4264 | TestCompletionCallback preconnect_callback; |
| 4265 | EXPECT_EQ(ERR_IO_PENDING, |
| 4266 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 4267 | preconnect_callback.callback(), |
| 4268 | NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4269 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4270 | EXPECT_EQ(1u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4271 | TestGroupId("a"))); |
| 4272 | EXPECT_EQ(1u, |
| 4273 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4274 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4275 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
| 4276 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("b"))); |
| 4277 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4278 | TestGroupId("b"))); |
| 4279 | EXPECT_EQ(0u, |
| 4280 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("b"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4281 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(TestGroupId("b"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4282 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("b"))); |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4283 | } |
| 4284 | |
[email protected] | b7b8be4 | 2011-07-12 12:46:41 | [diff] [blame] | 4285 | TEST_F(ClientSocketPoolBaseTest, PreconnectWithoutBackupJob) { |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4286 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, |
| 4287 | true /* enable_backup_connect_jobs */); |
[email protected] | a9fc8fc | 2011-05-10 02:41:07 | [diff] [blame] | 4288 | |
| 4289 | // Make the ConnectJob hang until it times out, shorten the timeout. |
| 4290 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 4291 | connect_job_factory_->set_timeout_duration(base::Milliseconds(500)); |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 4292 | TestCompletionCallback preconnect_callback; |
| 4293 | EXPECT_EQ(ERR_IO_PENDING, |
| 4294 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 1, |
| 4295 | preconnect_callback.callback(), |
| 4296 | NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4297 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4298 | EXPECT_EQ(1u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4299 | TestGroupId("a"))); |
| 4300 | EXPECT_EQ(1u, |
| 4301 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4302 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | a9fc8fc | 2011-05-10 02:41:07 | [diff] [blame] | 4303 | |
[email protected] | b7b8be4 | 2011-07-12 12:46:41 | [diff] [blame] | 4304 | // Verify the backup timer doesn't create a backup job, by making |
| 4305 | // the backup job a pending job instead of a waiting job, so it |
| 4306 | // *would* complete if it were created. |
Lukasz Krakowiak | 28dcf9d6 | 2020-06-04 09:46:59 | [diff] [blame] | 4307 | base::RunLoop loop; |
[email protected] | a9fc8fc | 2011-05-10 02:41:07 | [diff] [blame] | 4308 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
Sean Maher | 5b9af51f | 2022-11-21 15:32:47 | [diff] [blame] | 4309 | base::SingleThreadTaskRunner::GetCurrentDefault()->PostDelayedTask( |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 4310 | FROM_HERE, loop.QuitClosure(), base::Seconds(1)); |
Lukasz Krakowiak | 28dcf9d6 | 2020-06-04 09:46:59 | [diff] [blame] | 4311 | loop.Run(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4312 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
[email protected] | a9fc8fc | 2011-05-10 02:41:07 | [diff] [blame] | 4313 | } |
| 4314 | |
[email protected] | b7b8be4 | 2011-07-12 12:46:41 | [diff] [blame] | 4315 | TEST_F(ClientSocketPoolBaseTest, PreconnectWithBackupJob) { |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4316 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, |
| 4317 | true /* enable_backup_connect_jobs */); |
[email protected] | a9fc8fc | 2011-05-10 02:41:07 | [diff] [blame] | 4318 | |
| 4319 | // Make the ConnectJob hang forever. |
| 4320 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 4321 | TestCompletionCallback preconnect_callback; |
| 4322 | EXPECT_EQ(ERR_IO_PENDING, |
| 4323 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 1, |
| 4324 | preconnect_callback.callback(), |
| 4325 | NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4326 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4327 | EXPECT_EQ(1u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4328 | TestGroupId("a"))); |
| 4329 | EXPECT_EQ(1u, |
| 4330 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4331 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 4332 | base::RunLoop().RunUntilIdle(); |
[email protected] | a9fc8fc | 2011-05-10 02:41:07 | [diff] [blame] | 4333 | |
| 4334 | // Make the backup job be a pending job, so it completes normally. |
| 4335 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 4336 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 4337 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4338 | EXPECT_EQ( |
| 4339 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4340 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4341 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 4342 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4343 | pool_.get(), NetLogWithSource())); |
[email protected] | b7b8be4 | 2011-07-12 12:46:41 | [diff] [blame] | 4344 | // Timer has started, but the backup connect job shouldn't be created yet. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4345 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4346 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4347 | TestGroupId("a"))); |
| 4348 | EXPECT_EQ(0u, |
| 4349 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4350 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4351 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4352 | ASSERT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | a9fc8fc | 2011-05-10 02:41:07 | [diff] [blame] | 4353 | |
| 4354 | // The hung connect job should still be there, but everything else should be |
| 4355 | // complete. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4356 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4357 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4358 | TestGroupId("a"))); |
| 4359 | EXPECT_EQ(1u, |
| 4360 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4361 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4362 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
[email protected] | a9fc8fc | 2011-05-10 02:41:07 | [diff] [blame] | 4363 | } |
| 4364 | |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 4365 | // Tests that a preconnect that starts out with unread data can still be used. |
| 4366 | // http://crbug.com/334467 |
| 4367 | TEST_F(ClientSocketPoolBaseTest, PreconnectWithUnreadData) { |
| 4368 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 4369 | connect_job_factory_->set_job_type(TestConnectJob::kMockUnreadDataJob); |
| 4370 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 4371 | EXPECT_EQ( |
| 4372 | OK, pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 1, |
| 4373 | CompletionOnceCallback(), NetLogWithSource())); |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 4374 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4375 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 4376 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4377 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4378 | TestGroupId("a"))); |
| 4379 | EXPECT_EQ(0u, |
| 4380 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4381 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 4382 | |
| 4383 | // Fail future jobs to be sure that handle receives the preconnected socket |
| 4384 | // rather than closing it and making a new one. |
| 4385 | connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); |
| 4386 | ClientSocketHandle handle; |
| 4387 | TestCompletionCallback callback; |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4388 | EXPECT_EQ(OK, handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4389 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4390 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4391 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4392 | pool_.get(), NetLogWithSource())); |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 4393 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4394 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 4395 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4396 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4397 | TestGroupId("a"))); |
| 4398 | EXPECT_EQ(0u, |
| 4399 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4400 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4401 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 4402 | |
| 4403 | // Drain the pending read. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 4404 | EXPECT_EQ(1, handle.socket()->Read(nullptr, 1, CompletionOnceCallback())); |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 4405 | |
| 4406 | TestLoadTimingInfoConnectedReused(handle); |
| 4407 | handle.Reset(); |
| 4408 | |
| 4409 | // The socket should be usable now that it's idle again. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4410 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 4411 | } |
| 4412 | |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4413 | TEST_F(ClientSocketPoolBaseTest, RequestGetsAssignedJob) { |
| 4414 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 4415 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 4416 | |
| 4417 | ClientSocketHandle handle1; |
| 4418 | TestCompletionCallback callback1; |
| 4419 | EXPECT_EQ( |
| 4420 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4421 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4422 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4423 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4424 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4425 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4426 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4427 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4428 | TestGroupId("a"))); |
| 4429 | EXPECT_EQ(0u, |
| 4430 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4431 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4432 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4433 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4434 | &handle1)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4435 | } |
| 4436 | |
| 4437 | TEST_F(ClientSocketPoolBaseTest, MultipleRequestsGetAssignedJobs) { |
| 4438 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 4439 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 4440 | |
| 4441 | ClientSocketHandle handle1; |
| 4442 | TestCompletionCallback callback1; |
| 4443 | EXPECT_EQ( |
| 4444 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4445 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4446 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4447 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4448 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4449 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4450 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4451 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4452 | TestGroupId("a"))); |
| 4453 | EXPECT_EQ(0u, |
| 4454 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4455 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4456 | |
| 4457 | ClientSocketHandle handle2; |
| 4458 | TestCompletionCallback callback2; |
| 4459 | EXPECT_EQ( |
| 4460 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4461 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4462 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4463 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4464 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4465 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4466 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4467 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4468 | TestGroupId("a"))); |
| 4469 | EXPECT_EQ(0u, |
| 4470 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4471 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4472 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4473 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4474 | &handle1)); |
| 4475 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4476 | &handle2)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4477 | |
| 4478 | // One job completes. The other request should still have its job. |
| 4479 | client_socket_factory_.SignalJob(0); |
| 4480 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 4481 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4482 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4483 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4484 | TestGroupId("a"))); |
| 4485 | EXPECT_EQ(0u, |
| 4486 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4487 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4488 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4489 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4490 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4491 | &handle2)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4492 | } |
| 4493 | |
| 4494 | TEST_F(ClientSocketPoolBaseTest, PreconnectJobGetsAssignedToRequest) { |
| 4495 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 4496 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 4497 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 4498 | TestCompletionCallback preconnect_callback; |
| 4499 | EXPECT_EQ(ERR_IO_PENDING, |
| 4500 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 1, |
| 4501 | preconnect_callback.callback(), |
| 4502 | NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4503 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4504 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 4505 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4506 | EXPECT_EQ(1u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4507 | TestGroupId("a"))); |
| 4508 | EXPECT_EQ(1u, |
| 4509 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4510 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4511 | |
| 4512 | ClientSocketHandle handle1; |
| 4513 | TestCompletionCallback callback1; |
| 4514 | EXPECT_EQ( |
| 4515 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4516 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4517 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4518 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4519 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4520 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4521 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4522 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4523 | TestGroupId("a"))); |
| 4524 | EXPECT_EQ(0u, |
| 4525 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4526 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4527 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4528 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4529 | &handle1)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4530 | } |
| 4531 | |
| 4532 | TEST_F(ClientSocketPoolBaseTest, HigherPriorityRequestStealsJob) { |
| 4533 | CreatePool(kDefaultMaxSockets, 1); |
| 4534 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 4535 | |
| 4536 | ClientSocketHandle handle1; |
| 4537 | TestCompletionCallback callback1; |
| 4538 | EXPECT_EQ( |
| 4539 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4540 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4541 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4542 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4543 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4544 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4545 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4546 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4547 | TestGroupId("a"))); |
| 4548 | EXPECT_EQ(0u, |
| 4549 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4550 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4551 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4552 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4553 | &handle1)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4554 | |
| 4555 | // Insert a higher priority request |
| 4556 | ClientSocketHandle handle2; |
| 4557 | TestCompletionCallback callback2; |
| 4558 | EXPECT_EQ( |
| 4559 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4560 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, HIGHEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4561 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4562 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4563 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4564 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4565 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4566 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4567 | TestGroupId("a"))); |
| 4568 | EXPECT_EQ(0u, |
| 4569 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4570 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4571 | |
| 4572 | // The highest priority request should steal the job from the default priority |
| 4573 | // request. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4574 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4575 | &handle2)); |
| 4576 | EXPECT_FALSE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4577 | &handle1)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4578 | } |
| 4579 | |
| 4580 | TEST_F(ClientSocketPoolBaseTest, RequestStealsJobFromLowestRequestWithJob) { |
| 4581 | CreatePool(3, 3); |
| 4582 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 4583 | |
| 4584 | ClientSocketHandle handle_lowest; |
| 4585 | TestCompletionCallback callback_lowest; |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4586 | EXPECT_EQ( |
| 4587 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4588 | handle_lowest.Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4589 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 4590 | callback_lowest.callback(), |
| 4591 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 4592 | NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4593 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4594 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4595 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4596 | TestGroupId("a"))); |
| 4597 | EXPECT_EQ(0u, |
| 4598 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4599 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4600 | |
| 4601 | ClientSocketHandle handle_highest; |
| 4602 | TestCompletionCallback callback_highest; |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4603 | EXPECT_EQ( |
| 4604 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4605 | handle_highest.Init(TestGroupId("a"), params_, absl::nullopt, HIGHEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4606 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 4607 | callback_highest.callback(), |
| 4608 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 4609 | NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4610 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4611 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4612 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4613 | TestGroupId("a"))); |
| 4614 | EXPECT_EQ(0u, |
| 4615 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4616 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4617 | |
| 4618 | ClientSocketHandle handle_low; |
| 4619 | TestCompletionCallback callback_low; |
| 4620 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4621 | handle_low.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4622 | TestGroupId("a"), params_, absl::nullopt, LOW, SocketTag(), |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4623 | ClientSocketPool::RespectLimits::ENABLED, |
| 4624 | callback_low.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4625 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4626 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4627 | EXPECT_EQ(3u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4628 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4629 | TestGroupId("a"))); |
| 4630 | EXPECT_EQ(0u, |
| 4631 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4632 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4633 | |
| 4634 | ClientSocketHandle handle_lowest2; |
| 4635 | TestCompletionCallback callback_lowest2; |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4636 | EXPECT_EQ( |
| 4637 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4638 | handle_lowest2.Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4639 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 4640 | callback_lowest2.callback(), |
| 4641 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 4642 | NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4643 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4644 | EXPECT_EQ(3u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4645 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4646 | TestGroupId("a"))); |
| 4647 | EXPECT_EQ(0u, |
| 4648 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4649 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4650 | |
| 4651 | // The top three requests in the queue should have jobs. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4652 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4653 | &handle_highest)); |
| 4654 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4655 | &handle_low)); |
| 4656 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4657 | &handle_lowest)); |
| 4658 | EXPECT_FALSE(pool_->RequestInGroupWithHandleHasJobForTesting( |
| 4659 | TestGroupId("a"), &handle_lowest2)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4660 | |
| 4661 | // Add another request with medium priority. It should steal the job from the |
| 4662 | // lowest priority request with a job. |
| 4663 | ClientSocketHandle handle_medium; |
| 4664 | TestCompletionCallback callback_medium; |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4665 | EXPECT_EQ( |
| 4666 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4667 | handle_medium.Init(TestGroupId("a"), params_, absl::nullopt, MEDIUM, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4668 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 4669 | callback_medium.callback(), |
| 4670 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 4671 | NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4672 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4673 | EXPECT_EQ(3u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4674 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4675 | TestGroupId("a"))); |
| 4676 | EXPECT_EQ(0u, |
| 4677 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4678 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
| 4679 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4680 | &handle_highest)); |
| 4681 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4682 | &handle_medium)); |
| 4683 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4684 | &handle_low)); |
| 4685 | EXPECT_FALSE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4686 | &handle_lowest)); |
| 4687 | EXPECT_FALSE(pool_->RequestInGroupWithHandleHasJobForTesting( |
| 4688 | TestGroupId("a"), &handle_lowest2)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4689 | } |
| 4690 | |
| 4691 | TEST_F(ClientSocketPoolBaseTest, ReprioritizeRequestStealsJob) { |
| 4692 | CreatePool(kDefaultMaxSockets, 1); |
| 4693 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 4694 | |
| 4695 | ClientSocketHandle handle1; |
| 4696 | TestCompletionCallback callback1; |
| 4697 | EXPECT_EQ( |
| 4698 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4699 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4700 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4701 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4702 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4703 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4704 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4705 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4706 | TestGroupId("a"))); |
| 4707 | EXPECT_EQ(0u, |
| 4708 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4709 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4710 | |
| 4711 | ClientSocketHandle handle2; |
| 4712 | TestCompletionCallback callback2; |
| 4713 | EXPECT_EQ( |
| 4714 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4715 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4716 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4717 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4718 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4719 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4720 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4721 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4722 | TestGroupId("a"))); |
| 4723 | EXPECT_EQ(0u, |
| 4724 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4725 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4726 | |
| 4727 | // The second request doesn't get a job because we are at the limit. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4728 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4729 | &handle1)); |
| 4730 | EXPECT_FALSE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4731 | &handle2)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4732 | |
| 4733 | // Reprioritizing the second request places it above the first, and it steals |
| 4734 | // the job from the first request. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4735 | pool_->SetPriority(TestGroupId("a"), &handle2, HIGHEST); |
| 4736 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4737 | &handle2)); |
| 4738 | EXPECT_FALSE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4739 | &handle1)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4740 | } |
| 4741 | |
| 4742 | TEST_F(ClientSocketPoolBaseTest, CancelRequestReassignsJob) { |
| 4743 | CreatePool(kDefaultMaxSockets, 1); |
| 4744 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 4745 | |
| 4746 | ClientSocketHandle handle1; |
| 4747 | TestCompletionCallback callback1; |
| 4748 | EXPECT_EQ( |
| 4749 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4750 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4751 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4752 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4753 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4754 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4755 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4756 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4757 | TestGroupId("a"))); |
| 4758 | EXPECT_EQ(0u, |
| 4759 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4760 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4761 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4762 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4763 | &handle1)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4764 | |
| 4765 | ClientSocketHandle handle2; |
| 4766 | TestCompletionCallback callback2; |
| 4767 | EXPECT_EQ( |
| 4768 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4769 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4770 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4771 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4772 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4773 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4774 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4775 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4776 | TestGroupId("a"))); |
| 4777 | EXPECT_EQ(0u, |
| 4778 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4779 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4780 | |
| 4781 | // The second request doesn't get a job because we are the limit. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4782 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4783 | &handle1)); |
| 4784 | EXPECT_FALSE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4785 | &handle2)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4786 | |
| 4787 | // The second request should get a job upon cancelling the first request. |
| 4788 | handle1.Reset(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4789 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4790 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4791 | TestGroupId("a"))); |
| 4792 | EXPECT_EQ(0u, |
| 4793 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4794 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4795 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4796 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4797 | &handle2)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4798 | } |
| 4799 | |
| 4800 | TEST_F(ClientSocketPoolBaseTest, JobCompletionReassignsJob) { |
| 4801 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 4802 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 4803 | |
| 4804 | ClientSocketHandle handle1; |
| 4805 | TestCompletionCallback callback1; |
| 4806 | EXPECT_EQ( |
| 4807 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4808 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, HIGHEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4809 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4810 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4811 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4812 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4813 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4814 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4815 | TestGroupId("a"))); |
| 4816 | EXPECT_EQ(0u, |
| 4817 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4818 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4819 | |
| 4820 | ClientSocketHandle handle2; |
| 4821 | TestCompletionCallback callback2; |
| 4822 | EXPECT_EQ( |
| 4823 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4824 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4825 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4826 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4827 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4828 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4829 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4830 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4831 | TestGroupId("a"))); |
| 4832 | EXPECT_EQ(0u, |
| 4833 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4834 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4835 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4836 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4837 | &handle1)); |
| 4838 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4839 | &handle2)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4840 | |
| 4841 | // The lower-priority job completes first. The higher-priority request should |
| 4842 | // get the socket, and the lower-priority request should get the remaining |
| 4843 | // job. |
| 4844 | client_socket_factory_.SignalJob(1); |
| 4845 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4846 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4847 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4848 | TestGroupId("a"))); |
| 4849 | EXPECT_EQ(0u, |
| 4850 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4851 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4852 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4853 | EXPECT_TRUE(handle1.socket()); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4854 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4855 | &handle2)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4856 | } |
| 4857 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 4858 | class MockLayeredPool : public HigherLayeredPool { |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4859 | public: |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4860 | MockLayeredPool(TransportClientSocketPool* pool, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4861 | const ClientSocketPool::GroupId& group_id) |
Tsuyoshi Horo | 2ec06e00 | 2022-06-09 01:38:59 | [diff] [blame] | 4862 | : pool_(pool), group_id_(group_id) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 4863 | pool_->AddHigherLayeredPool(this); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4864 | } |
| 4865 | |
Daniel Cheng | 4496d082 | 2018-04-26 21:52:15 | [diff] [blame] | 4866 | ~MockLayeredPool() override { pool_->RemoveHigherLayeredPool(this); } |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4867 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4868 | int RequestSocket(TransportClientSocketPool* pool) { |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4869 | return handle_.Init( |
Matt Menke | 870e19ab | 2019-04-23 16:23:03 | [diff] [blame] | 4870 | group_id_, ClientSocketPool::SocketParams::CreateForHttpForTesting(), |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4871 | absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4872 | ClientSocketPool::RespectLimits::ENABLED, callback_.callback(), |
| 4873 | ClientSocketPool::ProxyAuthCallback(), pool, NetLogWithSource()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4874 | } |
| 4875 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4876 | int RequestSocketWithoutLimits(TransportClientSocketPool* pool) { |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4877 | return handle_.Init( |
Matt Menke | 870e19ab | 2019-04-23 16:23:03 | [diff] [blame] | 4878 | group_id_, ClientSocketPool::SocketParams::CreateForHttpForTesting(), |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4879 | absl::nullopt, MAXIMUM_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4880 | ClientSocketPool::RespectLimits::DISABLED, callback_.callback(), |
| 4881 | ClientSocketPool::ProxyAuthCallback(), pool, NetLogWithSource()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4882 | } |
| 4883 | |
| 4884 | bool ReleaseOneConnection() { |
| 4885 | if (!handle_.is_initialized() || !can_release_connection_) { |
| 4886 | return false; |
| 4887 | } |
| 4888 | handle_.socket()->Disconnect(); |
| 4889 | handle_.Reset(); |
| 4890 | return true; |
| 4891 | } |
| 4892 | |
| 4893 | void set_can_release_connection(bool can_release_connection) { |
| 4894 | can_release_connection_ = can_release_connection; |
| 4895 | } |
| 4896 | |
| 4897 | MOCK_METHOD0(CloseOneIdleConnection, bool()); |
| 4898 | |
| 4899 | private: |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 4900 | const raw_ptr<TransportClientSocketPool> pool_; |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4901 | ClientSocketHandle handle_; |
| 4902 | TestCompletionCallback callback_; |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4903 | const ClientSocketPool::GroupId group_id_; |
Tsuyoshi Horo | 2ec06e00 | 2022-06-09 01:38:59 | [diff] [blame] | 4904 | bool can_release_connection_ = true; |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4905 | }; |
| 4906 | |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4907 | // Tests the basic case of closing an idle socket in a higher layered pool when |
| 4908 | // a new request is issued and the lower layer pool is stalled. |
| 4909 | TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketsHeldByLayeredPoolWhenNeeded) { |
| 4910 | CreatePool(1, 1); |
| 4911 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 4912 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4913 | MockLayeredPool mock_layered_pool(pool_.get(), TestGroupId("foo")); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4914 | EXPECT_THAT(mock_layered_pool.RequestSocket(pool_.get()), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4915 | EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection()) |
| 4916 | .WillOnce(Invoke(&mock_layered_pool, |
| 4917 | &MockLayeredPool::ReleaseOneConnection)); |
| 4918 | ClientSocketHandle handle; |
| 4919 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4920 | EXPECT_EQ( |
| 4921 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4922 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4923 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 4924 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4925 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4926 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4927 | } |
| 4928 | |
Matt Menke | 83367864 | 2019-03-05 22:05:51 | [diff] [blame] | 4929 | // Tests the case that trying to close an idle socket in a higher layered pool |
| 4930 | // fails. |
| 4931 | TEST_F(ClientSocketPoolBaseTest, |
| 4932 | CloseIdleSocketsHeldByLayeredPoolWhenNeededFails) { |
| 4933 | CreatePool(1, 1); |
| 4934 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 4935 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4936 | MockLayeredPool mock_layered_pool(pool_.get(), TestGroupId("foo")); |
Matt Menke | 83367864 | 2019-03-05 22:05:51 | [diff] [blame] | 4937 | mock_layered_pool.set_can_release_connection(false); |
| 4938 | EXPECT_THAT(mock_layered_pool.RequestSocket(pool_.get()), IsOk()); |
| 4939 | EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection()) |
| 4940 | .WillOnce(Invoke(&mock_layered_pool, |
| 4941 | &MockLayeredPool::ReleaseOneConnection)); |
| 4942 | ClientSocketHandle handle; |
| 4943 | TestCompletionCallback callback; |
| 4944 | EXPECT_EQ( |
| 4945 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4946 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4947 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 4948 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4949 | pool_.get(), NetLogWithSource())); |
Matt Menke | 83367864 | 2019-03-05 22:05:51 | [diff] [blame] | 4950 | base::RunLoop().RunUntilIdle(); |
| 4951 | EXPECT_FALSE(callback.have_result()); |
| 4952 | } |
| 4953 | |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4954 | // Same as above, but the idle socket is in the same group as the stalled |
| 4955 | // socket, and closes the only other request in its group when closing requests |
| 4956 | // in higher layered pools. This generally shouldn't happen, but it may be |
| 4957 | // possible if a higher level pool issues a request and the request is |
| 4958 | // subsequently cancelled. Even if it's not possible, best not to crash. |
| 4959 | TEST_F(ClientSocketPoolBaseTest, |
| 4960 | CloseIdleSocketsHeldByLayeredPoolWhenNeededSameGroup) { |
| 4961 | CreatePool(2, 2); |
| 4962 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 4963 | |
| 4964 | // Need a socket in another group for the pool to be stalled (If a group |
| 4965 | // has the maximum number of connections already, it's not stalled). |
| 4966 | ClientSocketHandle handle1; |
| 4967 | TestCompletionCallback callback1; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4968 | EXPECT_EQ(OK, handle1.Init(TestGroupId("group1"), params_, absl::nullopt, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4969 | DEFAULT_PRIORITY, SocketTag(), |
| 4970 | ClientSocketPool::RespectLimits::ENABLED, |
| 4971 | callback1.callback(), |
| 4972 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 4973 | NetLogWithSource())); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4974 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4975 | MockLayeredPool mock_layered_pool(pool_.get(), TestGroupId("group2")); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4976 | EXPECT_THAT(mock_layered_pool.RequestSocket(pool_.get()), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4977 | EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection()) |
| 4978 | .WillOnce(Invoke(&mock_layered_pool, |
| 4979 | &MockLayeredPool::ReleaseOneConnection)); |
| 4980 | ClientSocketHandle handle; |
| 4981 | TestCompletionCallback callback2; |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4982 | EXPECT_EQ(ERR_IO_PENDING, |
| 4983 | handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4984 | TestGroupId("group2"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4985 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 4986 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4987 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4988 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4989 | } |
| 4990 | |
| 4991 | // Tests the case when an idle socket can be closed when a new request is |
| 4992 | // issued, and the new request belongs to a group that was previously stalled. |
| 4993 | TEST_F(ClientSocketPoolBaseTest, |
| 4994 | CloseIdleSocketsHeldByLayeredPoolInSameGroupWhenNeeded) { |
| 4995 | CreatePool(2, 2); |
| 4996 | std::list<TestConnectJob::JobType> job_types; |
| 4997 | job_types.push_back(TestConnectJob::kMockJob); |
| 4998 | job_types.push_back(TestConnectJob::kMockJob); |
| 4999 | job_types.push_back(TestConnectJob::kMockJob); |
| 5000 | job_types.push_back(TestConnectJob::kMockJob); |
| 5001 | connect_job_factory_->set_job_types(&job_types); |
| 5002 | |
| 5003 | ClientSocketHandle handle1; |
| 5004 | TestCompletionCallback callback1; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5005 | EXPECT_EQ(OK, handle1.Init(TestGroupId("group1"), params_, absl::nullopt, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5006 | DEFAULT_PRIORITY, SocketTag(), |
| 5007 | ClientSocketPool::RespectLimits::ENABLED, |
| 5008 | callback1.callback(), |
| 5009 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 5010 | NetLogWithSource())); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5011 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5012 | MockLayeredPool mock_layered_pool(pool_.get(), TestGroupId("group2")); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5013 | EXPECT_THAT(mock_layered_pool.RequestSocket(pool_.get()), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5014 | EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection()) |
| 5015 | .WillRepeatedly(Invoke(&mock_layered_pool, |
| 5016 | &MockLayeredPool::ReleaseOneConnection)); |
| 5017 | mock_layered_pool.set_can_release_connection(false); |
| 5018 | |
| 5019 | // The third request is made when the socket pool is in a stalled state. |
| 5020 | ClientSocketHandle handle3; |
| 5021 | TestCompletionCallback callback3; |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5022 | EXPECT_EQ(ERR_IO_PENDING, |
| 5023 | handle3.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5024 | TestGroupId("group3"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5025 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 5026 | callback3.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 5027 | pool_.get(), NetLogWithSource())); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5028 | |
| 5029 | base::RunLoop().RunUntilIdle(); |
| 5030 | EXPECT_FALSE(callback3.have_result()); |
| 5031 | |
| 5032 | // The fourth request is made when the pool is no longer stalled. The third |
| 5033 | // request should be serviced first, since it was issued first and has the |
| 5034 | // same priority. |
| 5035 | mock_layered_pool.set_can_release_connection(true); |
| 5036 | ClientSocketHandle handle4; |
| 5037 | TestCompletionCallback callback4; |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5038 | EXPECT_EQ(ERR_IO_PENDING, |
| 5039 | handle4.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5040 | TestGroupId("group3"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5041 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 5042 | callback4.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 5043 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5044 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5045 | EXPECT_FALSE(callback4.have_result()); |
| 5046 | |
| 5047 | // Closing a handle should free up another socket slot. |
| 5048 | handle1.Reset(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5049 | EXPECT_THAT(callback4.WaitForResult(), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5050 | } |
| 5051 | |
| 5052 | // Tests the case when an idle socket can be closed when a new request is |
| 5053 | // issued, and the new request belongs to a group that was previously stalled. |
| 5054 | // |
| 5055 | // The two differences from the above test are that the stalled requests are not |
| 5056 | // in the same group as the layered pool's request, and the the fourth request |
| 5057 | // has a higher priority than the third one, so gets a socket first. |
| 5058 | TEST_F(ClientSocketPoolBaseTest, |
| 5059 | CloseIdleSocketsHeldByLayeredPoolInSameGroupWhenNeeded2) { |
| 5060 | CreatePool(2, 2); |
| 5061 | std::list<TestConnectJob::JobType> job_types; |
| 5062 | job_types.push_back(TestConnectJob::kMockJob); |
| 5063 | job_types.push_back(TestConnectJob::kMockJob); |
| 5064 | job_types.push_back(TestConnectJob::kMockJob); |
| 5065 | job_types.push_back(TestConnectJob::kMockJob); |
| 5066 | connect_job_factory_->set_job_types(&job_types); |
| 5067 | |
| 5068 | ClientSocketHandle handle1; |
| 5069 | TestCompletionCallback callback1; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5070 | EXPECT_EQ(OK, handle1.Init(TestGroupId("group1"), params_, absl::nullopt, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5071 | DEFAULT_PRIORITY, SocketTag(), |
| 5072 | ClientSocketPool::RespectLimits::ENABLED, |
| 5073 | callback1.callback(), |
| 5074 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 5075 | NetLogWithSource())); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5076 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5077 | MockLayeredPool mock_layered_pool(pool_.get(), TestGroupId("group2")); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5078 | EXPECT_THAT(mock_layered_pool.RequestSocket(pool_.get()), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5079 | EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection()) |
| 5080 | .WillRepeatedly(Invoke(&mock_layered_pool, |
| 5081 | &MockLayeredPool::ReleaseOneConnection)); |
| 5082 | mock_layered_pool.set_can_release_connection(false); |
| 5083 | |
| 5084 | // The third request is made when the socket pool is in a stalled state. |
| 5085 | ClientSocketHandle handle3; |
| 5086 | TestCompletionCallback callback3; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 5087 | EXPECT_EQ( |
| 5088 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5089 | handle3.Init(TestGroupId("group3"), params_, absl::nullopt, MEDIUM, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5090 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 5091 | callback3.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 5092 | pool_.get(), NetLogWithSource())); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5093 | |
| 5094 | base::RunLoop().RunUntilIdle(); |
| 5095 | EXPECT_FALSE(callback3.have_result()); |
| 5096 | |
| 5097 | // The fourth request is made when the pool is no longer stalled. This |
| 5098 | // request has a higher priority than the third request, so is serviced first. |
| 5099 | mock_layered_pool.set_can_release_connection(true); |
| 5100 | ClientSocketHandle handle4; |
| 5101 | TestCompletionCallback callback4; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 5102 | EXPECT_EQ( |
| 5103 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5104 | handle4.Init(TestGroupId("group3"), params_, absl::nullopt, HIGHEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5105 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 5106 | callback4.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 5107 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5108 | EXPECT_THAT(callback4.WaitForResult(), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5109 | EXPECT_FALSE(callback3.have_result()); |
| 5110 | |
| 5111 | // Closing a handle should free up another socket slot. |
| 5112 | handle1.Reset(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5113 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5114 | } |
| 5115 | |
| 5116 | TEST_F(ClientSocketPoolBaseTest, |
| 5117 | CloseMultipleIdleSocketsHeldByLayeredPoolWhenNeeded) { |
| 5118 | CreatePool(1, 1); |
| 5119 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 5120 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5121 | MockLayeredPool mock_layered_pool1(pool_.get(), TestGroupId("foo")); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5122 | EXPECT_THAT(mock_layered_pool1.RequestSocket(pool_.get()), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5123 | EXPECT_CALL(mock_layered_pool1, CloseOneIdleConnection()) |
| 5124 | .WillRepeatedly(Invoke(&mock_layered_pool1, |
| 5125 | &MockLayeredPool::ReleaseOneConnection)); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5126 | MockLayeredPool mock_layered_pool2(pool_.get(), TestGroupId("bar")); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5127 | EXPECT_THAT(mock_layered_pool2.RequestSocketWithoutLimits(pool_.get()), |
| 5128 | IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5129 | EXPECT_CALL(mock_layered_pool2, CloseOneIdleConnection()) |
| 5130 | .WillRepeatedly(Invoke(&mock_layered_pool2, |
| 5131 | &MockLayeredPool::ReleaseOneConnection)); |
| 5132 | ClientSocketHandle handle; |
| 5133 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 5134 | EXPECT_EQ( |
| 5135 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5136 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5137 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 5138 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 5139 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5140 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5141 | } |
| 5142 | |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5143 | // Test that when a socket pool and group are at their limits, a request |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5144 | // with RespectLimits::DISABLED triggers creation of a new socket, and gets the |
| 5145 | // socket instead of a request with the same priority that was issued earlier, |
| 5146 | // but has RespectLimits::ENABLED. |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5147 | TEST_F(ClientSocketPoolBaseTest, IgnoreLimits) { |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5148 | CreatePool(1, 1); |
| 5149 | |
| 5150 | // Issue a request to reach the socket pool limit. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5151 | EXPECT_EQ(OK, StartRequestWithIgnoreLimits( |
| 5152 | TestGroupId("a"), MAXIMUM_PRIORITY, |
| 5153 | ClientSocketPool::RespectLimits::ENABLED)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5154 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5155 | |
| 5156 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 5157 | |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5158 | EXPECT_EQ(ERR_IO_PENDING, StartRequestWithIgnoreLimits( |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5159 | TestGroupId("a"), MAXIMUM_PRIORITY, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5160 | ClientSocketPool::RespectLimits::ENABLED)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5161 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5162 | |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5163 | // Issue a request that ignores the limits, so a new ConnectJob is |
| 5164 | // created. |
| 5165 | EXPECT_EQ(ERR_IO_PENDING, StartRequestWithIgnoreLimits( |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5166 | TestGroupId("a"), MAXIMUM_PRIORITY, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5167 | ClientSocketPool::RespectLimits::DISABLED)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5168 | ASSERT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5169 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5170 | EXPECT_THAT(request(2)->WaitForResult(), IsOk()); |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5171 | EXPECT_FALSE(request(1)->have_result()); |
| 5172 | } |
| 5173 | |
[email protected] | c55fabd | 2013-11-04 23:26:56 | [diff] [blame] | 5174 | // Test that when a socket pool and group are at their limits, a ConnectJob |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5175 | // issued for a request with RespectLimits::DISABLED is not cancelled when a |
| 5176 | // request with RespectLimits::ENABLED issued to the same group is cancelled. |
[email protected] | c55fabd | 2013-11-04 23:26:56 | [diff] [blame] | 5177 | TEST_F(ClientSocketPoolBaseTest, IgnoreLimitsCancelOtherJob) { |
[email protected] | c55fabd | 2013-11-04 23:26:56 | [diff] [blame] | 5178 | CreatePool(1, 1); |
| 5179 | |
| 5180 | // Issue a request to reach the socket pool limit. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5181 | EXPECT_EQ(OK, StartRequestWithIgnoreLimits( |
| 5182 | TestGroupId("a"), MAXIMUM_PRIORITY, |
| 5183 | ClientSocketPool::RespectLimits::ENABLED)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5184 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | c55fabd | 2013-11-04 23:26:56 | [diff] [blame] | 5185 | |
| 5186 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 5187 | |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5188 | EXPECT_EQ(ERR_IO_PENDING, StartRequestWithIgnoreLimits( |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5189 | TestGroupId("a"), MAXIMUM_PRIORITY, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5190 | ClientSocketPool::RespectLimits::ENABLED)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5191 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | c55fabd | 2013-11-04 23:26:56 | [diff] [blame] | 5192 | |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5193 | // Issue a request with RespectLimits::DISABLED, so a new ConnectJob is |
| 5194 | // created. |
| 5195 | EXPECT_EQ(ERR_IO_PENDING, StartRequestWithIgnoreLimits( |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5196 | TestGroupId("a"), MAXIMUM_PRIORITY, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5197 | ClientSocketPool::RespectLimits::DISABLED)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5198 | ASSERT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5199 | |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5200 | // Cancel the pending request with RespectLimits::ENABLED. The ConnectJob |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5201 | // should not be cancelled. |
| 5202 | request(1)->handle()->Reset(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5203 | ASSERT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5204 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5205 | EXPECT_THAT(request(2)->WaitForResult(), IsOk()); |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5206 | EXPECT_FALSE(request(1)->have_result()); |
| 5207 | } |
| 5208 | |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5209 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthNoAuthCallback) { |
| 5210 | CreatePool(1, 1); |
| 5211 | |
| 5212 | connect_job_factory_->set_job_type(TestConnectJob::kMockAuthChallengeOnceJob); |
| 5213 | |
| 5214 | ClientSocketHandle handle; |
| 5215 | TestCompletionCallback callback; |
| 5216 | EXPECT_EQ( |
| 5217 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5218 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5219 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 5220 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 5221 | pool_.get(), NetLogWithSource())); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5222 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5223 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5224 | |
| 5225 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_PROXY_AUTH_REQUESTED)); |
| 5226 | EXPECT_FALSE(handle.is_initialized()); |
| 5227 | EXPECT_FALSE(handle.socket()); |
| 5228 | |
| 5229 | // The group should now be empty, and thus be deleted. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5230 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5231 | } |
| 5232 | |
| 5233 | class TestAuthHelper { |
| 5234 | public: |
| 5235 | TestAuthHelper() = default; |
Peter Boström | 293b134 | 2021-09-22 17:31:43 | [diff] [blame] | 5236 | |
| 5237 | TestAuthHelper(const TestAuthHelper&) = delete; |
| 5238 | TestAuthHelper& operator=(const TestAuthHelper&) = delete; |
| 5239 | |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5240 | ~TestAuthHelper() = default; |
| 5241 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5242 | void InitHandle( |
Matt Menke | 84d11e56 | 2019-03-27 00:11:19 | [diff] [blame] | 5243 | scoped_refptr<ClientSocketPool::SocketParams> params, |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5244 | TransportClientSocketPool* pool, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5245 | RequestPriority priority = DEFAULT_PRIORITY, |
| 5246 | ClientSocketPool::RespectLimits respect_limits = |
| 5247 | ClientSocketPool::RespectLimits::ENABLED, |
| 5248 | const ClientSocketPool::GroupId& group_id_in = TestGroupId("a")) { |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5249 | EXPECT_EQ(ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5250 | handle_.Init(group_id_in, params, absl::nullopt, priority, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5251 | SocketTag(), respect_limits, callback_.callback(), |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5252 | base::BindRepeating(&TestAuthHelper::AuthCallback, |
| 5253 | base::Unretained(this)), |
| 5254 | pool, NetLogWithSource())); |
| 5255 | } |
| 5256 | |
| 5257 | void WaitForAuth() { |
| 5258 | run_loop_ = std::make_unique<base::RunLoop>(); |
| 5259 | run_loop_->Run(); |
| 5260 | run_loop_.reset(); |
| 5261 | } |
| 5262 | |
| 5263 | void WaitForAuthAndRestartSync() { |
| 5264 | restart_sync_ = true; |
| 5265 | WaitForAuth(); |
| 5266 | restart_sync_ = false; |
| 5267 | } |
| 5268 | |
| 5269 | void WaitForAuthAndResetHandleSync() { |
| 5270 | reset_handle_sync_ = true; |
| 5271 | WaitForAuth(); |
| 5272 | reset_handle_sync_ = false; |
| 5273 | } |
| 5274 | |
| 5275 | void RestartWithAuth() { |
| 5276 | DCHECK(restart_with_auth_callback_); |
| 5277 | std::move(restart_with_auth_callback_).Run(); |
| 5278 | } |
| 5279 | |
| 5280 | int WaitForResult() { |
| 5281 | int result = callback_.WaitForResult(); |
| 5282 | // There shouldn't be any callback waiting to be invoked once the request is |
| 5283 | // complete. |
| 5284 | EXPECT_FALSE(restart_with_auth_callback_); |
| 5285 | // The socket should only be initialized on success. |
| 5286 | EXPECT_EQ(result == OK, handle_.is_initialized()); |
| 5287 | EXPECT_EQ(result == OK, handle_.socket() != nullptr); |
| 5288 | return result; |
| 5289 | } |
| 5290 | |
| 5291 | ClientSocketHandle* handle() { return &handle_; } |
| 5292 | int auth_count() const { return auth_count_; } |
| 5293 | int have_result() const { return callback_.have_result(); } |
| 5294 | |
| 5295 | private: |
| 5296 | void AuthCallback(const HttpResponseInfo& response, |
| 5297 | HttpAuthController* auth_controller, |
| 5298 | base::OnceClosure restart_with_auth_callback) { |
| 5299 | EXPECT_FALSE(restart_with_auth_callback_); |
| 5300 | EXPECT_TRUE(restart_with_auth_callback); |
| 5301 | |
| 5302 | // Once there's a result, this method shouldn't be invoked again. |
| 5303 | EXPECT_FALSE(callback_.have_result()); |
| 5304 | |
| 5305 | ++auth_count_; |
| 5306 | run_loop_->Quit(); |
| 5307 | if (restart_sync_) { |
| 5308 | std::move(restart_with_auth_callback).Run(); |
| 5309 | return; |
| 5310 | } |
| 5311 | |
| 5312 | restart_with_auth_callback_ = std::move(restart_with_auth_callback); |
| 5313 | |
| 5314 | if (reset_handle_sync_) { |
| 5315 | handle_.Reset(); |
| 5316 | return; |
| 5317 | } |
| 5318 | } |
| 5319 | |
| 5320 | std::unique_ptr<base::RunLoop> run_loop_; |
| 5321 | base::OnceClosure restart_with_auth_callback_; |
| 5322 | |
| 5323 | bool restart_sync_ = false; |
| 5324 | bool reset_handle_sync_ = false; |
| 5325 | |
| 5326 | ClientSocketHandle handle_; |
| 5327 | int auth_count_ = 0; |
| 5328 | TestCompletionCallback callback_; |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5329 | }; |
| 5330 | |
| 5331 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthOnce) { |
| 5332 | CreatePool(1, 1); |
| 5333 | connect_job_factory_->set_job_type(TestConnectJob::kMockAuthChallengeOnceJob); |
| 5334 | |
| 5335 | TestAuthHelper auth_helper; |
| 5336 | auth_helper.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5337 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 5338 | EXPECT_EQ(LOAD_STATE_CONNECTING, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5339 | pool_->GetLoadState(TestGroupId("a"), auth_helper.handle())); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5340 | |
| 5341 | auth_helper.WaitForAuth(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5342 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 5343 | EXPECT_EQ(LOAD_STATE_ESTABLISHING_PROXY_TUNNEL, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5344 | pool_->GetLoadState(TestGroupId("a"), auth_helper.handle())); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5345 | |
| 5346 | auth_helper.RestartWithAuth(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5347 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 5348 | EXPECT_EQ(LOAD_STATE_ESTABLISHING_PROXY_TUNNEL, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5349 | pool_->GetLoadState(TestGroupId("a"), auth_helper.handle())); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5350 | |
| 5351 | EXPECT_THAT(auth_helper.WaitForResult(), IsOk()); |
| 5352 | EXPECT_EQ(1, auth_helper.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5353 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 5354 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5355 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5356 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5357 | } |
| 5358 | |
| 5359 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthOnceSync) { |
| 5360 | CreatePool(1, 1); |
| 5361 | connect_job_factory_->set_job_type(TestConnectJob::kMockAuthChallengeOnceJob); |
| 5362 | |
| 5363 | TestAuthHelper auth_helper; |
| 5364 | auth_helper.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5365 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 5366 | EXPECT_EQ(LOAD_STATE_CONNECTING, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5367 | pool_->GetLoadState(TestGroupId("a"), auth_helper.handle())); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5368 | |
| 5369 | auth_helper.WaitForAuthAndRestartSync(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5370 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 5371 | EXPECT_EQ(LOAD_STATE_ESTABLISHING_PROXY_TUNNEL, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5372 | pool_->GetLoadState(TestGroupId("a"), auth_helper.handle())); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5373 | |
| 5374 | EXPECT_THAT(auth_helper.WaitForResult(), IsOk()); |
| 5375 | EXPECT_EQ(1, auth_helper.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5376 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 5377 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5378 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5379 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5380 | } |
| 5381 | |
| 5382 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthOnceFails) { |
| 5383 | CreatePool(1, 1); |
| 5384 | connect_job_factory_->set_job_type( |
| 5385 | TestConnectJob::kMockAuthChallengeOnceFailingJob); |
| 5386 | |
| 5387 | TestAuthHelper auth_helper; |
| 5388 | auth_helper.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5389 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5390 | |
| 5391 | auth_helper.WaitForAuth(); |
| 5392 | auth_helper.RestartWithAuth(); |
| 5393 | EXPECT_THAT(auth_helper.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
| 5394 | |
| 5395 | EXPECT_EQ(1, auth_helper.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5396 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5397 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5398 | } |
| 5399 | |
| 5400 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthOnceSyncFails) { |
| 5401 | CreatePool(1, 1); |
| 5402 | connect_job_factory_->set_job_type( |
| 5403 | TestConnectJob::kMockAuthChallengeOnceFailingJob); |
| 5404 | |
| 5405 | TestAuthHelper auth_helper; |
| 5406 | auth_helper.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5407 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5408 | |
| 5409 | auth_helper.WaitForAuthAndRestartSync(); |
| 5410 | EXPECT_THAT(auth_helper.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
| 5411 | |
| 5412 | EXPECT_EQ(1, auth_helper.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5413 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5414 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5415 | } |
| 5416 | |
| 5417 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthOnceDeleteHandle) { |
| 5418 | CreatePool(1, 1); |
| 5419 | connect_job_factory_->set_job_type(TestConnectJob::kMockAuthChallengeOnceJob); |
| 5420 | |
| 5421 | TestAuthHelper auth_helper; |
| 5422 | auth_helper.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5423 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5424 | |
| 5425 | auth_helper.WaitForAuth(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5426 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5427 | |
| 5428 | auth_helper.handle()->Reset(); |
| 5429 | |
| 5430 | EXPECT_EQ(1, auth_helper.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5431 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5432 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5433 | EXPECT_FALSE(auth_helper.handle()->is_initialized()); |
| 5434 | EXPECT_FALSE(auth_helper.handle()->socket()); |
| 5435 | } |
| 5436 | |
| 5437 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthOnceDeleteHandleSync) { |
| 5438 | CreatePool(1, 1); |
| 5439 | connect_job_factory_->set_job_type(TestConnectJob::kMockAuthChallengeOnceJob); |
| 5440 | |
| 5441 | TestAuthHelper auth_helper; |
| 5442 | auth_helper.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5443 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5444 | |
| 5445 | auth_helper.WaitForAuthAndResetHandleSync(); |
| 5446 | EXPECT_EQ(1, auth_helper.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5447 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5448 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5449 | EXPECT_FALSE(auth_helper.handle()->is_initialized()); |
| 5450 | EXPECT_FALSE(auth_helper.handle()->socket()); |
| 5451 | } |
| 5452 | |
| 5453 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthOnceFlushWithError) { |
| 5454 | CreatePool(1, 1); |
| 5455 | connect_job_factory_->set_job_type(TestConnectJob::kMockAuthChallengeOnceJob); |
| 5456 | |
| 5457 | TestAuthHelper auth_helper; |
| 5458 | auth_helper.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5459 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5460 | |
| 5461 | auth_helper.WaitForAuth(); |
| 5462 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 5463 | pool_->FlushWithError(ERR_FAILED, "Network changed"); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5464 | base::RunLoop().RunUntilIdle(); |
| 5465 | |
| 5466 | // When flushing the socket pool, bound sockets should delay returning the |
| 5467 | // error until completion. |
| 5468 | EXPECT_FALSE(auth_helper.have_result()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5469 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5470 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5471 | |
| 5472 | auth_helper.RestartWithAuth(); |
| 5473 | // The callback should be called asynchronously. |
| 5474 | EXPECT_FALSE(auth_helper.have_result()); |
| 5475 | |
| 5476 | EXPECT_THAT(auth_helper.WaitForResult(), IsError(ERR_FAILED)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5477 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5478 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5479 | } |
| 5480 | |
| 5481 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthTwice) { |
| 5482 | CreatePool(1, 1); |
| 5483 | connect_job_factory_->set_job_type( |
| 5484 | TestConnectJob::kMockAuthChallengeTwiceJob); |
| 5485 | |
| 5486 | TestAuthHelper auth_helper; |
| 5487 | auth_helper.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5488 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 5489 | EXPECT_EQ(LOAD_STATE_CONNECTING, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5490 | pool_->GetLoadState(TestGroupId("a"), auth_helper.handle())); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5491 | |
| 5492 | auth_helper.WaitForAuth(); |
| 5493 | auth_helper.RestartWithAuth(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5494 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5495 | EXPECT_EQ(1, auth_helper.auth_count()); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 5496 | EXPECT_EQ(LOAD_STATE_ESTABLISHING_PROXY_TUNNEL, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5497 | pool_->GetLoadState(TestGroupId("a"), auth_helper.handle())); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5498 | |
| 5499 | auth_helper.WaitForAuth(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5500 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 5501 | EXPECT_EQ(2, auth_helper.auth_count()); |
| 5502 | EXPECT_EQ(LOAD_STATE_ESTABLISHING_PROXY_TUNNEL, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5503 | pool_->GetLoadState(TestGroupId("a"), auth_helper.handle())); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 5504 | |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5505 | auth_helper.RestartWithAuth(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5506 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5507 | EXPECT_EQ(2, auth_helper.auth_count()); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 5508 | EXPECT_EQ(LOAD_STATE_ESTABLISHING_PROXY_TUNNEL, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5509 | pool_->GetLoadState(TestGroupId("a"), auth_helper.handle())); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5510 | |
| 5511 | EXPECT_THAT(auth_helper.WaitForResult(), IsOk()); |
| 5512 | EXPECT_EQ(2, auth_helper.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5513 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 5514 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5515 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5516 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5517 | } |
| 5518 | |
| 5519 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthTwiceFails) { |
| 5520 | CreatePool(1, 1); |
| 5521 | connect_job_factory_->set_job_type( |
| 5522 | TestConnectJob::kMockAuthChallengeTwiceFailingJob); |
| 5523 | |
| 5524 | TestAuthHelper auth_helper; |
| 5525 | auth_helper.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5526 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5527 | |
| 5528 | auth_helper.WaitForAuth(); |
| 5529 | auth_helper.RestartWithAuth(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5530 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5531 | EXPECT_EQ(1, auth_helper.auth_count()); |
| 5532 | |
| 5533 | auth_helper.WaitForAuth(); |
| 5534 | auth_helper.RestartWithAuth(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5535 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5536 | EXPECT_EQ(2, auth_helper.auth_count()); |
| 5537 | |
| 5538 | EXPECT_THAT(auth_helper.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
| 5539 | EXPECT_EQ(2, auth_helper.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5540 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5541 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5542 | } |
| 5543 | |
| 5544 | // Makes sure that when a bound request is destroyed, a new ConnectJob is |
| 5545 | // created, if needed. |
| 5546 | TEST_F(ClientSocketPoolBaseTest, |
| 5547 | ProxyAuthCreateNewConnectJobOnDestroyBoundRequest) { |
| 5548 | CreatePool(1 /* max_sockets */, 1 /* max_sockets_per_group */); |
| 5549 | connect_job_factory_->set_job_type( |
| 5550 | TestConnectJob::kMockAuthChallengeOnceFailingJob); |
| 5551 | |
| 5552 | // First request creates a ConnectJob. |
| 5553 | TestAuthHelper auth_helper1; |
| 5554 | auth_helper1.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5555 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5556 | |
| 5557 | // A second request come in, but no new ConnectJob is needed, since the limit |
| 5558 | // has been reached. |
| 5559 | TestAuthHelper auth_helper2; |
| 5560 | auth_helper2.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5561 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5562 | |
| 5563 | // Run until the auth callback for the first request is invoked. |
| 5564 | auth_helper1.WaitForAuth(); |
| 5565 | EXPECT_EQ(0, auth_helper2.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5566 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 5567 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5568 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5569 | |
| 5570 | // Make connect jobs succeed, then cancel the first request, which should |
| 5571 | // destroy the bound ConnectJob, and cause a new ConnectJob to start. |
| 5572 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 5573 | auth_helper1.handle()->Reset(); |
| 5574 | EXPECT_EQ(0, auth_helper2.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5575 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5576 | |
| 5577 | // The second ConnectJob should succeed. |
| 5578 | EXPECT_THAT(auth_helper2.WaitForResult(), IsOk()); |
| 5579 | EXPECT_EQ(0, auth_helper2.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5580 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5581 | } |
| 5582 | |
| 5583 | // Makes sure that when a bound request is destroyed, a new ConnectJob is |
| 5584 | // created for another group, if needed. |
| 5585 | TEST_F(ClientSocketPoolBaseTest, |
| 5586 | ProxyAuthCreateNewConnectJobOnDestroyBoundRequestDifferentGroups) { |
| 5587 | CreatePool(1 /* max_sockets */, 1 /* max_sockets_per_group */); |
| 5588 | connect_job_factory_->set_job_type( |
| 5589 | TestConnectJob::kMockAuthChallengeOnceFailingJob); |
| 5590 | |
| 5591 | // First request creates a ConnectJob. |
| 5592 | TestAuthHelper auth_helper1; |
| 5593 | auth_helper1.InitHandle(params_, pool_.get(), DEFAULT_PRIORITY); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5594 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5595 | |
| 5596 | // A second request come in, but no new ConnectJob is needed, since the limit |
| 5597 | // has been reached. |
| 5598 | TestAuthHelper auth_helper2; |
| 5599 | auth_helper2.InitHandle(params_, pool_.get(), DEFAULT_PRIORITY, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5600 | ClientSocketPool::RespectLimits::ENABLED, |
| 5601 | TestGroupId("b")); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5602 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 5603 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("b"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5604 | |
| 5605 | // Run until the auth callback for the first request is invoked. |
| 5606 | auth_helper1.WaitForAuth(); |
| 5607 | EXPECT_EQ(0, auth_helper2.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5608 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 5609 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5610 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5611 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("b"))); |
| 5612 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("b"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5613 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("b"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5614 | |
| 5615 | // Make connect jobs succeed, then cancel the first request, which should |
| 5616 | // destroy the bound ConnectJob, and cause a new ConnectJob to start for the |
| 5617 | // other group. |
| 5618 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 5619 | auth_helper1.handle()->Reset(); |
| 5620 | EXPECT_EQ(0, auth_helper2.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5621 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 5622 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("b"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5623 | |
| 5624 | // The second ConnectJob should succeed. |
| 5625 | EXPECT_THAT(auth_helper2.WaitForResult(), IsOk()); |
| 5626 | EXPECT_EQ(0, auth_helper2.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5627 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 5628 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("b"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5629 | } |
| 5630 | |
| 5631 | // Test that once an auth challenge is bound, that's the request that gets all |
| 5632 | // subsequent calls and the socket itself. |
| 5633 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthStaysBound) { |
| 5634 | CreatePool(1, 1); |
| 5635 | connect_job_factory_->set_job_type( |
| 5636 | TestConnectJob::kMockAuthChallengeTwiceJob); |
| 5637 | |
| 5638 | // First request creates a ConnectJob. |
| 5639 | TestAuthHelper auth_helper1; |
| 5640 | auth_helper1.InitHandle(params_, pool_.get(), LOWEST); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5641 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5642 | |
| 5643 | // A second, higher priority request is made. |
| 5644 | TestAuthHelper auth_helper2; |
| 5645 | auth_helper2.InitHandle(params_, pool_.get(), LOW); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5646 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5647 | |
| 5648 | // Run until the auth callback for the second request is invoked. |
| 5649 | auth_helper2.WaitForAuth(); |
| 5650 | EXPECT_EQ(0, auth_helper1.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5651 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 5652 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5653 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5654 | |
| 5655 | // Start a higher priority job. It shouldn't be able to steal |auth_helper2|'s |
| 5656 | // ConnectJob. |
| 5657 | TestAuthHelper auth_helper3; |
| 5658 | auth_helper3.InitHandle(params_, pool_.get(), HIGHEST); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5659 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5660 | |
| 5661 | // Start a higher job that ignores limits, creating a hanging socket. It |
| 5662 | // shouldn't be able to steal |auth_helper2|'s ConnectJob. |
| 5663 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 5664 | TestAuthHelper auth_helper4; |
| 5665 | auth_helper4.InitHandle(params_, pool_.get(), HIGHEST, |
| 5666 | ClientSocketPool::RespectLimits::DISABLED); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5667 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5668 | |
| 5669 | // Restart with auth, and |auth_helper2|'s auth method should be invoked |
| 5670 | // again. |
| 5671 | auth_helper2.RestartWithAuth(); |
| 5672 | auth_helper2.WaitForAuth(); |
| 5673 | EXPECT_EQ(0, auth_helper1.auth_count()); |
| 5674 | EXPECT_FALSE(auth_helper1.have_result()); |
| 5675 | EXPECT_EQ(2, auth_helper2.auth_count()); |
| 5676 | EXPECT_FALSE(auth_helper2.have_result()); |
| 5677 | EXPECT_EQ(0, auth_helper3.auth_count()); |
| 5678 | EXPECT_FALSE(auth_helper3.have_result()); |
| 5679 | EXPECT_EQ(0, auth_helper4.auth_count()); |
| 5680 | EXPECT_FALSE(auth_helper4.have_result()); |
| 5681 | |
| 5682 | // Advance auth again, and |auth_helper2| should get the socket. |
| 5683 | auth_helper2.RestartWithAuth(); |
| 5684 | EXPECT_THAT(auth_helper2.WaitForResult(), IsOk()); |
| 5685 | // The hung ConnectJob for the RespectLimits::DISABLED request is still in the |
| 5686 | // socket pool. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5687 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 5688 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5689 | EXPECT_EQ(0, auth_helper1.auth_count()); |
| 5690 | EXPECT_FALSE(auth_helper1.have_result()); |
| 5691 | EXPECT_EQ(0, auth_helper3.auth_count()); |
| 5692 | EXPECT_FALSE(auth_helper3.have_result()); |
| 5693 | EXPECT_EQ(0, auth_helper4.auth_count()); |
| 5694 | EXPECT_FALSE(auth_helper4.have_result()); |
| 5695 | |
| 5696 | // If the socket is returned to the socket pool, the RespectLimits::DISABLED |
| 5697 | // socket request should be able to claim it. |
| 5698 | auth_helper2.handle()->Reset(); |
| 5699 | EXPECT_THAT(auth_helper4.WaitForResult(), IsOk()); |
| 5700 | EXPECT_EQ(0, auth_helper1.auth_count()); |
| 5701 | EXPECT_FALSE(auth_helper1.have_result()); |
| 5702 | EXPECT_EQ(0, auth_helper3.auth_count()); |
| 5703 | EXPECT_FALSE(auth_helper3.have_result()); |
| 5704 | EXPECT_EQ(0, auth_helper4.auth_count()); |
| 5705 | } |
| 5706 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5707 | enum class RefreshType { |
| 5708 | kServer, |
| 5709 | kProxy, |
| 5710 | }; |
| 5711 | |
| 5712 | // Common base class to test RefreshGroup() when called from either |
| 5713 | // OnSSLConfigForServerChanged() matching a specific group or the pool's proxy. |
| 5714 | // |
| 5715 | // Tests which test behavior specific to one or the other case should use |
| 5716 | // ClientSocketPoolBaseTest directly. In particular, there is no "other group" |
| 5717 | // when the pool's proxy matches. |
| 5718 | class ClientSocketPoolBaseRefreshTest |
| 5719 | : public ClientSocketPoolBaseTest, |
| 5720 | public testing::WithParamInterface<RefreshType> { |
| 5721 | public: |
| 5722 | void CreatePoolForRefresh(int max_sockets, |
| 5723 | int max_sockets_per_group, |
| 5724 | bool enable_backup_connect_jobs = false) { |
| 5725 | switch (GetParam()) { |
| 5726 | case RefreshType::kServer: |
| 5727 | CreatePool(max_sockets, max_sockets_per_group, |
| 5728 | enable_backup_connect_jobs); |
| 5729 | break; |
| 5730 | case RefreshType::kProxy: |
| 5731 | CreatePoolWithIdleTimeouts( |
| 5732 | max_sockets, max_sockets_per_group, kUnusedIdleSocketTimeout, |
| 5733 | ClientSocketPool::used_idle_socket_timeout(), |
| 5734 | enable_backup_connect_jobs, |
Eric Orth | 5ccc3f0 | 2021-09-23 00:01:57 | [diff] [blame] | 5735 | PacResultElementToProxyServer("HTTPS myproxy:70")); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5736 | break; |
| 5737 | } |
| 5738 | } |
| 5739 | |
| 5740 | static ClientSocketPool::GroupId GetGroupId() { |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 5741 | return TestGroupId("a", 443, url::kHttpsScheme); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5742 | } |
| 5743 | |
David Benjamin | 6dd7e88 | 2019-10-10 02:35:23 | [diff] [blame] | 5744 | static ClientSocketPool::GroupId GetGroupIdInPartition() { |
| 5745 | // Note this GroupId will match GetGroupId() unless |
Brianna Goldstein | abb3aac | 2022-10-07 12:06:00 | [diff] [blame] | 5746 | // kPartitionConnectionsByNetworkAnonymizationKey is enabled. |
Matt Menke | 4807a9a | 2020-11-21 00:14:41 | [diff] [blame] | 5747 | const SchemefulSite kSite(GURL("https://b/")); |
Brianna Goldstein | a7593fca | 2022-09-28 02:59:32 | [diff] [blame] | 5748 | const NetworkAnonymizationKey kNetworkAnonymizationKey( |
| 5749 | kSite, kSite, /*is_cross_site=*/false); |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 5750 | return TestGroupId("a", 443, url::kHttpsScheme, |
David Benjamin | 6dd7e88 | 2019-10-10 02:35:23 | [diff] [blame] | 5751 | PrivacyMode::PRIVACY_MODE_DISABLED, |
Brianna Goldstein | a7593fca | 2022-09-28 02:59:32 | [diff] [blame] | 5752 | kNetworkAnonymizationKey); |
David Benjamin | 6dd7e88 | 2019-10-10 02:35:23 | [diff] [blame] | 5753 | } |
| 5754 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5755 | void OnSSLConfigForServerChanged() { |
| 5756 | switch (GetParam()) { |
| 5757 | case RefreshType::kServer: |
| 5758 | pool_->OnSSLConfigForServerChanged(HostPortPair("a", 443)); |
| 5759 | break; |
| 5760 | case RefreshType::kProxy: |
| 5761 | pool_->OnSSLConfigForServerChanged(HostPortPair("myproxy", 70)); |
| 5762 | break; |
| 5763 | } |
| 5764 | } |
| 5765 | }; |
| 5766 | |
| 5767 | INSTANTIATE_TEST_SUITE_P(RefreshType, |
| 5768 | ClientSocketPoolBaseRefreshTest, |
| 5769 | ::testing::Values(RefreshType::kServer, |
| 5770 | RefreshType::kProxy)); |
| 5771 | |
| 5772 | TEST_P(ClientSocketPoolBaseRefreshTest, RefreshGroupCreatesNewConnectJobs) { |
| 5773 | CreatePoolForRefresh(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 5774 | const ClientSocketPool::GroupId kGroupId = GetGroupId(); |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 5775 | |
| 5776 | // First job will be waiting until it gets aborted. |
| 5777 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 5778 | |
| 5779 | ClientSocketHandle handle; |
| 5780 | TestCompletionCallback callback; |
| 5781 | EXPECT_THAT( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5782 | handle.Init(kGroupId, params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5783 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 5784 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 5785 | pool_.get(), NetLogWithSource()), |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 5786 | IsError(ERR_IO_PENDING)); |
| 5787 | |
| 5788 | // Switch connect job types, so creating a new ConnectJob will result in |
| 5789 | // success. |
| 5790 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 5791 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5792 | OnSSLConfigForServerChanged(); |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 5793 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5794 | ASSERT_TRUE(handle.socket()); |
| 5795 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5796 | ASSERT_TRUE(pool_->HasGroupForTesting(kGroupId)); |
| 5797 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(kGroupId)); |
| 5798 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(kGroupId)); |
| 5799 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(kGroupId)); |
| 5800 | } |
| 5801 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5802 | TEST_P(ClientSocketPoolBaseRefreshTest, RefreshGroupClosesIdleConnectJobs) { |
David Benjamin | 6dd7e88 | 2019-10-10 02:35:23 | [diff] [blame] | 5803 | base::test::ScopedFeatureList feature_list; |
| 5804 | feature_list.InitAndEnableFeature( |
| 5805 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 5806 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5807 | CreatePoolForRefresh(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 5808 | const ClientSocketPool::GroupId kGroupId = GetGroupId(); |
David Benjamin | 6dd7e88 | 2019-10-10 02:35:23 | [diff] [blame] | 5809 | const ClientSocketPool::GroupId kGroupIdInPartition = GetGroupIdInPartition(); |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 5810 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 5811 | EXPECT_EQ( |
| 5812 | OK, pool_->RequestSockets(kGroupId, params_, absl::nullopt, 2, |
| 5813 | CompletionOnceCallback(), NetLogWithSource())); |
| 5814 | |
| 5815 | EXPECT_EQ( |
| 5816 | OK, pool_->RequestSockets(kGroupIdInPartition, params_, absl::nullopt, 2, |
| 5817 | CompletionOnceCallback(), NetLogWithSource())); |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 5818 | ASSERT_TRUE(pool_->HasGroupForTesting(kGroupId)); |
David Benjamin | 6dd7e88 | 2019-10-10 02:35:23 | [diff] [blame] | 5819 | ASSERT_TRUE(pool_->HasGroupForTesting(kGroupIdInPartition)); |
| 5820 | EXPECT_EQ(4, pool_->IdleSocketCount()); |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 5821 | EXPECT_EQ(2u, pool_->IdleSocketCountInGroup(kGroupId)); |
David Benjamin | 6dd7e88 | 2019-10-10 02:35:23 | [diff] [blame] | 5822 | EXPECT_EQ(2u, pool_->IdleSocketCountInGroup(kGroupIdInPartition)); |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 5823 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5824 | OnSSLConfigForServerChanged(); |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 5825 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5826 | EXPECT_FALSE(pool_->HasGroupForTesting(kGroupId)); |
David Benjamin | 6dd7e88 | 2019-10-10 02:35:23 | [diff] [blame] | 5827 | EXPECT_FALSE(pool_->HasGroupForTesting(kGroupIdInPartition)); |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 5828 | } |
| 5829 | |
| 5830 | TEST_F(ClientSocketPoolBaseTest, |
| 5831 | RefreshGroupDoesNotCloseIdleConnectJobsInOtherGroup) { |
| 5832 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5833 | const ClientSocketPool::GroupId kGroupId = |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 5834 | TestGroupId("a", 443, url::kHttpsScheme); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5835 | const ClientSocketPool::GroupId kOtherGroupId = |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 5836 | TestGroupId("b", 443, url::kHttpsScheme); |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 5837 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame] | 5838 | EXPECT_EQ( |
| 5839 | OK, pool_->RequestSockets(kOtherGroupId, params_, absl::nullopt, 2, |
| 5840 | CompletionOnceCallback(), NetLogWithSource())); |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 5841 | ASSERT_TRUE(pool_->HasGroupForTesting(kOtherGroupId)); |
| 5842 | EXPECT_EQ(2, pool_->IdleSocketCount()); |
| 5843 | EXPECT_EQ(2u, pool_->IdleSocketCountInGroup(kOtherGroupId)); |
| 5844 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5845 | pool_->OnSSLConfigForServerChanged(HostPortPair("a", 443)); |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 5846 | ASSERT_TRUE(pool_->HasGroupForTesting(kOtherGroupId)); |
| 5847 | EXPECT_EQ(2, pool_->IdleSocketCount()); |
| 5848 | EXPECT_EQ(2u, pool_->IdleSocketCountInGroup(kOtherGroupId)); |
| 5849 | } |
| 5850 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5851 | TEST_P(ClientSocketPoolBaseRefreshTest, RefreshGroupPreventsSocketReuse) { |
| 5852 | CreatePoolForRefresh(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 5853 | const ClientSocketPool::GroupId kGroupId = GetGroupId(); |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 5854 | |
| 5855 | ClientSocketHandle handle; |
| 5856 | TestCompletionCallback callback; |
| 5857 | EXPECT_THAT( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5858 | handle.Init(kGroupId, params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5859 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 5860 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 5861 | pool_.get(), NetLogWithSource()), |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 5862 | IsOk()); |
| 5863 | ASSERT_TRUE(pool_->HasGroupForTesting(kGroupId)); |
| 5864 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(kGroupId)); |
| 5865 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5866 | OnSSLConfigForServerChanged(); |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 5867 | |
| 5868 | handle.Reset(); |
| 5869 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5870 | EXPECT_FALSE(pool_->HasGroupForTesting(kGroupId)); |
| 5871 | } |
| 5872 | |
| 5873 | TEST_F(ClientSocketPoolBaseTest, |
| 5874 | RefreshGroupDoesNotPreventSocketReuseInOtherGroup) { |
| 5875 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5876 | const ClientSocketPool::GroupId kGroupId = |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 5877 | TestGroupId("a", 443, url::kHttpsScheme); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5878 | const ClientSocketPool::GroupId kOtherGroupId = |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 5879 | TestGroupId("b", 443, url::kHttpsScheme); |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 5880 | |
| 5881 | ClientSocketHandle handle; |
| 5882 | TestCompletionCallback callback; |
| 5883 | EXPECT_THAT( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5884 | handle.Init(kOtherGroupId, params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5885 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 5886 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 5887 | pool_.get(), NetLogWithSource()), |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 5888 | IsOk()); |
| 5889 | ASSERT_TRUE(pool_->HasGroupForTesting(kOtherGroupId)); |
| 5890 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(kOtherGroupId)); |
| 5891 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5892 | pool_->OnSSLConfigForServerChanged(HostPortPair("a", 443)); |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 5893 | |
| 5894 | handle.Reset(); |
| 5895 | EXPECT_EQ(1, pool_->IdleSocketCount()); |
| 5896 | ASSERT_TRUE(pool_->HasGroupForTesting(kOtherGroupId)); |
| 5897 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(kOtherGroupId)); |
| 5898 | } |
| 5899 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5900 | TEST_P(ClientSocketPoolBaseRefreshTest, |
| 5901 | RefreshGroupReplacesBoundConnectJobOnConnect) { |
| 5902 | CreatePoolForRefresh(1, 1); |
| 5903 | const ClientSocketPool::GroupId kGroupId = GetGroupId(); |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 5904 | connect_job_factory_->set_job_type(TestConnectJob::kMockAuthChallengeOnceJob); |
| 5905 | |
| 5906 | TestAuthHelper auth_helper; |
| 5907 | auth_helper.InitHandle(params_, pool_.get(), DEFAULT_PRIORITY, |
| 5908 | ClientSocketPool::RespectLimits::ENABLED, kGroupId); |
| 5909 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(kGroupId)); |
| 5910 | |
| 5911 | auth_helper.WaitForAuth(); |
| 5912 | |
| 5913 | // This should update the generation, but not cancel the old ConnectJob - it's |
| 5914 | // not safe to do anything while waiting on the original ConnectJob. |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5915 | OnSSLConfigForServerChanged(); |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 5916 | |
| 5917 | // Providing auth credentials and restarting the request with them will cause |
| 5918 | // the ConnectJob to complete successfully, but the result will be discarded |
| 5919 | // because of the generation mismatch. |
| 5920 | auth_helper.RestartWithAuth(); |
| 5921 | |
| 5922 | // Despite using ConnectJobs that simulate a single challenge, a second |
| 5923 | // challenge will be seen, due to using a new ConnectJob. |
| 5924 | auth_helper.WaitForAuth(); |
| 5925 | auth_helper.RestartWithAuth(); |
| 5926 | |
| 5927 | EXPECT_THAT(auth_helper.WaitForResult(), IsOk()); |
| 5928 | EXPECT_TRUE(auth_helper.handle()->socket()); |
| 5929 | EXPECT_EQ(2, auth_helper.auth_count()); |
| 5930 | |
| 5931 | // When released, the socket will be returned to the socket pool, and |
| 5932 | // available for reuse. |
| 5933 | auth_helper.handle()->Reset(); |
| 5934 | EXPECT_EQ(1, pool_->IdleSocketCount()); |
| 5935 | ASSERT_TRUE(pool_->HasGroupForTesting(kGroupId)); |
| 5936 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(kGroupId)); |
| 5937 | } |
| 5938 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5939 | TEST_F(ClientSocketPoolBaseTest, RefreshProxyRefreshesAllGroups) { |
| 5940 | CreatePoolWithIdleTimeouts(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, |
| 5941 | kUnusedIdleSocketTimeout, |
| 5942 | ClientSocketPool::used_idle_socket_timeout(), |
| 5943 | false /* no backup connect jobs */, |
Eric Orth | 5ccc3f0 | 2021-09-23 00:01:57 | [diff] [blame] | 5944 | PacResultElementToProxyServer("HTTPS myproxy:70")); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5945 | |
| 5946 | const ClientSocketPool::GroupId kGroupId1 = |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 5947 | TestGroupId("a", 443, url::kHttpsScheme); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5948 | const ClientSocketPool::GroupId kGroupId2 = |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 5949 | TestGroupId("b", 443, url::kHttpsScheme); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5950 | const ClientSocketPool::GroupId kGroupId3 = |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 5951 | TestGroupId("c", 443, url::kHttpsScheme); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5952 | |
| 5953 | // Make three sockets in three different groups. The third socket is released |
| 5954 | // to the pool as idle. |
| 5955 | ClientSocketHandle handle1, handle2, handle3; |
| 5956 | TestCompletionCallback callback; |
| 5957 | EXPECT_THAT( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5958 | handle1.Init(kGroupId1, params_, absl::nullopt, DEFAULT_PRIORITY, |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5959 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 5960 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 5961 | pool_.get(), NetLogWithSource()), |
| 5962 | IsOk()); |
| 5963 | EXPECT_THAT( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5964 | handle2.Init(kGroupId2, params_, absl::nullopt, DEFAULT_PRIORITY, |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5965 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 5966 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 5967 | pool_.get(), NetLogWithSource()), |
| 5968 | IsOk()); |
| 5969 | EXPECT_THAT( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5970 | handle3.Init(kGroupId3, params_, absl::nullopt, DEFAULT_PRIORITY, |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5971 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 5972 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 5973 | pool_.get(), NetLogWithSource()), |
| 5974 | IsOk()); |
| 5975 | handle3.Reset(); |
| 5976 | ASSERT_TRUE(pool_->HasGroupForTesting(kGroupId1)); |
| 5977 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(kGroupId1)); |
| 5978 | ASSERT_TRUE(pool_->HasGroupForTesting(kGroupId2)); |
| 5979 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(kGroupId2)); |
| 5980 | ASSERT_TRUE(pool_->HasGroupForTesting(kGroupId3)); |
| 5981 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(kGroupId3)); |
| 5982 | |
| 5983 | // Changes to some other proxy do not affect the pool. The idle socket remains |
| 5984 | // alive and closing |handle2| makes the socket available for the pool. |
| 5985 | pool_->OnSSLConfigForServerChanged(HostPortPair("someotherproxy", 70)); |
| 5986 | |
| 5987 | ASSERT_TRUE(pool_->HasGroupForTesting(kGroupId1)); |
| 5988 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(kGroupId1)); |
| 5989 | ASSERT_TRUE(pool_->HasGroupForTesting(kGroupId2)); |
| 5990 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(kGroupId2)); |
| 5991 | ASSERT_TRUE(pool_->HasGroupForTesting(kGroupId3)); |
| 5992 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(kGroupId3)); |
| 5993 | |
| 5994 | handle2.Reset(); |
| 5995 | ASSERT_TRUE(pool_->HasGroupForTesting(kGroupId2)); |
| 5996 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(kGroupId2)); |
| 5997 | |
| 5998 | // Changes to the matching proxy refreshes all groups. |
| 5999 | pool_->OnSSLConfigForServerChanged(HostPortPair("myproxy", 70)); |
| 6000 | |
| 6001 | // Idle sockets are closed. |
| 6002 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 6003 | EXPECT_FALSE(pool_->HasGroupForTesting(kGroupId2)); |
| 6004 | EXPECT_FALSE(pool_->HasGroupForTesting(kGroupId3)); |
| 6005 | |
| 6006 | // The active socket, however, continues to be active. |
| 6007 | ASSERT_TRUE(pool_->HasGroupForTesting(kGroupId1)); |
| 6008 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(kGroupId1)); |
| 6009 | |
| 6010 | // Closing it does not make it available for the pool. |
| 6011 | handle1.Reset(); |
| 6012 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 6013 | EXPECT_FALSE(pool_->HasGroupForTesting(kGroupId1)); |
| 6014 | } |
| 6015 | |
| 6016 | TEST_F(ClientSocketPoolBaseTest, RefreshBothPrivacyAndNormalSockets) { |
| 6017 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 6018 | |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 6019 | const ClientSocketPool::GroupId kGroupId = TestGroupId( |
| 6020 | "a", 443, url::kHttpsScheme, PrivacyMode::PRIVACY_MODE_DISABLED); |
| 6021 | const ClientSocketPool::GroupId kGroupIdPrivacy = TestGroupId( |
| 6022 | "a", 443, url::kHttpsScheme, PrivacyMode::PRIVACY_MODE_ENABLED); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 6023 | const ClientSocketPool::GroupId kOtherGroupId = |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 6024 | TestGroupId("b", 443, url::kHttpsScheme); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 6025 | |
| 6026 | // Make a socket in each groups. |
| 6027 | ClientSocketHandle handle1, handle2, handle3; |
| 6028 | TestCompletionCallback callback; |
| 6029 | EXPECT_THAT( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 6030 | handle1.Init(kGroupId, params_, absl::nullopt, DEFAULT_PRIORITY, |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 6031 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 6032 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 6033 | pool_.get(), NetLogWithSource()), |
| 6034 | IsOk()); |
| 6035 | EXPECT_THAT( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 6036 | handle2.Init(kGroupIdPrivacy, params_, absl::nullopt, DEFAULT_PRIORITY, |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 6037 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 6038 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 6039 | pool_.get(), NetLogWithSource()), |
| 6040 | IsOk()); |
| 6041 | EXPECT_THAT( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 6042 | handle3.Init(kOtherGroupId, params_, absl::nullopt, DEFAULT_PRIORITY, |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 6043 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 6044 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 6045 | pool_.get(), NetLogWithSource()), |
| 6046 | IsOk()); |
| 6047 | ASSERT_TRUE(pool_->HasGroupForTesting(kGroupId)); |
| 6048 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(kGroupId)); |
| 6049 | ASSERT_TRUE(pool_->HasGroupForTesting(kGroupIdPrivacy)); |
| 6050 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(kGroupIdPrivacy)); |
| 6051 | ASSERT_TRUE(pool_->HasGroupForTesting(kOtherGroupId)); |
| 6052 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(kOtherGroupId)); |
| 6053 | |
| 6054 | pool_->OnSSLConfigForServerChanged(HostPortPair("a", 443)); |
| 6055 | |
| 6056 | // Active sockets continue to be active. |
| 6057 | ASSERT_TRUE(pool_->HasGroupForTesting(kGroupId)); |
| 6058 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(kGroupId)); |
| 6059 | ASSERT_TRUE(pool_->HasGroupForTesting(kGroupIdPrivacy)); |
| 6060 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(kGroupIdPrivacy)); |
| 6061 | ASSERT_TRUE(pool_->HasGroupForTesting(kOtherGroupId)); |
| 6062 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(kOtherGroupId)); |
| 6063 | |
| 6064 | // Closing them leaves kOtherGroupId alone, but kGroupId and kGroupIdPrivacy |
| 6065 | // are unusable. |
| 6066 | handle1.Reset(); |
| 6067 | handle2.Reset(); |
| 6068 | handle3.Reset(); |
| 6069 | EXPECT_EQ(1, pool_->IdleSocketCount()); |
| 6070 | EXPECT_FALSE(pool_->HasGroupForTesting(kGroupId)); |
| 6071 | EXPECT_FALSE(pool_->HasGroupForTesting(kGroupIdPrivacy)); |
| 6072 | EXPECT_TRUE(pool_->HasGroupForTesting(kOtherGroupId)); |
| 6073 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(kOtherGroupId)); |
| 6074 | } |
| 6075 | |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 6076 | } // namespace |
| 6077 | |
| 6078 | } // namespace net |