[email protected] | e34400c3 | 2012-01-24 02:49:33 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[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 | |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 10 | #include "base/bind.h" |
[email protected] | 2041cf34 | 2010-02-19 03:15:59 | [diff] [blame] | 11 | #include "base/callback.h" |
danakj | db9ae794 | 2020-11-11 16:01:35 | [diff] [blame] | 12 | #include "base/callback_helpers.h" |
Hans Wennborg | 0924470b | 2020-04-27 21:08:05 | [diff] [blame] | 13 | #include "base/check_op.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" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 25 | #include "base/threading/thread_task_runner_handle.h" |
Gabriel Charette | d87f10f | 2022-03-31 00:44:22 | [diff] [blame] | 26 | #include "base/time/time.h" |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 27 | #include "base/values.h" |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 28 | #include "net/base/features.h" |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 29 | #include "net/base/host_port_pair.h" |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 30 | #include "net/base/load_timing_info.h" |
[email protected] | b258e079 | 2013-01-12 07:11:59 | [diff] [blame] | 31 | #include "net/base/load_timing_info_test_util.h" |
[email protected] | d8eb8424 | 2010-09-25 02:25:06 | [diff] [blame] | 32 | #include "net/base/net_errors.h" |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 33 | #include "net/base/network_isolation_key.h" |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 34 | #include "net/base/privacy_mode.h" |
Matt Menke | aafff54 | 2019-04-22 22:09:36 | [diff] [blame] | 35 | #include "net/base/proxy_server.h" |
Eric Orth | 5ccc3f0 | 2021-09-23 00:01:57 | [diff] [blame] | 36 | #include "net/base/proxy_string_util.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 37 | #include "net/base/request_priority.h" |
Matt Menke | 4807a9a | 2020-11-21 00:14:41 | [diff] [blame] | 38 | #include "net/base/schemeful_site.h" |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 39 | #include "net/base/test_completion_callback.h" |
dalyk | edd30d98 | 2019-12-16 15:31:10 | [diff] [blame] | 40 | #include "net/dns/public/resolve_error_info.h" |
Ben Schwartz | 3ff4dc1e6 | 2021-04-27 21:15:23 | [diff] [blame] | 41 | #include "net/dns/public/secure_dns_policy.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 42 | #include "net/http/http_response_headers.h" |
Matt Menke | 39b7c5a | 2019-04-10 19:47:51 | [diff] [blame] | 43 | #include "net/http/http_response_info.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 44 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 45 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 46 | #include "net/log/net_log_source.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 47 | #include "net/log/net_log_source_type.h" |
mmenke | 16a7cbdd | 2015-04-24 23:00:56 | [diff] [blame] | 48 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 49 | #include "net/log/test_net_log_util.h" |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 50 | #include "net/socket/client_socket_factory.h" |
| 51 | #include "net/socket/client_socket_handle.h" |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 52 | #include "net/socket/connect_job_factory.h" |
tfarina | 5dd13c2 | 2016-11-16 12:08:26 | [diff] [blame] | 53 | #include "net/socket/datagram_client_socket.h" |
tbansal | ca83c00 | 2016-04-28 20:56:28 | [diff] [blame] | 54 | #include "net/socket/socket_performance_watcher.h" |
Paul Jensen | 8d6f87ec | 2018-01-13 00:46:54 | [diff] [blame] | 55 | #include "net/socket/socket_tag.h" |
[email protected] | 75439d3b | 2009-07-23 22:11:17 | [diff] [blame] | 56 | #include "net/socket/socket_test_util.h" |
[email protected] | 18ccfdb | 2013-08-15 00:13:44 | [diff] [blame] | 57 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 3268023f | 2011-05-05 00:08:10 | [diff] [blame] | 58 | #include "net/socket/stream_socket.h" |
Daniel Cheng | 5feb16f | 2022-02-28 06:52:07 | [diff] [blame] | 59 | #include "net/socket/transport_client_socket_pool.h" |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 60 | #include "net/socket/transport_connect_job.h" |
Matt Menke | 39b7c5a | 2019-04-10 19:47:51 | [diff] [blame] | 61 | #include "net/ssl/ssl_cert_request_info.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 62 | #include "net/test/gtest_util.h" |
Gabriel Charette | c710874 | 2019-08-23 03:31:40 | [diff] [blame] | 63 | #include "net/test/test_with_task_environment.h" |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 64 | #include "net/traffic_annotation/network_traffic_annotation.h" |
Ramin Halavati | 0a08cc8 | 2018-02-06 07:46:38 | [diff] [blame] | 65 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
[email protected] | 51fdc7c | 2012-04-10 19:19:48 | [diff] [blame] | 66 | #include "testing/gmock/include/gmock/gmock.h" |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 67 | #include "testing/gtest/include/gtest/gtest.h" |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 68 | #include "third_party/abseil-cpp/absl/types/optional.h" |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 69 | #include "url/scheme_host_port.h" |
| 70 | #include "url/url_constants.h" |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 71 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 72 | using net::test::IsError; |
| 73 | using net::test::IsOk; |
| 74 | |
[email protected] | 51fdc7c | 2012-04-10 19:19:48 | [diff] [blame] | 75 | using ::testing::Invoke; |
| 76 | using ::testing::Return; |
| 77 | |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 78 | namespace net { |
| 79 | |
| 80 | namespace { |
| 81 | |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 82 | const int kDefaultMaxSockets = 4; |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 83 | const int kDefaultMaxSocketsPerGroup = 2; |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 84 | constexpr base::TimeDelta kUnusedIdleSocketTimeout = base::Seconds(10); |
[email protected] | 0b7648c | 2009-07-06 20:14:01 | [diff] [blame] | 85 | |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 86 | ClientSocketPool::GroupId TestGroupId( |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 87 | base::StringPiece host, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 88 | int port = 80, |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 89 | base::StringPiece scheme = url::kHttpScheme, |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 90 | PrivacyMode privacy_mode = PrivacyMode::PRIVACY_MODE_DISABLED, |
| 91 | NetworkIsolationKey network_isolation_key = NetworkIsolationKey()) { |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 92 | return ClientSocketPool::GroupId(url::SchemeHostPort(scheme, host, port), |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 93 | privacy_mode, network_isolation_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) |
| 151 | : connected_(false), |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 152 | has_unread_data_(false), |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 153 | net_log_(NetLogWithSource::Make(net_log, NetLogSourceType::SOCKET)), |
Charlie Harrison | 3e4c062 | 2018-05-13 15:44:30 | [diff] [blame] | 154 | was_used_to_convey_data_(false) {} |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 155 | |
Peter Boström | 407869b | 2021-10-07 04:42:48 | [diff] [blame] | 156 | MockClientSocket(const MockClientSocket&) = delete; |
| 157 | MockClientSocket& operator=(const MockClientSocket&) = delete; |
| 158 | |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 159 | // Sets whether the socket has unread data. If true, the next call to Read() |
| 160 | // will return 1 byte and IsConnectedAndIdle() will return false. |
| 161 | void set_has_unread_data(bool has_unread_data) { |
| 162 | has_unread_data_ = has_unread_data; |
| 163 | } |
| 164 | |
[email protected] | 3f55aa1 | 2011-12-07 02:03:33 | [diff] [blame] | 165 | // Socket implementation. |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 166 | int Read(IOBuffer* /* buf */, |
| 167 | int len, |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 168 | CompletionOnceCallback /* callback */) override { |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 169 | if (has_unread_data_ && len > 0) { |
| 170 | has_unread_data_ = false; |
| 171 | was_used_to_convey_data_ = true; |
| 172 | return 1; |
| 173 | } |
[email protected] | e86df8dc | 2013-03-30 13:18:28 | [diff] [blame] | 174 | return ERR_UNEXPECTED; |
[email protected] | 3f55aa1 | 2011-12-07 02:03:33 | [diff] [blame] | 175 | } |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 176 | |
[email protected] | a2b2cfc | 2017-12-06 09:06:08 | [diff] [blame] | 177 | int Write( |
| 178 | IOBuffer* /* buf */, |
| 179 | int len, |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 180 | CompletionOnceCallback /* callback */, |
[email protected] | a2b2cfc | 2017-12-06 09:06:08 | [diff] [blame] | 181 | const NetworkTrafficAnnotationTag& /*traffic_annotation*/) override { |
[email protected] | 0f873e8 | 2010-09-02 16:09:01 | [diff] [blame] | 182 | was_used_to_convey_data_ = true; |
| 183 | return len; |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 184 | } |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 185 | int SetReceiveBufferSize(int32_t size) override { return OK; } |
| 186 | int SetSendBufferSize(int32_t size) override { return OK; } |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 187 | |
[email protected] | dbf036f | 2011-12-06 23:33:24 | [diff] [blame] | 188 | // StreamSocket implementation. |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 189 | int Connect(CompletionOnceCallback callback) override { |
[email protected] | dbf036f | 2011-12-06 23:33:24 | [diff] [blame] | 190 | connected_ = true; |
| 191 | return OK; |
| 192 | } |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 193 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 194 | void Disconnect() override { connected_ = false; } |
| 195 | bool IsConnected() const override { return connected_; } |
| 196 | bool IsConnectedAndIdle() const override { |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 197 | return connected_ && !has_unread_data_; |
| 198 | } |
[email protected] | 0b7648c | 2009-07-06 20:14:01 | [diff] [blame] | 199 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 200 | int GetPeerAddress(IPEndPoint* /* address */) const override { |
[email protected] | 9f864b3 | 2010-01-20 15:01:16 | [diff] [blame] | 201 | return ERR_UNEXPECTED; |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 202 | } |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 203 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 204 | int GetLocalAddress(IPEndPoint* /* address */) const override { |
[email protected] | e7f74da | 2011-04-19 23:49:35 | [diff] [blame] | 205 | return ERR_UNEXPECTED; |
| 206 | } |
| 207 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 208 | const NetLogWithSource& NetLog() const override { return net_log_; } |
[email protected] | a2006ece | 2010-04-23 16:44:02 | [diff] [blame] | 209 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 210 | bool WasEverUsed() const override { return was_used_to_convey_data_; } |
tfarina | 2846404c | 2016-12-25 14:31:37 | [diff] [blame] | 211 | bool WasAlpnNegotiated() const override { return false; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 212 | NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; } |
| 213 | bool GetSSLInfo(SSLInfo* ssl_info) override { return false; } |
tbansal | f82cc8e | 2015-10-14 20:05:49 | [diff] [blame] | 214 | int64_t GetTotalReceivedBytes() const override { |
| 215 | NOTIMPLEMENTED(); |
| 216 | return 0; |
| 217 | } |
Paul Jensen | 0f49dec | 2017-12-12 23:39:58 | [diff] [blame] | 218 | void ApplySocketTag(const SocketTag& tag) override {} |
[email protected] | 9b5614a | 2010-08-25 20:29:45 | [diff] [blame] | 219 | |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 220 | private: |
| 221 | bool connected_; |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 222 | bool has_unread_data_; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 223 | NetLogWithSource net_log_; |
[email protected] | 0f873e8 | 2010-09-02 16:09:01 | [diff] [blame] | 224 | bool was_used_to_convey_data_; |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 225 | }; |
| 226 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 227 | class TestConnectJob; |
| 228 | |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 229 | class MockClientSocketFactory : public ClientSocketFactory { |
| 230 | public: |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 231 | MockClientSocketFactory() : allocation_count_(0) {} |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 232 | |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 233 | std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket( |
[email protected] | 5370c01 | 2011-06-29 03:47:04 | [diff] [blame] | 234 | DatagramSocket::BindType bind_type, |
[email protected] | 98b0e58 | 2011-06-22 14:31:41 | [diff] [blame] | 235 | NetLog* net_log, |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 236 | const NetLogSource& source) override { |
[email protected] | 98b0e58 | 2011-06-22 14:31:41 | [diff] [blame] | 237 | NOTREACHED(); |
David Benjamin | 24725be | 2019-07-24 20:57:18 | [diff] [blame] | 238 | return nullptr; |
[email protected] | 98b0e58 | 2011-06-22 14:31:41 | [diff] [blame] | 239 | } |
| 240 | |
Helen Li | d5bb922 | 2018-04-12 15:33:09 | [diff] [blame] | 241 | std::unique_ptr<TransportClientSocket> CreateTransportClientSocket( |
[email protected] | 0a0b768 | 2010-08-25 17:08:07 | [diff] [blame] | 242 | const AddressList& addresses, |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 243 | std::unique_ptr< |
| 244 | SocketPerformanceWatcher> /* socket_performance_watcher */, |
Eric Roman | 2bc7716 | 2020-09-16 18:30:45 | [diff] [blame] | 245 | NetworkQualityEstimator* /* network_quality_estimator */, |
[email protected] | 0a0b768 | 2010-08-25 17:08:07 | [diff] [blame] | 246 | NetLog* /* net_log */, |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 247 | const NetLogSource& /*source*/) override { |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 248 | allocation_count_++; |
Helen Li | d5bb922 | 2018-04-12 15:33:09 | [diff] [blame] | 249 | return nullptr; |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 250 | } |
| 251 | |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 252 | std::unique_ptr<SSLClientSocket> CreateSSLClientSocket( |
David Benjamin | 24725be | 2019-07-24 20:57:18 | [diff] [blame] | 253 | SSLClientContext* context, |
Matt Menke | 841fc41 | 2019-03-05 23:20:12 | [diff] [blame] | 254 | std::unique_ptr<StreamSocket> stream_socket, |
[email protected] | 4f4de7e6 | 2010-11-12 19:55:27 | [diff] [blame] | 255 | const HostPortPair& host_and_port, |
David Benjamin | 24725be | 2019-07-24 20:57:18 | [diff] [blame] | 256 | const SSLConfig& ssl_config) override { |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 257 | NOTIMPLEMENTED(); |
David Benjamin | 24725be | 2019-07-24 20:57:18 | [diff] [blame] | 258 | return nullptr; |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 259 | } |
Matt Menke | fd95692 | 2019-02-04 23:44:03 | [diff] [blame] | 260 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 261 | void WaitForSignal(TestConnectJob* job) { waiting_jobs_.push_back(job); } |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 262 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 263 | void SignalJobs(); |
| 264 | |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 265 | void SignalJob(size_t job); |
| 266 | |
| 267 | void SetJobLoadState(size_t job, LoadState load_state); |
| 268 | |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 269 | // Sets the HasConnectionEstablished value of the specified job to true, |
| 270 | // without invoking the callback. |
| 271 | void SetJobHasEstablishedConnection(size_t job); |
| 272 | |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 273 | int allocation_count() const { return allocation_count_; } |
| 274 | |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 275 | private: |
| 276 | int allocation_count_; |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 277 | std::vector<TestConnectJob*> waiting_jobs_; |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 278 | }; |
| 279 | |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 280 | class TestConnectJob : public ConnectJob { |
| 281 | public: |
| 282 | enum JobType { |
| 283 | kMockJob, |
| 284 | kMockFailingJob, |
| 285 | kMockPendingJob, |
| 286 | kMockPendingFailingJob, |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 287 | kMockWaitingJob, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 288 | |
| 289 | // Certificate errors return a socket in addition to an error code. |
| 290 | kMockCertErrorJob, |
| 291 | kMockPendingCertErrorJob, |
| 292 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 293 | kMockAdditionalErrorStateJob, |
| 294 | kMockPendingAdditionalErrorStateJob, |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 295 | kMockUnreadDataJob, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 296 | |
| 297 | kMockAuthChallengeOnceJob, |
| 298 | kMockAuthChallengeTwiceJob, |
| 299 | kMockAuthChallengeOnceFailingJob, |
| 300 | kMockAuthChallengeTwiceFailingJob, |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 301 | }; |
| 302 | |
[email protected] | 994d493 | 2010-07-12 17:55:13 | [diff] [blame] | 303 | // The kMockPendingJob uses a slight delay before allowing the connect |
| 304 | // to complete. |
| 305 | static const int kPendingConnectDelay = 2; |
| 306 | |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 307 | TestConnectJob(JobType job_type, |
Matt Menke | 16f5c2e5 | 2019-03-25 21:50:40 | [diff] [blame] | 308 | RequestPriority request_priority, |
| 309 | SocketTag socket_tag, |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 310 | base::TimeDelta timeout_duration, |
Matt Menke | a6f99ad | 2019-03-08 02:26:43 | [diff] [blame] | 311 | const CommonConnectJobParams* common_connect_job_params, |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 312 | ConnectJob::Delegate* delegate, |
Matt Menke | a6f99ad | 2019-03-08 02:26:43 | [diff] [blame] | 313 | MockClientSocketFactory* client_socket_factory) |
Matt Menke | 16f5c2e5 | 2019-03-25 21:50:40 | [diff] [blame] | 314 | : ConnectJob(request_priority, |
| 315 | socket_tag, |
Matt Menke | 1a6c92d | 2019-02-23 00:25:38 | [diff] [blame] | 316 | timeout_duration, |
Matt Menke | a6f99ad | 2019-03-08 02:26:43 | [diff] [blame] | 317 | common_connect_job_params, |
Matt Menke | 1a6c92d | 2019-02-23 00:25:38 | [diff] [blame] | 318 | delegate, |
| 319 | nullptr /* net_log */, |
| 320 | NetLogSourceType::TRANSPORT_CONNECT_JOB, |
| 321 | NetLogEventType::TRANSPORT_CONNECT_JOB_CONNECT), |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 322 | job_type_(job_type), |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 323 | client_socket_factory_(client_socket_factory), |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 324 | load_state_(LOAD_STATE_IDLE), |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 325 | has_established_connection_(false), |
Jeremy Roman | d54000b2 | 2019-07-08 18:40:16 | [diff] [blame] | 326 | store_additional_error_state_(false) {} |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 327 | |
Peter Boström | 407869b | 2021-10-07 04:42:48 | [diff] [blame] | 328 | TestConnectJob(const TestConnectJob&) = delete; |
| 329 | TestConnectJob& operator=(const TestConnectJob&) = delete; |
| 330 | |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 331 | void Signal() { |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 332 | DoConnect(waiting_success_, true /* async */, false /* recoverable */); |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 333 | } |
| 334 | |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 335 | void set_load_state(LoadState load_state) { load_state_ = load_state; } |
| 336 | |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 337 | void set_has_established_connection() { |
| 338 | DCHECK(!has_established_connection_); |
| 339 | has_established_connection_ = true; |
| 340 | } |
| 341 | |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 342 | // From ConnectJob: |
| 343 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 344 | LoadState GetLoadState() const override { return load_state_; } |
[email protected] | 4645135 | 2009-09-01 14:54:21 | [diff] [blame] | 345 | |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 346 | bool HasEstablishedConnection() const override { |
| 347 | return has_established_connection_; |
| 348 | } |
| 349 | |
dalyk | edd30d98 | 2019-12-16 15:31:10 | [diff] [blame] | 350 | ResolveErrorInfo GetResolveErrorInfo() const override { |
| 351 | return ResolveErrorInfo(OK); |
| 352 | } |
| 353 | |
Matt Menke | 6f84d1f1 | 2019-04-11 19:26:47 | [diff] [blame] | 354 | bool IsSSLError() const override { return store_additional_error_state_; } |
| 355 | |
| 356 | scoped_refptr<SSLCertRequestInfo> GetCertRequestInfo() override { |
| 357 | if (store_additional_error_state_) |
| 358 | return base::MakeRefCounted<SSLCertRequestInfo>(); |
| 359 | return nullptr; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 360 | } |
| 361 | |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 362 | private: |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 363 | // From ConnectJob: |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 364 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 365 | int ConnectInternal() override { |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 366 | AddressList ignored; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 367 | client_socket_factory_->CreateTransportClientSocket( |
Eric Roman | 2bc7716 | 2020-09-16 18:30:45 | [diff] [blame] | 368 | ignored, nullptr, nullptr, nullptr, NetLogSource()); |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 369 | switch (job_type_) { |
| 370 | case kMockJob: |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 371 | return DoConnect(true /* successful */, false /* sync */, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 372 | false /* cert_error */); |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 373 | case kMockFailingJob: |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 374 | return DoConnect(false /* error */, false /* sync */, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 375 | false /* cert_error */); |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 376 | case kMockPendingJob: |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 377 | set_load_state(LOAD_STATE_CONNECTING); |
[email protected] | 6b17538 | 2009-10-13 06:47:47 | [diff] [blame] | 378 | |
| 379 | // Depending on execution timings, posting a delayed task can result |
| 380 | // in the task getting executed the at the earliest possible |
| 381 | // opportunity or only after returning once from the message loop and |
| 382 | // then a second call into the message loop. In order to make behavior |
| 383 | // more deterministic, we change the default delay to 2ms. This should |
| 384 | // always require us to wait for the second call into the message loop. |
| 385 | // |
| 386 | // N.B. The correct fix for this and similar timing problems is to |
| 387 | // abstract time for the purpose of unittests. Unfortunately, we have |
| 388 | // a lot of third-party components that directly call the various |
| 389 | // time functions, so this change would be rather invasive. |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 390 | base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 391 | FROM_HERE, |
kylechar | f4fe517 | 2019-02-15 18:53:49 | [diff] [blame] | 392 | base::BindOnce(base::IgnoreResult(&TestConnectJob::DoConnect), |
| 393 | weak_factory_.GetWeakPtr(), true /* successful */, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 394 | true /* async */, false /* cert_error */), |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 395 | base::Milliseconds(kPendingConnectDelay)); |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 396 | return ERR_IO_PENDING; |
| 397 | case kMockPendingFailingJob: |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 398 | set_load_state(LOAD_STATE_CONNECTING); |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 399 | base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 400 | FROM_HERE, |
kylechar | f4fe517 | 2019-02-15 18:53:49 | [diff] [blame] | 401 | base::BindOnce(base::IgnoreResult(&TestConnectJob::DoConnect), |
| 402 | weak_factory_.GetWeakPtr(), false /* error */, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 403 | true /* async */, false /* cert_error */), |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 404 | base::Milliseconds(2)); |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 405 | return ERR_IO_PENDING; |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 406 | case kMockWaitingJob: |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 407 | set_load_state(LOAD_STATE_CONNECTING); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 408 | client_socket_factory_->WaitForSignal(this); |
| 409 | waiting_success_ = true; |
| 410 | return ERR_IO_PENDING; |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 411 | case kMockCertErrorJob: |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 412 | return DoConnect(false /* error */, false /* sync */, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 413 | true /* cert_error */); |
| 414 | case kMockPendingCertErrorJob: |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 415 | set_load_state(LOAD_STATE_CONNECTING); |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 416 | base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 417 | FROM_HERE, |
kylechar | f4fe517 | 2019-02-15 18:53:49 | [diff] [blame] | 418 | base::BindOnce(base::IgnoreResult(&TestConnectJob::DoConnect), |
| 419 | weak_factory_.GetWeakPtr(), false /* error */, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 420 | true /* async */, true /* cert_error */), |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 421 | base::Milliseconds(2)); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 422 | return ERR_IO_PENDING; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 423 | case kMockAdditionalErrorStateJob: |
| 424 | store_additional_error_state_ = true; |
| 425 | return DoConnect(false /* error */, false /* sync */, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 426 | false /* cert_error */); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 427 | case kMockPendingAdditionalErrorStateJob: |
| 428 | set_load_state(LOAD_STATE_CONNECTING); |
| 429 | store_additional_error_state_ = true; |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 430 | base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 431 | FROM_HERE, |
kylechar | f4fe517 | 2019-02-15 18:53:49 | [diff] [blame] | 432 | base::BindOnce(base::IgnoreResult(&TestConnectJob::DoConnect), |
| 433 | weak_factory_.GetWeakPtr(), false /* error */, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 434 | true /* async */, false /* cert_error */), |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 435 | base::Milliseconds(2)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 436 | return ERR_IO_PENDING; |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 437 | case kMockUnreadDataJob: { |
| 438 | int ret = DoConnect(true /* successful */, false /* sync */, |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 439 | false /* cert_error */); |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 440 | static_cast<MockClientSocket*>(socket())->set_has_unread_data(true); |
| 441 | return ret; |
| 442 | } |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 443 | case kMockAuthChallengeOnceJob: |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 444 | set_load_state(LOAD_STATE_CONNECTING); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 445 | DoAdvanceAuthChallenge(1, true /* succeed_after_last_challenge */); |
| 446 | return ERR_IO_PENDING; |
| 447 | case kMockAuthChallengeTwiceJob: |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 448 | set_load_state(LOAD_STATE_CONNECTING); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 449 | DoAdvanceAuthChallenge(2, true /* succeed_after_last_challenge */); |
| 450 | return ERR_IO_PENDING; |
| 451 | case kMockAuthChallengeOnceFailingJob: |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 452 | set_load_state(LOAD_STATE_CONNECTING); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 453 | DoAdvanceAuthChallenge(1, false /* succeed_after_last_challenge */); |
| 454 | return ERR_IO_PENDING; |
| 455 | case kMockAuthChallengeTwiceFailingJob: |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 456 | set_load_state(LOAD_STATE_CONNECTING); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 457 | DoAdvanceAuthChallenge(2, false /* succeed_after_last_challenge */); |
| 458 | return ERR_IO_PENDING; |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 459 | default: |
| 460 | NOTREACHED(); |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 461 | SetSocket(std::unique_ptr<StreamSocket>(), absl::nullopt); |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 462 | return ERR_FAILED; |
| 463 | } |
| 464 | } |
| 465 | |
Lily Chen | 02ef29a | 2018-11-30 16:31:43 | [diff] [blame] | 466 | void ChangePriorityInternal(RequestPriority priority) override {} |
| 467 | |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 468 | int DoConnect(bool succeed, bool was_async, bool cert_error) { |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 469 | int result = OK; |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 470 | has_established_connection_ = true; |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 471 | if (succeed) { |
Cammie Smith Barnes | aa2a8b5 | 2020-12-17 19:33:19 | [diff] [blame] | 472 | SetSocket(std::make_unique<MockClientSocket>(net_log().net_log()), |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 473 | absl::nullopt); |
Bence Béky | bdbb0e7 | 2018-08-07 21:42:59 | [diff] [blame] | 474 | socket()->Connect(CompletionOnceCallback()); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 475 | } else if (cert_error) { |
Cammie Smith Barnes | aa2a8b5 | 2020-12-17 19:33:19 | [diff] [blame] | 476 | SetSocket(std::make_unique<MockClientSocket>(net_log().net_log()), |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 477 | absl::nullopt); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 478 | result = ERR_CERT_COMMON_NAME_INVALID; |
[email protected] | 6e713f0 | 2009-08-06 02:56:40 | [diff] [blame] | 479 | } else { |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 480 | result = ERR_CONNECTION_FAILED; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 481 | SetSocket(std::unique_ptr<StreamSocket>(), absl::nullopt); |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 482 | } |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 483 | |
| 484 | if (was_async) |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 485 | NotifyDelegateOfCompletion(result); |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 486 | return result; |
| 487 | } |
| 488 | |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 489 | void DoAdvanceAuthChallenge(int remaining_challenges, |
| 490 | bool succeed_after_last_challenge) { |
| 491 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 492 | FROM_HERE, |
| 493 | base::BindOnce(&TestConnectJob::InvokeNextProxyAuthCallback, |
| 494 | weak_factory_.GetWeakPtr(), remaining_challenges, |
| 495 | succeed_after_last_challenge)); |
| 496 | } |
| 497 | |
| 498 | void InvokeNextProxyAuthCallback(int remaining_challenges, |
| 499 | bool succeed_after_last_challenge) { |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 500 | set_load_state(LOAD_STATE_ESTABLISHING_PROXY_TUNNEL); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 501 | if (remaining_challenges == 0) { |
| 502 | DoConnect(succeed_after_last_challenge, true /* was_async */, |
| 503 | false /* cert_error */); |
| 504 | return; |
| 505 | } |
| 506 | |
| 507 | // Integration tests make sure HttpResponseInfo and HttpAuthController work. |
| 508 | // The auth tests here are just focused on ConnectJob bookkeeping. |
| 509 | HttpResponseInfo info; |
| 510 | NotifyDelegateOfProxyAuth( |
| 511 | info, nullptr /* http_auth_controller */, |
| 512 | base::BindOnce(&TestConnectJob::DoAdvanceAuthChallenge, |
| 513 | weak_factory_.GetWeakPtr(), remaining_challenges - 1, |
| 514 | succeed_after_last_challenge)); |
| 515 | } |
| 516 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 517 | bool waiting_success_; |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 518 | const JobType job_type_; |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 519 | const raw_ptr<MockClientSocketFactory> client_socket_factory_; |
[email protected] | 4645135 | 2009-09-01 14:54:21 | [diff] [blame] | 520 | LoadState load_state_; |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 521 | bool has_established_connection_; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 522 | bool store_additional_error_state_; |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 523 | |
Jeremy Roman | d54000b2 | 2019-07-08 18:40:16 | [diff] [blame] | 524 | base::WeakPtrFactory<TestConnectJob> weak_factory_{this}; |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 525 | }; |
| 526 | |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 527 | class TestConnectJobFactory : public ConnectJobFactory { |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 528 | public: |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 529 | explicit TestConnectJobFactory(MockClientSocketFactory* client_socket_factory) |
| 530 | : client_socket_factory_(client_socket_factory) {} |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 531 | |
Peter Boström | 293b134 | 2021-09-22 17:31:43 | [diff] [blame] | 532 | TestConnectJobFactory(const TestConnectJobFactory&) = delete; |
| 533 | TestConnectJobFactory& operator=(const TestConnectJobFactory&) = delete; |
| 534 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 535 | ~TestConnectJobFactory() override = default; |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 536 | |
| 537 | void set_job_type(TestConnectJob::JobType job_type) { job_type_ = job_type; } |
| 538 | |
[email protected] | 51fdc7c | 2012-04-10 19:19:48 | [diff] [blame] | 539 | void set_job_types(std::list<TestConnectJob::JobType>* job_types) { |
| 540 | job_types_ = job_types; |
| 541 | CHECK(!job_types_->empty()); |
| 542 | } |
| 543 | |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 544 | void set_timeout_duration(base::TimeDelta timeout_duration) { |
| 545 | timeout_duration_ = timeout_duration; |
| 546 | } |
| 547 | |
[email protected] | 3f55aa1 | 2011-12-07 02:03:33 | [diff] [blame] | 548 | // ConnectJobFactory implementation. |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 549 | |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 550 | std::unique_ptr<ConnectJob> CreateConnectJob( |
Eric Orth | c98a3e6 | 2021-07-02 17:46:37 | [diff] [blame] | 551 | Endpoint endpoint, |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 552 | const ProxyServer& proxy_server, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 553 | const absl::optional<NetworkTrafficAnnotationTag>& proxy_annotation_tag, |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 554 | const SSLConfig* ssl_config_for_origin, |
| 555 | const SSLConfig* ssl_config_for_proxy, |
| 556 | bool force_tunnel, |
| 557 | PrivacyMode privacy_mode, |
| 558 | const OnHostResolutionCallback& resolution_callback, |
Matt Menke | 16f5c2e5 | 2019-03-25 21:50:40 | [diff] [blame] | 559 | RequestPriority request_priority, |
| 560 | SocketTag socket_tag, |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 561 | const NetworkIsolationKey& network_isolation_key, |
| 562 | SecureDnsPolicy secure_dns_policy, |
| 563 | const CommonConnectJobParams* common_connect_job_params, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 564 | ConnectJob::Delegate* delegate) const override { |
[email protected] | 51fdc7c | 2012-04-10 19:19:48 | [diff] [blame] | 565 | EXPECT_TRUE(!job_types_ || !job_types_->empty()); |
| 566 | TestConnectJob::JobType job_type = job_type_; |
| 567 | if (job_types_ && !job_types_->empty()) { |
| 568 | job_type = job_types_->front(); |
| 569 | job_types_->pop_front(); |
| 570 | } |
Matt Menke | a6f99ad | 2019-03-08 02:26:43 | [diff] [blame] | 571 | return std::make_unique<TestConnectJob>( |
Matt Menke | 16f5c2e5 | 2019-03-25 21:50:40 | [diff] [blame] | 572 | job_type, request_priority, socket_tag, timeout_duration_, |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 573 | common_connect_job_params, delegate, client_socket_factory_); |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | private: |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 577 | TestConnectJob::JobType job_type_ = TestConnectJob::kMockJob; |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 578 | raw_ptr<std::list<TestConnectJob::JobType>> job_types_ = nullptr; |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 579 | base::TimeDelta timeout_duration_; |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 580 | const raw_ptr<MockClientSocketFactory> client_socket_factory_; |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 581 | }; |
| 582 | |
[email protected] | a937a06d | 2009-08-19 21:19:24 | [diff] [blame] | 583 | } // namespace |
| 584 | |
[email protected] | a937a06d | 2009-08-19 21:19:24 | [diff] [blame] | 585 | namespace { |
| 586 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 587 | void MockClientSocketFactory::SignalJobs() { |
jdoerrie | 22a91d8b9 | 2018-10-05 08:43:26 | [diff] [blame] | 588 | for (auto it = waiting_jobs_.begin(); it != waiting_jobs_.end(); ++it) { |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 589 | (*it)->Signal(); |
| 590 | } |
| 591 | waiting_jobs_.clear(); |
| 592 | } |
| 593 | |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 594 | void MockClientSocketFactory::SignalJob(size_t job) { |
| 595 | ASSERT_LT(job, waiting_jobs_.size()); |
| 596 | waiting_jobs_[job]->Signal(); |
| 597 | waiting_jobs_.erase(waiting_jobs_.begin() + job); |
| 598 | } |
| 599 | |
| 600 | void MockClientSocketFactory::SetJobLoadState(size_t job, |
| 601 | LoadState load_state) { |
| 602 | ASSERT_LT(job, waiting_jobs_.size()); |
| 603 | waiting_jobs_[job]->set_load_state(load_state); |
| 604 | } |
| 605 | |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 606 | void MockClientSocketFactory::SetJobHasEstablishedConnection(size_t job) { |
| 607 | ASSERT_LT(job, waiting_jobs_.size()); |
| 608 | waiting_jobs_[job]->set_has_established_connection(); |
| 609 | } |
| 610 | |
Gabriel Charette | 694c3c33 | 2019-08-19 14:53:05 | [diff] [blame] | 611 | class ClientSocketPoolBaseTest : public TestWithTaskEnvironment { |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 612 | protected: |
Alex Clarke | 0def209 | 2018-12-10 12:01:45 | [diff] [blame] | 613 | ClientSocketPoolBaseTest() |
Gabriel Charette | 694c3c33 | 2019-08-19 14:53:05 | [diff] [blame] | 614 | : TestWithTaskEnvironment( |
| 615 | base::test::TaskEnvironment::TimeSource::MOCK_TIME), |
Matt Menke | 870e19ab | 2019-04-23 16:23:03 | [diff] [blame] | 616 | params_(ClientSocketPool::SocketParams::CreateForHttpForTesting()) { |
[email protected] | 636b825 | 2011-04-08 19:56:54 | [diff] [blame] | 617 | connect_backup_jobs_enabled_ = |
Matt Menke | 16f5c2e5 | 2019-03-25 21:50:40 | [diff] [blame] | 618 | TransportClientSocketPool::connect_backup_jobs_enabled(); |
| 619 | TransportClientSocketPool::set_connect_backup_jobs_enabled(true); |
[email protected] | 636b825 | 2011-04-08 19:56:54 | [diff] [blame] | 620 | } |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 621 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 622 | ~ClientSocketPoolBaseTest() override { |
Matt Menke | 16f5c2e5 | 2019-03-25 21:50:40 | [diff] [blame] | 623 | TransportClientSocketPool::set_connect_backup_jobs_enabled( |
[email protected] | 636b825 | 2011-04-08 19:56:54 | [diff] [blame] | 624 | connect_backup_jobs_enabled_); |
| 625 | } |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 626 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 627 | void CreatePool(int max_sockets, |
| 628 | int max_sockets_per_group, |
| 629 | bool enable_backup_connect_jobs = false) { |
Tarun Bansal | a763509 | 2019-02-20 10:00:59 | [diff] [blame] | 630 | CreatePoolWithIdleTimeouts(max_sockets, max_sockets_per_group, |
| 631 | kUnusedIdleSocketTimeout, |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 632 | ClientSocketPool::used_idle_socket_timeout(), |
| 633 | enable_backup_connect_jobs); |
[email protected] | 9bf28db | 2009-08-29 01:35:16 | [diff] [blame] | 634 | } |
| 635 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 636 | void CreatePoolWithIdleTimeouts( |
| 637 | int max_sockets, |
| 638 | int max_sockets_per_group, |
| 639 | base::TimeDelta unused_idle_socket_timeout, |
| 640 | base::TimeDelta used_idle_socket_timeout, |
| 641 | bool enable_backup_connect_jobs = false, |
| 642 | ProxyServer proxy_server = ProxyServer::Direct()) { |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 643 | DCHECK(!pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 644 | std::unique_ptr<TestConnectJobFactory> connect_job_factory = |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 645 | std::make_unique<TestConnectJobFactory>(&client_socket_factory_); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 646 | connect_job_factory_ = connect_job_factory.get(); |
| 647 | pool_ = TransportClientSocketPool::CreateForTesting( |
| 648 | max_sockets, max_sockets_per_group, unused_idle_socket_timeout, |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 649 | used_idle_socket_timeout, proxy_server, /*is_for_websockets=*/false, |
| 650 | &common_connect_job_params_, std::move(connect_job_factory), |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 651 | nullptr /* ssl_config_service */, enable_backup_connect_jobs); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 652 | } |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 653 | |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 654 | int StartRequestWithIgnoreLimits( |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 655 | const ClientSocketPool::GroupId& group_id, |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 656 | RequestPriority priority, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 657 | ClientSocketPool::RespectLimits respect_limits) { |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 658 | return test_base_.StartRequestUsingPool(pool_.get(), group_id, priority, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 659 | respect_limits, params_); |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 660 | } |
| 661 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 662 | int StartRequest(const ClientSocketPool::GroupId& group_id, |
| 663 | RequestPriority priority) { |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 664 | return StartRequestWithIgnoreLimits( |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 665 | group_id, priority, ClientSocketPool::RespectLimits::ENABLED); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 666 | } |
| 667 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 668 | int GetOrderOfRequest(size_t index) const { |
| 669 | return test_base_.GetOrderOfRequest(index); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 670 | } |
| 671 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 672 | bool ReleaseOneConnection(ClientSocketPoolTest::KeepAlive keep_alive) { |
| 673 | return test_base_.ReleaseOneConnection(keep_alive); |
| 674 | } |
| 675 | |
| 676 | void ReleaseAllConnections(ClientSocketPoolTest::KeepAlive keep_alive) { |
| 677 | test_base_.ReleaseAllConnections(keep_alive); |
| 678 | } |
| 679 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 680 | // Expects a single NetLogEventType::SOCKET_POOL_CLOSING_SOCKET in |net_log_|. |
| 681 | // It should be logged for the provided source and have the indicated reason. |
| 682 | void ExpectSocketClosedWithReason(NetLogSource expected_source, |
| 683 | const char* expected_reason) { |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 684 | auto entries = net_log_observer_.GetEntriesForSourceWithType( |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 685 | expected_source, NetLogEventType::SOCKET_POOL_CLOSING_SOCKET, |
| 686 | NetLogEventPhase::NONE); |
| 687 | ASSERT_EQ(1u, entries.size()); |
| 688 | ASSERT_TRUE(entries[0].HasParams()); |
| 689 | ASSERT_TRUE(entries[0].params.is_dict()); |
Matt Menke | ca721da | 2022-06-01 04:47:29 | [diff] [blame] | 690 | const std::string* reason = |
| 691 | entries[0].params.GetDict().FindString("reason"); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 692 | ASSERT_TRUE(reason); |
| 693 | EXPECT_EQ(expected_reason, *reason); |
| 694 | } |
| 695 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 696 | TestSocketRequest* request(int i) { return test_base_.request(i); } |
| 697 | size_t requests_size() const { return test_base_.requests_size(); } |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 698 | std::vector<std::unique_ptr<TestSocketRequest>>* requests() { |
olli.raula | 9d66b7d | 2015-11-23 08:30:42 | [diff] [blame] | 699 | return test_base_.requests(); |
| 700 | } |
rdsmith | 29dbad1 | 2017-02-17 02:22:18 | [diff] [blame] | 701 | // Only counts the requests that get sockets asynchronously; |
| 702 | // synchronous completions are not registered by this count. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 703 | size_t completion_count() const { return test_base_.completion_count(); } |
| 704 | |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 705 | const CommonConnectJobParams common_connect_job_params_{ |
| 706 | nullptr /* client_socket_factory */, |
| 707 | nullptr /* host_resolver */, |
| 708 | nullptr /* http_auth_cache */, |
| 709 | nullptr /* http_auth_handler_factory */, |
| 710 | nullptr /* spdy_session_pool */, |
| 711 | nullptr /* quic_supported_versions */, |
| 712 | nullptr /* quic_stream_factory */, |
| 713 | nullptr /* proxy_delegate */, |
| 714 | nullptr /* http_user_agent_settings */, |
| 715 | nullptr /* ssl_client_context */, |
| 716 | nullptr /* socket_performance_watcher_factory */, |
| 717 | nullptr /* network_quality_estimator */, |
Matt Reichhoff | 36a1fd6 | 2021-10-12 22:52:20 | [diff] [blame] | 718 | NetLog::Get(), |
Eric Orth | a9b8be0 | 2021-06-29 23:09:08 | [diff] [blame] | 719 | nullptr /* websocket_endpoint_lock_manager */}; |
[email protected] | 636b825 | 2011-04-08 19:56:54 | [diff] [blame] | 720 | bool connect_backup_jobs_enabled_; |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 721 | MockClientSocketFactory client_socket_factory_; |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 722 | raw_ptr<TestConnectJobFactory> connect_job_factory_; |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 723 | RecordingNetLogObserver net_log_observer_; |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 724 | // These parameters are never actually used to create a TransportConnectJob. |
Matt Menke | 84d11e56 | 2019-03-27 00:11:19 | [diff] [blame] | 725 | scoped_refptr<ClientSocketPool::SocketParams> params_; |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 726 | std::unique_ptr<TransportClientSocketPool> pool_; |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 727 | ClientSocketPoolTest test_base_; |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 728 | }; |
| 729 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 730 | TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 731 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 732 | |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 733 | TestCompletionCallback callback; |
[email protected] | a512f598 | 2009-08-18 16:01:06 | [diff] [blame] | 734 | ClientSocketHandle handle; |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 735 | NetLogWithSource net_log_with_source = |
| 736 | NetLogWithSource::Make(NetLogSourceType::NONE); |
| 737 | |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 738 | TestLoadTimingInfoNotConnected(handle); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 739 | |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 740 | EXPECT_EQ(OK, handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 741 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 742 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 743 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 744 | pool_.get(), net_log_with_source)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 745 | EXPECT_TRUE(handle.is_initialized()); |
| 746 | EXPECT_TRUE(handle.socket()); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 747 | TestLoadTimingInfoConnectedNotReused(handle); |
| 748 | |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 749 | handle.Reset(); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 750 | TestLoadTimingInfoNotConnected(handle); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 751 | |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 752 | auto entries = |
| 753 | net_log_observer_.GetEntriesForSource(net_log_with_source.source()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 754 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 755 | EXPECT_EQ(5u, entries.size()); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 756 | EXPECT_TRUE(LogContainsEvent( |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 757 | entries, 0, NetLogEventType::TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 758 | NetLogEventPhase::NONE)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 759 | EXPECT_TRUE(LogContainsBeginEvent(entries, 1, NetLogEventType::SOCKET_POOL)); |
| 760 | EXPECT_TRUE(LogContainsEvent( |
| 761 | entries, 2, NetLogEventType::SOCKET_POOL_BOUND_TO_CONNECT_JOB, |
| 762 | NetLogEventPhase::NONE)); |
| 763 | EXPECT_TRUE(LogContainsEvent(entries, 3, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 764 | NetLogEventType::SOCKET_POOL_BOUND_TO_SOCKET, |
| 765 | NetLogEventPhase::NONE)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 766 | EXPECT_TRUE(LogContainsEndEvent(entries, 4, NetLogEventType::SOCKET_POOL)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 767 | } |
| 768 | |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 769 | TEST_F(ClientSocketPoolBaseTest, InitConnectionFailure) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 770 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 771 | |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 772 | connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 773 | NetLogWithSource net_log_with_source = |
| 774 | NetLogWithSource::Make(NetLogSourceType::NONE); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 775 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 776 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 777 | TestCompletionCallback callback; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 778 | // Set the additional error state members to ensure that they get cleared. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 779 | handle.set_is_ssl_error(true); |
Matt Menke | 39b7c5a | 2019-04-10 19:47:51 | [diff] [blame] | 780 | handle.set_ssl_cert_request_info(base::MakeRefCounted<SSLCertRequestInfo>()); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 781 | EXPECT_EQ( |
| 782 | ERR_CONNECTION_FAILED, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 783 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 784 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 785 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 786 | pool_.get(), net_log_with_source)); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 787 | EXPECT_FALSE(handle.socket()); |
| 788 | EXPECT_FALSE(handle.is_ssl_error()); |
Matt Menke | 39b7c5a | 2019-04-10 19:47:51 | [diff] [blame] | 789 | EXPECT_FALSE(handle.ssl_cert_request_info()); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 790 | TestLoadTimingInfoNotConnected(handle); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 791 | |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 792 | auto entries = |
| 793 | net_log_observer_.GetEntriesForSource(net_log_with_source.source()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 794 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 795 | EXPECT_EQ(4u, entries.size()); |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 796 | EXPECT_TRUE(LogContainsEvent( |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 797 | entries, 0, NetLogEventType::TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 798 | NetLogEventPhase::NONE)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 799 | EXPECT_TRUE(LogContainsBeginEvent(entries, 1, NetLogEventType::SOCKET_POOL)); |
| 800 | EXPECT_TRUE(LogContainsEvent( |
| 801 | entries, 2, NetLogEventType::SOCKET_POOL_BOUND_TO_CONNECT_JOB, |
| 802 | NetLogEventPhase::NONE)); |
| 803 | EXPECT_TRUE(LogContainsEndEvent(entries, 3, NetLogEventType::SOCKET_POOL)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 804 | } |
| 805 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 806 | // Test releasing an open socket into the socket pool, telling the socket pool |
| 807 | // to close the socket. |
| 808 | TEST_F(ClientSocketPoolBaseTest, ReleaseAndCloseConnection) { |
| 809 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 810 | |
| 811 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(OK)); |
| 812 | ASSERT_TRUE(request(0)->handle()->socket()); |
| 813 | net::NetLogSource source = request(0)->handle()->socket()->NetLog().source(); |
| 814 | ReleaseOneConnection(ClientSocketPoolTest::NO_KEEP_ALIVE); |
| 815 | |
| 816 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 817 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 818 | |
| 819 | ExpectSocketClosedWithReason( |
| 820 | source, TransportClientSocketPool::kClosedConnectionReturnedToPool); |
| 821 | } |
| 822 | |
| 823 | TEST_F(ClientSocketPoolBaseTest, SocketWithUnreadDataReturnedToPool) { |
| 824 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 825 | connect_job_factory_->set_job_type(TestConnectJob::kMockUnreadDataJob); |
| 826 | |
| 827 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(OK)); |
| 828 | ASSERT_TRUE(request(0)->handle()->socket()); |
| 829 | net::NetLogSource source = request(0)->handle()->socket()->NetLog().source(); |
| 830 | EXPECT_TRUE(request(0)->handle()->socket()->IsConnected()); |
| 831 | EXPECT_FALSE(request(0)->handle()->socket()->IsConnectedAndIdle()); |
| 832 | ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE); |
| 833 | |
| 834 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 835 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 836 | |
| 837 | ExpectSocketClosedWithReason( |
| 838 | source, TransportClientSocketPool::kDataReceivedUnexpectedly); |
| 839 | } |
| 840 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 841 | // Make sure different groups do not share sockets. |
| 842 | TEST_F(ClientSocketPoolBaseTest, GroupSeparation) { |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 843 | base::test::ScopedFeatureList feature_list; |
| 844 | feature_list.InitAndEnableFeature( |
| 845 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 846 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 847 | CreatePool(1000 /* max_sockets */, 2 /* max_sockets_per_group */); |
| 848 | |
| 849 | const HostPortPair kHostPortPairs[] = { |
| 850 | {"a", 80}, |
| 851 | {"a", 443}, |
| 852 | {"b", 80}, |
| 853 | }; |
| 854 | |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 855 | const char* const kSchemes[] = { |
| 856 | url::kHttpScheme, |
| 857 | url::kHttpsScheme, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 858 | }; |
| 859 | |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 860 | const PrivacyMode kPrivacyModes[] = {PrivacyMode::PRIVACY_MODE_DISABLED, |
| 861 | PrivacyMode::PRIVACY_MODE_ENABLED}; |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 862 | |
Matt Menke | 4807a9a | 2020-11-21 00:14:41 | [diff] [blame] | 863 | const SchemefulSite kSiteA(GURL("http://a.test/")); |
| 864 | const SchemefulSite kSiteB(GURL("http://b.test/")); |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 865 | const NetworkIsolationKey kNetworkIsolationKeys[] = { |
Matt Menke | 4807a9a | 2020-11-21 00:14:41 | [diff] [blame] | 866 | NetworkIsolationKey(kSiteA, kSiteA), |
| 867 | NetworkIsolationKey(kSiteB, kSiteB), |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 868 | }; |
| 869 | |
Ben Schwartz | 3ff4dc1e6 | 2021-04-27 21:15:23 | [diff] [blame] | 870 | const SecureDnsPolicy kSecureDnsPolicys[] = {SecureDnsPolicy::kAllow, |
| 871 | SecureDnsPolicy::kDisable}; |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 872 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 873 | int total_idle_sockets = 0; |
| 874 | |
| 875 | // Walk through each GroupId, making sure that requesting a socket for one |
| 876 | // group does not return a previously connected socket for another group. |
| 877 | for (const auto& host_port_pair : kHostPortPairs) { |
| 878 | SCOPED_TRACE(host_port_pair.ToString()); |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 879 | for (const char* scheme : kSchemes) { |
| 880 | SCOPED_TRACE(scheme); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 881 | for (const auto& privacy_mode : kPrivacyModes) { |
| 882 | SCOPED_TRACE(privacy_mode); |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 883 | for (const auto& network_isolation_key : kNetworkIsolationKeys) { |
| 884 | SCOPED_TRACE(network_isolation_key.ToString()); |
Ben Schwartz | 3ff4dc1e6 | 2021-04-27 21:15:23 | [diff] [blame] | 885 | for (const auto& secure_dns_policy : kSecureDnsPolicys) { |
| 886 | SCOPED_TRACE(static_cast<int>(secure_dns_policy)); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 887 | |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 888 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 889 | |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 890 | ClientSocketPool::GroupId group_id( |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 891 | url::SchemeHostPort(scheme, host_port_pair.host(), |
| 892 | host_port_pair.port()), |
| 893 | privacy_mode, network_isolation_key, secure_dns_policy); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 894 | |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 895 | EXPECT_FALSE(pool_->HasGroupForTesting(group_id)); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 896 | |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 897 | TestCompletionCallback callback; |
| 898 | ClientSocketHandle handle; |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 899 | |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 900 | // Since the group is empty, requesting a socket should not complete |
| 901 | // synchronously. |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 902 | EXPECT_THAT(handle.Init(group_id, params_, absl::nullopt, |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 903 | DEFAULT_PRIORITY, SocketTag(), |
| 904 | ClientSocketPool::RespectLimits::ENABLED, |
| 905 | callback.callback(), |
| 906 | ClientSocketPool::ProxyAuthCallback(), |
| 907 | pool_.get(), NetLogWithSource()), |
| 908 | IsError(ERR_IO_PENDING)); |
| 909 | EXPECT_TRUE(pool_->HasGroupForTesting(group_id)); |
| 910 | EXPECT_EQ(total_idle_sockets, pool_->IdleSocketCount()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 911 | |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 912 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 913 | EXPECT_TRUE(handle.socket()); |
| 914 | EXPECT_TRUE(pool_->HasGroupForTesting(group_id)); |
| 915 | EXPECT_EQ(total_idle_sockets, pool_->IdleSocketCount()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 916 | |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 917 | // Return socket to pool. |
| 918 | handle.Reset(); |
| 919 | EXPECT_EQ(total_idle_sockets + 1, pool_->IdleSocketCount()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 920 | |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 921 | // Requesting a socket again should return the same socket as |
| 922 | // before, so should complete synchronously. |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 923 | EXPECT_THAT(handle.Init(group_id, params_, absl::nullopt, |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 924 | DEFAULT_PRIORITY, SocketTag(), |
| 925 | ClientSocketPool::RespectLimits::ENABLED, |
| 926 | callback.callback(), |
| 927 | ClientSocketPool::ProxyAuthCallback(), |
| 928 | pool_.get(), NetLogWithSource()), |
| 929 | IsOk()); |
| 930 | EXPECT_TRUE(handle.socket()); |
| 931 | EXPECT_EQ(total_idle_sockets, pool_->IdleSocketCount()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 932 | |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 933 | // Return socket to pool again. |
| 934 | handle.Reset(); |
| 935 | EXPECT_EQ(total_idle_sockets + 1, pool_->IdleSocketCount()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 936 | |
dalyk | 5f48a13 | 2019-10-14 15:20:19 | [diff] [blame] | 937 | ++total_idle_sockets; |
| 938 | } |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 939 | } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 940 | } |
| 941 | } |
| 942 | } |
| 943 | } |
| 944 | |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 945 | TEST_F(ClientSocketPoolBaseTest, TotalLimit) { |
| 946 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 947 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 948 | // TODO(eroman): Check that the NetLog contains this event. |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 949 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 950 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 951 | EXPECT_THAT(StartRequest(TestGroupId("b"), DEFAULT_PRIORITY), IsOk()); |
| 952 | EXPECT_THAT(StartRequest(TestGroupId("c"), DEFAULT_PRIORITY), IsOk()); |
| 953 | EXPECT_THAT(StartRequest(TestGroupId("d"), DEFAULT_PRIORITY), IsOk()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 954 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 955 | EXPECT_EQ(static_cast<int>(requests_size()), |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 956 | client_socket_factory_.allocation_count()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 957 | EXPECT_EQ(requests_size() - kDefaultMaxSockets, completion_count()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 958 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 959 | EXPECT_THAT(StartRequest(TestGroupId("e"), DEFAULT_PRIORITY), |
| 960 | IsError(ERR_IO_PENDING)); |
| 961 | EXPECT_THAT(StartRequest(TestGroupId("f"), DEFAULT_PRIORITY), |
| 962 | IsError(ERR_IO_PENDING)); |
| 963 | EXPECT_THAT(StartRequest(TestGroupId("g"), DEFAULT_PRIORITY), |
| 964 | IsError(ERR_IO_PENDING)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 965 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 966 | ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 967 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 968 | EXPECT_EQ(static_cast<int>(requests_size()), |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 969 | client_socket_factory_.allocation_count()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 970 | EXPECT_EQ(requests_size() - kDefaultMaxSockets, completion_count()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 971 | |
| 972 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 973 | EXPECT_EQ(2, GetOrderOfRequest(2)); |
| 974 | EXPECT_EQ(3, GetOrderOfRequest(3)); |
| 975 | EXPECT_EQ(4, GetOrderOfRequest(4)); |
| 976 | EXPECT_EQ(5, GetOrderOfRequest(5)); |
| 977 | EXPECT_EQ(6, GetOrderOfRequest(6)); |
| 978 | EXPECT_EQ(7, GetOrderOfRequest(7)); |
[email protected] | 75439d3b | 2009-07-23 22:11:17 | [diff] [blame] | 979 | |
| 980 | // Make sure we test order of all requests made. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 981 | EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(8)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | TEST_F(ClientSocketPoolBaseTest, TotalLimitReachedNewGroup) { |
| 985 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 986 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 987 | // TODO(eroman): Check that the NetLog contains this event. |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 988 | |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 989 | // Reach all limits: max total sockets, and max sockets per group. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 990 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 991 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 992 | EXPECT_THAT(StartRequest(TestGroupId("b"), DEFAULT_PRIORITY), IsOk()); |
| 993 | EXPECT_THAT(StartRequest(TestGroupId("b"), DEFAULT_PRIORITY), IsOk()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 994 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 995 | EXPECT_EQ(static_cast<int>(requests_size()), |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 996 | client_socket_factory_.allocation_count()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 997 | EXPECT_EQ(requests_size() - kDefaultMaxSockets, completion_count()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 998 | |
| 999 | // Now create a new group and verify that we don't starve it. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1000 | EXPECT_THAT(StartRequest(TestGroupId("c"), DEFAULT_PRIORITY), |
| 1001 | IsError(ERR_IO_PENDING)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1002 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1003 | ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1004 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1005 | EXPECT_EQ(static_cast<int>(requests_size()), |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1006 | client_socket_factory_.allocation_count()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1007 | EXPECT_EQ(requests_size() - kDefaultMaxSockets, completion_count()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1008 | |
| 1009 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 1010 | EXPECT_EQ(2, GetOrderOfRequest(2)); |
| 1011 | EXPECT_EQ(3, GetOrderOfRequest(3)); |
| 1012 | EXPECT_EQ(4, GetOrderOfRequest(4)); |
| 1013 | EXPECT_EQ(5, GetOrderOfRequest(5)); |
[email protected] | 75439d3b | 2009-07-23 22:11:17 | [diff] [blame] | 1014 | |
| 1015 | // Make sure we test order of all requests made. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1016 | EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(6)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | TEST_F(ClientSocketPoolBaseTest, TotalLimitRespectsPriority) { |
| 1020 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1021 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1022 | EXPECT_THAT(StartRequest(TestGroupId("b"), LOWEST), IsOk()); |
| 1023 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsOk()); |
| 1024 | EXPECT_THAT(StartRequest(TestGroupId("b"), HIGHEST), IsOk()); |
| 1025 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsOk()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1026 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1027 | EXPECT_EQ(static_cast<int>(requests_size()), |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1028 | client_socket_factory_.allocation_count()); |
| 1029 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1030 | EXPECT_THAT(StartRequest(TestGroupId("c"), LOWEST), IsError(ERR_IO_PENDING)); |
| 1031 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsError(ERR_IO_PENDING)); |
| 1032 | EXPECT_THAT(StartRequest(TestGroupId("b"), HIGHEST), IsError(ERR_IO_PENDING)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1033 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1034 | ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1035 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1036 | EXPECT_EQ(requests_size() - kDefaultMaxSockets, completion_count()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1037 | |
| 1038 | // First 4 requests don't have to wait, and finish in order. |
| 1039 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 1040 | EXPECT_EQ(2, GetOrderOfRequest(2)); |
| 1041 | EXPECT_EQ(3, GetOrderOfRequest(3)); |
| 1042 | EXPECT_EQ(4, GetOrderOfRequest(4)); |
| 1043 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1044 | // Request ("b", HIGHEST) has the highest priority, then (TestGroupId("a"), |
| 1045 | // MEDIUM), and then ("c", LOWEST). |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1046 | EXPECT_EQ(7, GetOrderOfRequest(5)); |
| 1047 | EXPECT_EQ(6, GetOrderOfRequest(6)); |
| 1048 | EXPECT_EQ(5, GetOrderOfRequest(7)); |
[email protected] | 75439d3b | 2009-07-23 22:11:17 | [diff] [blame] | 1049 | |
| 1050 | // Make sure we test order of all requests made. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1051 | EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(9)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1052 | } |
| 1053 | |
rdsmith | 29dbad1 | 2017-02-17 02:22:18 | [diff] [blame] | 1054 | // Test reprioritizing a request before completion doesn't interfere with |
| 1055 | // its completion. |
| 1056 | TEST_F(ClientSocketPoolBaseTest, ReprioritizeOne) { |
| 1057 | CreatePool(kDefaultMaxSockets, 1); |
| 1058 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1059 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(OK)); |
| 1060 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsError(ERR_IO_PENDING)); |
rdsmith | 29dbad1 | 2017-02-17 02:22:18 | [diff] [blame] | 1061 | EXPECT_TRUE(request(0)->handle()->socket()); |
| 1062 | EXPECT_FALSE(request(1)->handle()->socket()); |
| 1063 | |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 1064 | request(1)->handle()->SetPriority(HIGHEST); |
rdsmith | 29dbad1 | 2017-02-17 02:22:18 | [diff] [blame] | 1065 | |
| 1066 | ReleaseOneConnection(ClientSocketPoolTest::NO_KEEP_ALIVE); |
| 1067 | |
| 1068 | EXPECT_TRUE(request(1)->handle()->socket()); |
| 1069 | } |
| 1070 | |
| 1071 | // Reprioritize a request up past another one and make sure that changes the |
| 1072 | // completion order. |
| 1073 | TEST_F(ClientSocketPoolBaseTest, ReprioritizeUpReorder) { |
| 1074 | CreatePool(kDefaultMaxSockets, 1); |
| 1075 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1076 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(OK)); |
| 1077 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsError(ERR_IO_PENDING)); |
| 1078 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(ERR_IO_PENDING)); |
rdsmith | 29dbad1 | 2017-02-17 02:22:18 | [diff] [blame] | 1079 | EXPECT_TRUE(request(0)->handle()->socket()); |
| 1080 | EXPECT_FALSE(request(1)->handle()->socket()); |
| 1081 | EXPECT_FALSE(request(2)->handle()->socket()); |
| 1082 | |
| 1083 | request(2)->handle()->SetPriority(HIGHEST); |
| 1084 | |
| 1085 | ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
| 1086 | |
| 1087 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 1088 | EXPECT_EQ(3, GetOrderOfRequest(2)); |
| 1089 | EXPECT_EQ(2, GetOrderOfRequest(3)); |
| 1090 | } |
| 1091 | |
| 1092 | // Reprioritize a request without changing relative priorities and check |
| 1093 | // that the order doesn't change. |
| 1094 | TEST_F(ClientSocketPoolBaseTest, ReprioritizeUpNoReorder) { |
| 1095 | CreatePool(kDefaultMaxSockets, 1); |
| 1096 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1097 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(OK)); |
| 1098 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsError(ERR_IO_PENDING)); |
| 1099 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOW), IsError(ERR_IO_PENDING)); |
rdsmith | 29dbad1 | 2017-02-17 02:22:18 | [diff] [blame] | 1100 | EXPECT_TRUE(request(0)->handle()->socket()); |
| 1101 | EXPECT_FALSE(request(1)->handle()->socket()); |
| 1102 | EXPECT_FALSE(request(2)->handle()->socket()); |
| 1103 | |
| 1104 | request(2)->handle()->SetPriority(MEDIUM); |
| 1105 | |
| 1106 | ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
| 1107 | |
| 1108 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 1109 | EXPECT_EQ(2, GetOrderOfRequest(2)); |
| 1110 | EXPECT_EQ(3, GetOrderOfRequest(3)); |
| 1111 | } |
| 1112 | |
| 1113 | // Reprioritize a request past down another one and make sure that changes the |
| 1114 | // completion order. |
| 1115 | TEST_F(ClientSocketPoolBaseTest, ReprioritizeDownReorder) { |
| 1116 | CreatePool(kDefaultMaxSockets, 1); |
| 1117 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1118 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(OK)); |
| 1119 | EXPECT_THAT(StartRequest(TestGroupId("a"), HIGHEST), IsError(ERR_IO_PENDING)); |
| 1120 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsError(ERR_IO_PENDING)); |
rdsmith | 29dbad1 | 2017-02-17 02:22:18 | [diff] [blame] | 1121 | EXPECT_TRUE(request(0)->handle()->socket()); |
| 1122 | EXPECT_FALSE(request(1)->handle()->socket()); |
| 1123 | EXPECT_FALSE(request(2)->handle()->socket()); |
| 1124 | |
| 1125 | request(1)->handle()->SetPriority(LOW); |
| 1126 | |
| 1127 | ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
| 1128 | |
| 1129 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 1130 | EXPECT_EQ(3, GetOrderOfRequest(2)); |
| 1131 | EXPECT_EQ(2, GetOrderOfRequest(3)); |
| 1132 | } |
| 1133 | |
| 1134 | // Reprioritize a request to the same level as another and confirm it is |
| 1135 | // put after the old request. |
| 1136 | TEST_F(ClientSocketPoolBaseTest, ReprioritizeResetFIFO) { |
| 1137 | CreatePool(kDefaultMaxSockets, 1); |
| 1138 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1139 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(OK)); |
| 1140 | EXPECT_THAT(StartRequest(TestGroupId("a"), HIGHEST), IsError(ERR_IO_PENDING)); |
| 1141 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsError(ERR_IO_PENDING)); |
rdsmith | 29dbad1 | 2017-02-17 02:22:18 | [diff] [blame] | 1142 | EXPECT_TRUE(request(0)->handle()->socket()); |
| 1143 | EXPECT_FALSE(request(1)->handle()->socket()); |
| 1144 | EXPECT_FALSE(request(2)->handle()->socket()); |
| 1145 | |
| 1146 | request(1)->handle()->SetPriority(MEDIUM); |
| 1147 | |
| 1148 | ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
| 1149 | |
| 1150 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 1151 | EXPECT_EQ(3, GetOrderOfRequest(2)); |
| 1152 | EXPECT_EQ(2, GetOrderOfRequest(3)); |
| 1153 | } |
| 1154 | |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1155 | TEST_F(ClientSocketPoolBaseTest, TotalLimitRespectsGroupLimit) { |
| 1156 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1157 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1158 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsOk()); |
| 1159 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOW), IsOk()); |
| 1160 | EXPECT_THAT(StartRequest(TestGroupId("b"), HIGHEST), IsOk()); |
| 1161 | EXPECT_THAT(StartRequest(TestGroupId("b"), MEDIUM), IsOk()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1162 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1163 | EXPECT_EQ(static_cast<int>(requests_size()), |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1164 | client_socket_factory_.allocation_count()); |
| 1165 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1166 | EXPECT_THAT(StartRequest(TestGroupId("c"), MEDIUM), IsError(ERR_IO_PENDING)); |
| 1167 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOW), IsError(ERR_IO_PENDING)); |
| 1168 | EXPECT_THAT(StartRequest(TestGroupId("b"), HIGHEST), IsError(ERR_IO_PENDING)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1169 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1170 | ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1171 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1172 | EXPECT_EQ(static_cast<int>(requests_size()), |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1173 | client_socket_factory_.allocation_count()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1174 | EXPECT_EQ(requests_size() - kDefaultMaxSockets, completion_count()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1175 | |
| 1176 | // First 4 requests don't have to wait, and finish in order. |
| 1177 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 1178 | EXPECT_EQ(2, GetOrderOfRequest(2)); |
| 1179 | EXPECT_EQ(3, GetOrderOfRequest(3)); |
| 1180 | EXPECT_EQ(4, GetOrderOfRequest(4)); |
| 1181 | |
| 1182 | // Request ("b", 7) has the highest priority, but we can't make new socket for |
| 1183 | // group "b", because it has reached the per-group limit. Then we make |
| 1184 | // socket for ("c", 6), because it has higher priority than ("a", 4), |
| 1185 | // and we still can't make a socket for group "b". |
| 1186 | EXPECT_EQ(5, GetOrderOfRequest(5)); |
| 1187 | EXPECT_EQ(6, GetOrderOfRequest(6)); |
| 1188 | EXPECT_EQ(7, GetOrderOfRequest(7)); |
[email protected] | 75439d3b | 2009-07-23 22:11:17 | [diff] [blame] | 1189 | |
| 1190 | // Make sure we test order of all requests made. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1191 | EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(8)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | // Make sure that we count connecting sockets against the total limit. |
| 1195 | TEST_F(ClientSocketPoolBaseTest, TotalLimitCountsConnectingSockets) { |
| 1196 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1197 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1198 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 1199 | EXPECT_THAT(StartRequest(TestGroupId("b"), DEFAULT_PRIORITY), IsOk()); |
| 1200 | EXPECT_THAT(StartRequest(TestGroupId("c"), DEFAULT_PRIORITY), IsOk()); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1201 | |
| 1202 | // Create one asynchronous request. |
| 1203 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1204 | EXPECT_THAT(StartRequest(TestGroupId("d"), DEFAULT_PRIORITY), |
| 1205 | IsError(ERR_IO_PENDING)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1206 | |
[email protected] | 6b17538 | 2009-10-13 06:47:47 | [diff] [blame] | 1207 | // We post all of our delayed tasks with a 2ms delay. I.e. they don't |
| 1208 | // actually become pending until 2ms after they have been created. In order |
| 1209 | // to flush all tasks, we need to wait so that we know there are no |
| 1210 | // soon-to-be-pending tasks waiting. |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 1211 | FastForwardBy(base::Milliseconds(10)); |
[email protected] | 6b17538 | 2009-10-13 06:47:47 | [diff] [blame] | 1212 | |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1213 | // The next synchronous request should wait for its turn. |
| 1214 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1215 | EXPECT_THAT(StartRequest(TestGroupId("e"), DEFAULT_PRIORITY), |
| 1216 | IsError(ERR_IO_PENDING)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1217 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1218 | ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1219 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1220 | EXPECT_EQ(static_cast<int>(requests_size()), |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1221 | client_socket_factory_.allocation_count()); |
| 1222 | |
| 1223 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 1224 | EXPECT_EQ(2, GetOrderOfRequest(2)); |
| 1225 | EXPECT_EQ(3, GetOrderOfRequest(3)); |
| 1226 | EXPECT_EQ(4, GetOrderOfRequest(4)); |
[email protected] | 75439d3b | 2009-07-23 22:11:17 | [diff] [blame] | 1227 | EXPECT_EQ(5, GetOrderOfRequest(5)); |
| 1228 | |
| 1229 | // Make sure we test order of all requests made. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1230 | EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(6)); |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1231 | } |
| 1232 | |
[email protected] | 6427fe2 | 2010-04-16 22:27:41 | [diff] [blame] | 1233 | TEST_F(ClientSocketPoolBaseTest, CorrectlyCountStalledGroups) { |
| 1234 | CreatePool(kDefaultMaxSockets, kDefaultMaxSockets); |
| 1235 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 1236 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 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()); |
| 1240 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
[email protected] | 6427fe2 | 2010-04-16 22:27:41 | [diff] [blame] | 1241 | |
| 1242 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 1243 | |
| 1244 | EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count()); |
| 1245 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1246 | EXPECT_THAT(StartRequest(TestGroupId("b"), DEFAULT_PRIORITY), |
| 1247 | IsError(ERR_IO_PENDING)); |
| 1248 | EXPECT_THAT(StartRequest(TestGroupId("c"), DEFAULT_PRIORITY), |
| 1249 | IsError(ERR_IO_PENDING)); |
[email protected] | 6427fe2 | 2010-04-16 22:27:41 | [diff] [blame] | 1250 | |
| 1251 | EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count()); |
| 1252 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1253 | EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE)); |
[email protected] | 6427fe2 | 2010-04-16 22:27:41 | [diff] [blame] | 1254 | EXPECT_EQ(kDefaultMaxSockets + 1, client_socket_factory_.allocation_count()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1255 | EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE)); |
[email protected] | 6427fe2 | 2010-04-16 22:27:41 | [diff] [blame] | 1256 | EXPECT_EQ(kDefaultMaxSockets + 2, client_socket_factory_.allocation_count()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1257 | EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE)); |
| 1258 | EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE)); |
[email protected] | 6427fe2 | 2010-04-16 22:27:41 | [diff] [blame] | 1259 | EXPECT_EQ(kDefaultMaxSockets + 2, client_socket_factory_.allocation_count()); |
| 1260 | } |
| 1261 | |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 1262 | TEST_F(ClientSocketPoolBaseTest, StallAndThenCancelAndTriggerAvailableSocket) { |
| 1263 | CreatePool(kDefaultMaxSockets, kDefaultMaxSockets); |
| 1264 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 1265 | |
| 1266 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1267 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1268 | EXPECT_EQ( |
| 1269 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1270 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1271 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 1272 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1273 | pool_.get(), NetLogWithSource())); |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 1274 | |
| 1275 | ClientSocketHandle handles[4]; |
Daniel Cheng | 5feb16f | 2022-02-28 06:52:07 | [diff] [blame] | 1276 | for (size_t i = 0; i < std::size(handles); ++i) { |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1277 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1278 | handles[i].Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1279 | TestGroupId("b"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1280 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 1281 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1282 | pool_.get(), NetLogWithSource())); |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | // One will be stalled, cancel all the handles now. |
| 1286 | // This should hit the OnAvailableSocketSlot() code where we previously had |
| 1287 | // stalled groups, but no longer have any. |
Daniel Cheng | 5feb16f | 2022-02-28 06:52:07 | [diff] [blame] | 1288 | for (size_t i = 0; i < std::size(handles); ++i) |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 1289 | handles[i].Reset(); |
| 1290 | } |
| 1291 | |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1292 | TEST_F(ClientSocketPoolBaseTest, CancelStalledSocketAtSocketLimit) { |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1293 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1294 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 1295 | |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1296 | { |
| 1297 | ClientSocketHandle handles[kDefaultMaxSockets]; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1298 | TestCompletionCallback callbacks[kDefaultMaxSockets]; |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1299 | for (int i = 0; i < kDefaultMaxSockets; ++i) { |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 1300 | EXPECT_EQ(OK, handles[i].Init(TestGroupId("a" + base::NumberToString(i)), |
| 1301 | params_, absl::nullopt, DEFAULT_PRIORITY, |
| 1302 | SocketTag(), |
| 1303 | ClientSocketPool::RespectLimits::ENABLED, |
| 1304 | callbacks[i].callback(), |
| 1305 | ClientSocketPool::ProxyAuthCallback(), |
| 1306 | pool_.get(), NetLogWithSource())); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | // Force a stalled group. |
| 1310 | ClientSocketHandle stalled_handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1311 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 1312 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1313 | stalled_handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1314 | TestGroupId("foo"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1315 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 1316 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1317 | pool_.get(), NetLogWithSource())); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1318 | |
| 1319 | // Cancel the stalled request. |
| 1320 | stalled_handle.Reset(); |
| 1321 | |
| 1322 | EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count()); |
| 1323 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 1324 | |
| 1325 | // Dropping out of scope will close all handles and return them to idle. |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1326 | } |
| 1327 | |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1328 | EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count()); |
| 1329 | EXPECT_EQ(kDefaultMaxSockets, pool_->IdleSocketCount()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1330 | } |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1331 | |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1332 | TEST_F(ClientSocketPoolBaseTest, CancelPendingSocketAtSocketLimit) { |
| 1333 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1334 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 1335 | |
| 1336 | { |
| 1337 | ClientSocketHandle handles[kDefaultMaxSockets]; |
| 1338 | for (int i = 0; i < kDefaultMaxSockets; ++i) { |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1339 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 1340 | EXPECT_EQ(ERR_IO_PENDING, |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 1341 | handles[i].Init( |
| 1342 | TestGroupId("a" + base::NumberToString(i)), params_, |
| 1343 | absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
| 1344 | ClientSocketPool::RespectLimits::ENABLED, |
| 1345 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1346 | pool_.get(), NetLogWithSource())); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | // Force a stalled group. |
| 1350 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 1351 | ClientSocketHandle stalled_handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1352 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 1353 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1354 | stalled_handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1355 | TestGroupId("foo"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1356 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 1357 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1358 | pool_.get(), NetLogWithSource())); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1359 | |
| 1360 | // Since it is stalled, it should have no connect jobs. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 1361 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("foo"))); |
| 1362 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 1363 | TestGroupId("foo"))); |
| 1364 | EXPECT_EQ(0u, pool_->NumUnassignedConnectJobsInGroupForTesting( |
| 1365 | TestGroupId("foo"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1366 | |
| 1367 | // Cancel the stalled request. |
| 1368 | handles[0].Reset(); |
| 1369 | |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1370 | // Now we should have a connect job. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 1371 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("foo"))); |
| 1372 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 1373 | TestGroupId("foo"))); |
| 1374 | EXPECT_EQ(0u, pool_->NumUnassignedConnectJobsInGroupForTesting( |
| 1375 | TestGroupId("foo"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1376 | |
| 1377 | // The stalled socket should connect. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1378 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1379 | |
| 1380 | EXPECT_EQ(kDefaultMaxSockets + 1, |
| 1381 | client_socket_factory_.allocation_count()); |
| 1382 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 1383 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("foo"))); |
| 1384 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 1385 | TestGroupId("foo"))); |
| 1386 | EXPECT_EQ(0u, pool_->NumUnassignedConnectJobsInGroupForTesting( |
| 1387 | TestGroupId("foo"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1388 | |
| 1389 | // Dropping out of scope will close all handles and return them to idle. |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1390 | } |
| 1391 | |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1392 | EXPECT_EQ(1, pool_->IdleSocketCount()); |
| 1393 | } |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1394 | |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1395 | TEST_F(ClientSocketPoolBaseTest, WaitForStalledSocketAtSocketLimit) { |
| 1396 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1397 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1398 | |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1399 | ClientSocketHandle stalled_handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1400 | TestCompletionCallback callback; |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1401 | { |
[email protected] | 51fdc7c | 2012-04-10 19:19:48 | [diff] [blame] | 1402 | EXPECT_FALSE(pool_->IsStalled()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1403 | ClientSocketHandle handles[kDefaultMaxSockets]; |
| 1404 | for (int i = 0; i < kDefaultMaxSockets; ++i) { |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1405 | EXPECT_EQ( |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1406 | OK, handles[i].Init( |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 1407 | TestGroupId(base::StringPrintf("take-2-%d", i)), params_, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1408 | absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1409 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
| 1410 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 1411 | NetLogWithSource())); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count()); |
| 1415 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
[email protected] | 51fdc7c | 2012-04-10 19:19:48 | [diff] [blame] | 1416 | EXPECT_FALSE(pool_->IsStalled()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1417 | |
| 1418 | // Now we will hit the socket limit. |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 1419 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1420 | stalled_handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1421 | TestGroupId("foo"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1422 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 1423 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1424 | pool_.get(), NetLogWithSource())); |
[email protected] | 51fdc7c | 2012-04-10 19:19:48 | [diff] [blame] | 1425 | EXPECT_TRUE(pool_->IsStalled()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1426 | |
| 1427 | // Dropping out of scope will close all handles and return them to idle. |
| 1428 | } |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1429 | |
| 1430 | // But if we wait for it, the released idle sockets will be closed in |
| 1431 | // preference of the waiting request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1432 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 1433 | |
| 1434 | EXPECT_EQ(kDefaultMaxSockets + 1, client_socket_factory_.allocation_count()); |
| 1435 | EXPECT_EQ(3, pool_->IdleSocketCount()); |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | // Regression test for http://crbug.com/40952. |
| 1439 | TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketAtSocketLimitDeleteGroup) { |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 1440 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, |
| 1441 | true /* enable_backup_connect_jobs */); |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1442 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 1443 | |
| 1444 | for (int i = 0; i < kDefaultMaxSockets; ++i) { |
| 1445 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1446 | TestCompletionCallback callback; |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 1447 | EXPECT_EQ( |
| 1448 | OK, |
| 1449 | handle.Init(TestGroupId("a" + base::NumberToString(i)), params_, |
| 1450 | absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
| 1451 | ClientSocketPool::RespectLimits::ENABLED, |
| 1452 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1453 | pool_.get(), NetLogWithSource())); |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | // Flush all the DoReleaseSocket tasks. |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 1457 | base::RunLoop().RunUntilIdle(); |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1458 | |
| 1459 | // Stall a group. Set a pending job so it'll trigger a backup job if we don't |
| 1460 | // reuse a socket. |
| 1461 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 1462 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1463 | TestCompletionCallback callback; |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1464 | |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 1465 | // "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] | 1466 | // which is the one which we would close an idle socket for. We shouldn't |
| 1467 | // close an idle socket though, since we should reuse the idle socket. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1468 | EXPECT_EQ(OK, handle.Init( |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 1469 | TestGroupId("a0"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1470 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1471 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1472 | pool_.get(), NetLogWithSource())); |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1473 | |
| 1474 | EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count()); |
| 1475 | EXPECT_EQ(kDefaultMaxSockets - 1, pool_->IdleSocketCount()); |
| 1476 | } |
| 1477 | |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 1478 | TEST_F(ClientSocketPoolBaseTest, PendingRequests) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1479 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1480 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1481 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 1482 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 1483 | EXPECT_THAT(StartRequest(TestGroupId("a"), IDLE), IsError(ERR_IO_PENDING)); |
| 1484 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(ERR_IO_PENDING)); |
| 1485 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsError(ERR_IO_PENDING)); |
| 1486 | EXPECT_THAT(StartRequest(TestGroupId("a"), HIGHEST), IsError(ERR_IO_PENDING)); |
| 1487 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOW), IsError(ERR_IO_PENDING)); |
| 1488 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(ERR_IO_PENDING)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1489 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1490 | ReleaseAllConnections(ClientSocketPoolTest::KEEP_ALIVE); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1491 | EXPECT_EQ(kDefaultMaxSocketsPerGroup, |
| 1492 | client_socket_factory_.allocation_count()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1493 | EXPECT_EQ(requests_size() - kDefaultMaxSocketsPerGroup, |
| 1494 | completion_count()); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1495 | |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1496 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 1497 | EXPECT_EQ(2, GetOrderOfRequest(2)); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 1498 | EXPECT_EQ(8, GetOrderOfRequest(3)); |
| 1499 | EXPECT_EQ(6, GetOrderOfRequest(4)); |
| 1500 | EXPECT_EQ(4, GetOrderOfRequest(5)); |
| 1501 | EXPECT_EQ(3, GetOrderOfRequest(6)); |
| 1502 | EXPECT_EQ(5, GetOrderOfRequest(7)); |
| 1503 | EXPECT_EQ(7, GetOrderOfRequest(8)); |
[email protected] | 75439d3b | 2009-07-23 22:11:17 | [diff] [blame] | 1504 | |
| 1505 | // Make sure we test order of all requests made. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1506 | EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(9)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1507 | } |
| 1508 | |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 1509 | TEST_F(ClientSocketPoolBaseTest, PendingRequests_NoKeepAlive) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1510 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1511 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1512 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 1513 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 1514 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(ERR_IO_PENDING)); |
| 1515 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsError(ERR_IO_PENDING)); |
| 1516 | EXPECT_THAT(StartRequest(TestGroupId("a"), HIGHEST), IsError(ERR_IO_PENDING)); |
| 1517 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOW), IsError(ERR_IO_PENDING)); |
| 1518 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(ERR_IO_PENDING)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1519 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1520 | ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1521 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1522 | for (size_t i = kDefaultMaxSocketsPerGroup; i < requests_size(); ++i) |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1523 | EXPECT_THAT(request(i)->WaitForResult(), IsOk()); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1524 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1525 | EXPECT_EQ(static_cast<int>(requests_size()), |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1526 | client_socket_factory_.allocation_count()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1527 | EXPECT_EQ(requests_size() - kDefaultMaxSocketsPerGroup, |
| 1528 | completion_count()); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1529 | } |
| 1530 | |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1531 | TEST_F(ClientSocketPoolBaseTest, ResetAndCloseSocket) { |
| 1532 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1533 | |
| 1534 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 1535 | ClientSocketHandle handle; |
| 1536 | TestCompletionCallback callback; |
| 1537 | EXPECT_EQ( |
| 1538 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1539 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1540 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 1541 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1542 | pool_.get(), NetLogWithSource())); |
| 1543 | |
| 1544 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 1545 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1546 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 1547 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
| 1548 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
| 1549 | |
| 1550 | handle.ResetAndCloseSocket(); |
| 1551 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1552 | } |
| 1553 | |
Matt Menke | 99251ea4 | 2019-04-25 22:59:02 | [diff] [blame] | 1554 | // This test will start up a socket request and then call Reset() on the handle. |
| 1555 | // The pending ConnectJob should not be destroyed. |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1556 | TEST_F(ClientSocketPoolBaseTest, CancelRequestKeepsConnectJob) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1557 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1558 | |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 1559 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1560 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1561 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1562 | EXPECT_EQ( |
| 1563 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1564 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1565 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 1566 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1567 | pool_.get(), NetLogWithSource())); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1568 | handle.Reset(); |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1569 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1570 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 1571 | } |
| 1572 | |
Matt Menke | 99251ea4 | 2019-04-25 22:59:02 | [diff] [blame] | 1573 | // This test will start up a socket request and then call ResetAndCloseSocket() |
| 1574 | // on the handle. The pending ConnectJob or connected socket should be |
| 1575 | // destroyed. |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1576 | TEST_F(ClientSocketPoolBaseTest, CancelRequestAndCloseSocket) { |
| 1577 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1578 | |
Matt Menke | 99251ea4 | 2019-04-25 22:59:02 | [diff] [blame] | 1579 | // When true, the socket connects before it's canceled. |
| 1580 | for (bool cancel_when_callback_pending : {false, true}) { |
| 1581 | if (cancel_when_callback_pending) { |
| 1582 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 1583 | } else { |
| 1584 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 1585 | } |
| 1586 | ClientSocketHandle handle; |
| 1587 | TestCompletionCallback callback; |
| 1588 | EXPECT_EQ( |
| 1589 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1590 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | 99251ea4 | 2019-04-25 22:59:02 | [diff] [blame] | 1591 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 1592 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1593 | pool_.get(), NetLogWithSource())); |
| 1594 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1595 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 1596 | |
| 1597 | if (cancel_when_callback_pending) { |
| 1598 | client_socket_factory_.SignalJobs(); |
| 1599 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1600 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
| 1601 | } |
| 1602 | |
| 1603 | handle.ResetAndCloseSocket(); |
| 1604 | ASSERT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1605 | } |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | TEST_F(ClientSocketPoolBaseTest, |
| 1609 | CancelRequestAndCloseSocketWhenMoreRequestsThanConnectJobs) { |
| 1610 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1611 | |
Matt Menke | 99251ea4 | 2019-04-25 22:59:02 | [diff] [blame] | 1612 | // When true, the sockets connect before they're canceled. |
| 1613 | for (bool cancel_when_callback_pending : {false, true}) { |
| 1614 | if (cancel_when_callback_pending) { |
| 1615 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 1616 | } else { |
| 1617 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 1618 | } |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1619 | |
Matt Menke | 99251ea4 | 2019-04-25 22:59:02 | [diff] [blame] | 1620 | std::vector<std::unique_ptr<ClientSocketHandle>> handles; |
| 1621 | TestCompletionCallback callback; |
| 1622 | // Make |kDefaultMaxSockets + 1| socket requests. |
| 1623 | for (int i = 0; i < kDefaultMaxSocketsPerGroup + 1; ++i) { |
| 1624 | std::unique_ptr<ClientSocketHandle> handle = |
| 1625 | std::make_unique<ClientSocketHandle>(); |
| 1626 | EXPECT_EQ(ERR_IO_PENDING, |
| 1627 | handle->Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1628 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | 99251ea4 | 2019-04-25 22:59:02 | [diff] [blame] | 1629 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 1630 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1631 | pool_.get(), NetLogWithSource())); |
| 1632 | handles.push_back(std::move(handle)); |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1633 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Matt Menke | 99251ea4 | 2019-04-25 22:59:02 | [diff] [blame] | 1634 | EXPECT_EQ( |
| 1635 | static_cast<size_t>(std::min(i + 1, kDefaultMaxSocketsPerGroup)), |
| 1636 | pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 1637 | } |
| 1638 | |
| 1639 | if (cancel_when_callback_pending) { |
| 1640 | client_socket_factory_.SignalJobs(); |
| 1641 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1642 | EXPECT_EQ(kDefaultMaxSocketsPerGroup, |
| 1643 | pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
| 1644 | } |
| 1645 | |
| 1646 | // Calling ResetAndCloseSocket() on a handle should not cancel a ConnectJob |
| 1647 | // or close a socket, since there are more requests than ConnectJobs or |
| 1648 | // sockets. |
| 1649 | handles[kDefaultMaxSocketsPerGroup]->ResetAndCloseSocket(); |
| 1650 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1651 | if (cancel_when_callback_pending) { |
| 1652 | EXPECT_EQ(kDefaultMaxSocketsPerGroup, |
| 1653 | pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
| 1654 | } else { |
| 1655 | EXPECT_EQ(static_cast<size_t>(kDefaultMaxSocketsPerGroup), |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1656 | pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 1657 | } |
Matt Menke | 99251ea4 | 2019-04-25 22:59:02 | [diff] [blame] | 1658 | |
| 1659 | // Calling ResetAndCloseSocket() on other handles should cancel a ConnectJob |
| 1660 | // or close a socket. |
| 1661 | for (int i = kDefaultMaxSocketsPerGroup - 1; i >= 0; --i) { |
| 1662 | handles[i]->ResetAndCloseSocket(); |
| 1663 | if (i > 0) { |
| 1664 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1665 | if (cancel_when_callback_pending) { |
| 1666 | EXPECT_EQ(i, |
| 1667 | pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
| 1668 | } else { |
| 1669 | EXPECT_EQ(static_cast<size_t>(i), |
| 1670 | pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 1671 | } |
| 1672 | } else { |
| 1673 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1674 | } |
| 1675 | } |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1676 | } |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1677 | } |
| 1678 | |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 1679 | TEST_F(ClientSocketPoolBaseTest, ConnectCancelConnect) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1680 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1681 | |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 1682 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
[email protected] | a512f598 | 2009-08-18 16:01:06 | [diff] [blame] | 1683 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1684 | TestCompletionCallback callback; |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1685 | |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1686 | EXPECT_EQ( |
| 1687 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1688 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1689 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 1690 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1691 | pool_.get(), NetLogWithSource())); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1692 | |
| 1693 | handle.Reset(); |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1694 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1695 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1696 | |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1697 | // This will create a second ConnectJob, since the other ConnectJob was |
| 1698 | // previously assigned to a request. |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1699 | TestCompletionCallback callback2; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1700 | EXPECT_EQ( |
| 1701 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1702 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1703 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1704 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1705 | pool_.get(), NetLogWithSource())); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1706 | |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1707 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1708 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 1709 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1710 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1711 | EXPECT_FALSE(callback.have_result()); |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1712 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1713 | // One ConnectJob completed, and its socket is now assigned to |handle|. |
| 1714 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
| 1715 | // The other ConnectJob should have either completed, or still be connecting. |
| 1716 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a")) + |
| 1717 | pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1718 | |
| 1719 | handle.Reset(); |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 1720 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 1721 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a")) + |
| 1722 | pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
| 1723 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1724 | } |
| 1725 | |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 1726 | TEST_F(ClientSocketPoolBaseTest, CancelRequest) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1727 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1728 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1729 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 1730 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 1731 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(ERR_IO_PENDING)); |
| 1732 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsError(ERR_IO_PENDING)); |
| 1733 | EXPECT_THAT(StartRequest(TestGroupId("a"), HIGHEST), IsError(ERR_IO_PENDING)); |
| 1734 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOW), IsError(ERR_IO_PENDING)); |
| 1735 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(ERR_IO_PENDING)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1736 | |
| 1737 | // Cancel a request. |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1738 | size_t index_to_cancel = kDefaultMaxSocketsPerGroup + 2; |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1739 | EXPECT_FALSE((*requests())[index_to_cancel]->handle()->is_initialized()); |
| 1740 | (*requests())[index_to_cancel]->handle()->Reset(); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1741 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1742 | ReleaseAllConnections(ClientSocketPoolTest::KEEP_ALIVE); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1743 | |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1744 | EXPECT_EQ(kDefaultMaxSocketsPerGroup, |
| 1745 | client_socket_factory_.allocation_count()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1746 | EXPECT_EQ(requests_size() - kDefaultMaxSocketsPerGroup - 1, |
| 1747 | completion_count()); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1748 | |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1749 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 1750 | EXPECT_EQ(2, GetOrderOfRequest(2)); |
| 1751 | EXPECT_EQ(5, GetOrderOfRequest(3)); |
| 1752 | EXPECT_EQ(3, GetOrderOfRequest(4)); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1753 | EXPECT_EQ(ClientSocketPoolTest::kRequestNotFound, |
| 1754 | GetOrderOfRequest(5)); // Canceled request. |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1755 | EXPECT_EQ(4, GetOrderOfRequest(6)); |
| 1756 | EXPECT_EQ(6, GetOrderOfRequest(7)); |
[email protected] | 75439d3b | 2009-07-23 22:11:17 | [diff] [blame] | 1757 | |
| 1758 | // Make sure we test order of all requests made. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1759 | EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(8)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1760 | } |
| 1761 | |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1762 | // Function to be used as a callback on socket request completion. It first |
| 1763 | // disconnects the successfully connected socket from the first request, and |
| 1764 | // then reuses the ClientSocketHandle to request another socket. |
| 1765 | // |
| 1766 | // |nested_callback| is called with the result of the second socket request. |
| 1767 | void RequestSocketOnComplete(ClientSocketHandle* handle, |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 1768 | TransportClientSocketPool* pool, |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1769 | TestConnectJobFactory* test_connect_job_factory, |
| 1770 | TestConnectJob::JobType next_job_type, |
Bence Béky | a4a5093 | 2018-08-10 13:39:41 | [diff] [blame] | 1771 | TestCompletionCallback* nested_callback, |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1772 | int first_request_result) { |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1773 | EXPECT_THAT(first_request_result, IsOk()); |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1774 | |
| 1775 | test_connect_job_factory->set_job_type(next_job_type); |
| 1776 | |
| 1777 | // Don't allow reuse of the socket. Disconnect it and then release it. |
| 1778 | if (handle->socket()) |
| 1779 | handle->socket()->Disconnect(); |
| 1780 | handle->Reset(); |
| 1781 | |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1782 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1783 | int rv = handle->Init( |
Matt Menke | 870e19ab | 2019-04-23 16:23:03 | [diff] [blame] | 1784 | TestGroupId("a"), |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1785 | ClientSocketPool::SocketParams::CreateForHttpForTesting(), absl::nullopt, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1786 | LOWEST, SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 870e19ab | 2019-04-23 16:23:03 | [diff] [blame] | 1787 | nested_callback->callback(), ClientSocketPool::ProxyAuthCallback(), pool, |
| 1788 | NetLogWithSource()); |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1789 | if (rv != ERR_IO_PENDING) { |
| 1790 | DCHECK_EQ(TestConnectJob::kMockJob, next_job_type); |
Bence Béky | a4a5093 | 2018-08-10 13:39:41 | [diff] [blame] | 1791 | nested_callback->callback().Run(rv); |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1792 | } else { |
| 1793 | DCHECK_EQ(TestConnectJob::kMockPendingJob, next_job_type); |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1794 | } |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1795 | } |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1796 | |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1797 | // Tests the case where a second socket is requested in a completion callback, |
| 1798 | // and the second socket connects asynchronously. Reuses the same |
| 1799 | // ClientSocketHandle for the second socket, after disconnecting the first. |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 1800 | TEST_F(ClientSocketPoolBaseTest, RequestPendingJobTwice) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1801 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1802 | |
[email protected] | 0b7648c | 2009-07-06 20:14:01 | [diff] [blame] | 1803 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
[email protected] | a512f598 | 2009-08-18 16:01:06 | [diff] [blame] | 1804 | ClientSocketHandle handle; |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1805 | TestCompletionCallback second_result_callback; |
| 1806 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1807 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Paul Jensen | 8d6f87ec | 2018-01-13 00:46:54 | [diff] [blame] | 1808 | ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1809 | base::BindOnce(&RequestSocketOnComplete, &handle, pool_.get(), |
| 1810 | connect_job_factory_, TestConnectJob::kMockPendingJob, |
| 1811 | &second_result_callback), |
| 1812 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1813 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1814 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1815 | EXPECT_THAT(second_result_callback.WaitForResult(), IsOk()); |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 1816 | } |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1817 | |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1818 | // Tests the case where a second socket is requested in a completion callback, |
| 1819 | // and the second socket connects synchronously. Reuses the same |
| 1820 | // ClientSocketHandle for the second socket, after disconnecting the first. |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 1821 | TEST_F(ClientSocketPoolBaseTest, RequestPendingJobThenSynchronous) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1822 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1823 | |
[email protected] | 0b7648c | 2009-07-06 20:14:01 | [diff] [blame] | 1824 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
[email protected] | a512f598 | 2009-08-18 16:01:06 | [diff] [blame] | 1825 | ClientSocketHandle handle; |
mmenke | 33d24423d | 2015-05-19 19:41:09 | [diff] [blame] | 1826 | TestCompletionCallback second_result_callback; |
| 1827 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1828 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Paul Jensen | 8d6f87ec | 2018-01-13 00:46:54 | [diff] [blame] | 1829 | ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1830 | base::BindOnce(&RequestSocketOnComplete, &handle, pool_.get(), |
| 1831 | connect_job_factory_, TestConnectJob::kMockPendingJob, |
| 1832 | &second_result_callback), |
| 1833 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1834 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 1835 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1836 | EXPECT_THAT(second_result_callback.WaitForResult(), IsOk()); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | // Make sure that pending requests get serviced after active requests get |
| 1840 | // cancelled. |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 1841 | TEST_F(ClientSocketPoolBaseTest, CancelActiveRequestWithPendingRequests) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1842 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1843 | |
[email protected] | 0b7648c | 2009-07-06 20:14:01 | [diff] [blame] | 1844 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1845 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1846 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 1847 | IsError(ERR_IO_PENDING)); |
| 1848 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 1849 | IsError(ERR_IO_PENDING)); |
| 1850 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 1851 | IsError(ERR_IO_PENDING)); |
| 1852 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 1853 | IsError(ERR_IO_PENDING)); |
| 1854 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 1855 | IsError(ERR_IO_PENDING)); |
| 1856 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 1857 | IsError(ERR_IO_PENDING)); |
| 1858 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 1859 | IsError(ERR_IO_PENDING)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1860 | |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1861 | // Now, kDefaultMaxSocketsPerGroup requests should be active. |
| 1862 | // Let's cancel them. |
| 1863 | for (int i = 0; i < kDefaultMaxSocketsPerGroup; ++i) { |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1864 | ASSERT_FALSE(request(i)->handle()->is_initialized()); |
| 1865 | request(i)->handle()->Reset(); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1866 | } |
| 1867 | |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1868 | // Let's wait for the rest to complete now. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1869 | for (size_t i = kDefaultMaxSocketsPerGroup; i < requests_size(); ++i) { |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1870 | EXPECT_THAT(request(i)->WaitForResult(), IsOk()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1871 | request(i)->handle()->Reset(); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1872 | } |
| 1873 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1874 | EXPECT_EQ(requests_size() - kDefaultMaxSocketsPerGroup, |
| 1875 | completion_count()); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1876 | } |
| 1877 | |
| 1878 | // Make sure that pending requests get serviced after active requests fail. |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 1879 | TEST_F(ClientSocketPoolBaseTest, FailingActiveRequestWithPendingRequests) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1880 | const size_t kMaxSockets = 5; |
| 1881 | CreatePool(kMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | c9d6a1d | 2009-07-14 16:15:20 | [diff] [blame] | 1882 | |
[email protected] | 0b7648c | 2009-07-06 20:14:01 | [diff] [blame] | 1883 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1884 | |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1885 | const size_t kNumberOfRequests = 2 * kDefaultMaxSocketsPerGroup + 1; |
| 1886 | ASSERT_LE(kNumberOfRequests, kMaxSockets); // Otherwise the test will hang. |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1887 | |
| 1888 | // Queue up all the requests |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1889 | for (size_t i = 0; i < kNumberOfRequests; ++i) |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1890 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 1891 | IsError(ERR_IO_PENDING)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1892 | |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1893 | for (size_t i = 0; i < kNumberOfRequests; ++i) |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1894 | EXPECT_THAT(request(i)->WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
[email protected] | f6d1d6eb | 2009-06-24 20:16:09 | [diff] [blame] | 1895 | } |
| 1896 | |
mmenke | 9d72fe4 | 2017-05-18 22:36:07 | [diff] [blame] | 1897 | // Make sure that pending requests that complete synchronously get serviced |
| 1898 | // after active requests fail. See https://crbug.com/723748 |
| 1899 | TEST_F(ClientSocketPoolBaseTest, HandleMultipleSyncFailuresAfterAsyncFailure) { |
| 1900 | const size_t kNumberOfRequests = 10; |
| 1901 | const size_t kMaxSockets = 1; |
| 1902 | CreatePool(kMaxSockets, kMaxSockets); |
| 1903 | |
| 1904 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); |
| 1905 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1906 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 1907 | IsError(ERR_IO_PENDING)); |
mmenke | 9d72fe4 | 2017-05-18 22:36:07 | [diff] [blame] | 1908 | |
| 1909 | connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); |
| 1910 | |
| 1911 | // Queue up all the other requests |
| 1912 | for (size_t i = 1; i < kNumberOfRequests; ++i) |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 1913 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 1914 | IsError(ERR_IO_PENDING)); |
mmenke | 9d72fe4 | 2017-05-18 22:36:07 | [diff] [blame] | 1915 | |
| 1916 | // Make sure all requests fail, instead of hanging. |
| 1917 | for (size_t i = 0; i < kNumberOfRequests; ++i) |
| 1918 | EXPECT_THAT(request(i)->WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
| 1919 | } |
| 1920 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 1921 | TEST_F(ClientSocketPoolBaseTest, CancelActiveRequestThenRequestSocket) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 1922 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 1923 | |
| 1924 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 1925 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1926 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 1927 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1928 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1929 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1930 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
| 1931 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1932 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 1933 | |
| 1934 | // Cancel the active request. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1935 | handle.Reset(); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 1936 | |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1937 | rv = handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1938 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1939 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 1940 | pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1941 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1942 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 1943 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1944 | EXPECT_FALSE(handle.is_reused()); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 1945 | TestLoadTimingInfoConnectedNotReused(handle); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 1946 | EXPECT_EQ(2, client_socket_factory_.allocation_count()); |
| 1947 | } |
| 1948 | |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 1949 | TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketsForced) { |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 1950 | const char kReason[] = "Really nifty reason"; |
| 1951 | |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 1952 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1953 | ClientSocketHandle handle; |
| 1954 | TestCompletionCallback callback; |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 1955 | int rv = |
| 1956 | handle.Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, SocketTag(), |
| 1957 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
| 1958 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 1959 | NetLogWithSource::Make(NetLogSourceType::NONE)); |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 1960 | EXPECT_THAT(rv, IsOk()); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 1961 | ASSERT_TRUE(handle.socket()); |
| 1962 | NetLogSource source = handle.socket()->NetLog().source(); |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 1963 | handle.Reset(); |
| 1964 | EXPECT_EQ(1, pool_->IdleSocketCount()); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 1965 | pool_->CloseIdleSockets(kReason); |
| 1966 | ExpectSocketClosedWithReason(source, kReason); |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 1967 | } |
| 1968 | |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 1969 | TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketsInGroupForced) { |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 1970 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1971 | TestCompletionCallback callback; |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 1972 | NetLogWithSource net_log_with_source = |
| 1973 | NetLogWithSource::Make(NetLogSourceType::NONE); |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 1974 | ClientSocketHandle handle1; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1975 | int rv = handle1.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1976 | TestGroupId("a"), params_, absl::nullopt, LOWEST, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1977 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 1978 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), net_log_with_source); |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 1979 | EXPECT_THAT(rv, IsOk()); |
| 1980 | ClientSocketHandle handle2; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1981 | rv = handle2.Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1982 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1983 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 1984 | pool_.get(), net_log_with_source); |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 1985 | ClientSocketHandle handle3; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 1986 | rv = handle3.Init(TestGroupId("b"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 1987 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 1988 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 1989 | pool_.get(), net_log_with_source); |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 1990 | EXPECT_THAT(rv, IsOk()); |
| 1991 | handle1.Reset(); |
| 1992 | handle2.Reset(); |
| 1993 | handle3.Reset(); |
| 1994 | EXPECT_EQ(3, pool_->IdleSocketCount()); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 1995 | pool_->CloseIdleSocketsInGroup(TestGroupId("a"), "Very good reason"); |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 1996 | EXPECT_EQ(1, pool_->IdleSocketCount()); |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 1997 | } |
| 1998 | |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 1999 | TEST_F(ClientSocketPoolBaseTest, CleanUpUnusableIdleSockets) { |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 2000 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 2001 | ClientSocketHandle handle; |
| 2002 | TestCompletionCallback callback; |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2003 | NetLogWithSource net_log_with_source = |
| 2004 | NetLogWithSource::Make(NetLogSourceType::NONE); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2005 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2006 | TestGroupId("a"), params_, absl::nullopt, LOWEST, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2007 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2008 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), net_log_with_source); |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 2009 | EXPECT_THAT(rv, IsOk()); |
| 2010 | StreamSocket* socket = handle.socket(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 2011 | ASSERT_TRUE(socket); |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 2012 | handle.Reset(); |
| 2013 | EXPECT_EQ(1, pool_->IdleSocketCount()); |
| 2014 | |
| 2015 | // Disconnect socket now to make the socket unusable. |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 2016 | NetLogSource source = socket->NetLog().source(); |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 2017 | socket->Disconnect(); |
| 2018 | ClientSocketHandle handle2; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2019 | rv = handle2.Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2020 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2021 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2022 | pool_.get(), net_log_with_source); |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 2023 | EXPECT_THAT(rv, IsOk()); |
| 2024 | EXPECT_FALSE(handle2.is_reused()); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 2025 | |
| 2026 | // This is admittedly not an accurate error in this case, but normally code |
| 2027 | // doesn't secretly keep a raw pointers to sockets returned to the socket pool |
| 2028 | // and close them out of band, so discovering an idle socket was closed when |
| 2029 | // trying to reuse it normally means it was closed by the remote side. |
| 2030 | ExpectSocketClosedWithReason( |
| 2031 | source, TransportClientSocketPool::kRemoteSideClosedConnection); |
xunjieli | 26619e7 | 2016-11-23 19:39:55 | [diff] [blame] | 2032 | } |
| 2033 | |
[email protected] | 2b7523d | 2009-07-29 20:29:23 | [diff] [blame] | 2034 | // Regression test for http://crbug.com/17985. |
| 2035 | TEST_F(ClientSocketPoolBaseTest, GroupWithPendingRequestsIsNotEmpty) { |
| 2036 | const int kMaxSockets = 3; |
| 2037 | const int kMaxSocketsPerGroup = 2; |
| 2038 | CreatePool(kMaxSockets, kMaxSocketsPerGroup); |
| 2039 | |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 2040 | const RequestPriority kHighPriority = HIGHEST; |
[email protected] | 2b7523d | 2009-07-29 20:29:23 | [diff] [blame] | 2041 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2042 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 2043 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
[email protected] | 2b7523d | 2009-07-29 20:29:23 | [diff] [blame] | 2044 | |
| 2045 | // This is going to be a pending request in an otherwise empty group. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2046 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 2047 | IsError(ERR_IO_PENDING)); |
[email protected] | 2b7523d | 2009-07-29 20:29:23 | [diff] [blame] | 2048 | |
| 2049 | // Reach the maximum socket limit. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2050 | EXPECT_THAT(StartRequest(TestGroupId("b"), DEFAULT_PRIORITY), IsOk()); |
[email protected] | 2b7523d | 2009-07-29 20:29:23 | [diff] [blame] | 2051 | |
| 2052 | // Create a stalled group with high priorities. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2053 | EXPECT_THAT(StartRequest(TestGroupId("c"), kHighPriority), |
| 2054 | IsError(ERR_IO_PENDING)); |
| 2055 | EXPECT_THAT(StartRequest(TestGroupId("c"), kHighPriority), |
| 2056 | IsError(ERR_IO_PENDING)); |
[email protected] | 2b7523d | 2009-07-29 20:29:23 | [diff] [blame] | 2057 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2058 | // Release the first two sockets from TestGroupId("a"). Because this is a |
| 2059 | // keepalive, the first release will unblock the pending request for |
| 2060 | // TestGroupId("a"). The second release will unblock a request for "c", |
| 2061 | // because it is the next high priority socket. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2062 | EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE)); |
| 2063 | EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE)); |
[email protected] | 2b7523d | 2009-07-29 20:29:23 | [diff] [blame] | 2064 | |
| 2065 | // Closing idle sockets should not get us into trouble, but in the bug |
| 2066 | // we were hitting a CHECK here. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2067 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 2068 | pool_->CloseIdleSockets("Very good reason"); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 2069 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 2070 | // Run the released socket wakeups. |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 2071 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2b7523d | 2009-07-29 20:29:23 | [diff] [blame] | 2072 | } |
| 2073 | |
[email protected] | 4d3b05d | 2010-01-27 21:27:29 | [diff] [blame] | 2074 | TEST_F(ClientSocketPoolBaseTest, BasicAsynchronous) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 2075 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2076 | |
| 2077 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2078 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2079 | TestCompletionCallback callback; |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2080 | NetLogWithSource net_log_with_source = |
| 2081 | NetLogWithSource::Make(NetLogSourceType::NONE); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2082 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2083 | TestGroupId("a"), params_, absl::nullopt, LOWEST, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2084 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2085 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), net_log_with_source); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2086 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2087 | EXPECT_EQ(LOAD_STATE_CONNECTING, |
| 2088 | pool_->GetLoadState(TestGroupId("a"), &handle)); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 2089 | TestLoadTimingInfoNotConnected(handle); |
| 2090 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2091 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2092 | EXPECT_TRUE(handle.is_initialized()); |
| 2093 | EXPECT_TRUE(handle.socket()); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 2094 | TestLoadTimingInfoConnectedNotReused(handle); |
| 2095 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2096 | handle.Reset(); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 2097 | TestLoadTimingInfoNotConnected(handle); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 2098 | |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2099 | auto entries = |
| 2100 | net_log_observer_.GetEntriesForSource(net_log_with_source.source()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2101 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2102 | EXPECT_EQ(5u, entries.size()); |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 2103 | EXPECT_TRUE(LogContainsEvent( |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2104 | entries, 0, NetLogEventType::TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2105 | NetLogEventPhase::NONE)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2106 | EXPECT_TRUE(LogContainsBeginEvent(entries, 1, NetLogEventType::SOCKET_POOL)); |
| 2107 | EXPECT_TRUE(LogContainsEvent( |
| 2108 | entries, 2, NetLogEventType::SOCKET_POOL_BOUND_TO_CONNECT_JOB, |
| 2109 | NetLogEventPhase::NONE)); |
| 2110 | EXPECT_TRUE(LogContainsEvent(entries, 3, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2111 | NetLogEventType::SOCKET_POOL_BOUND_TO_SOCKET, |
| 2112 | NetLogEventPhase::NONE)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2113 | EXPECT_TRUE(LogContainsEndEvent(entries, 4, NetLogEventType::SOCKET_POOL)); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2114 | } |
| 2115 | |
[email protected] | 4d3b05d | 2010-01-27 21:27:29 | [diff] [blame] | 2116 | TEST_F(ClientSocketPoolBaseTest, |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2117 | InitConnectionAsynchronousFailure) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 2118 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2119 | |
| 2120 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2121 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2122 | TestCompletionCallback callback; |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2123 | NetLogWithSource net_log_with_source = |
| 2124 | NetLogWithSource::Make(NetLogSourceType::NONE); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2125 | // Set the additional error state members to ensure that they get cleared. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2126 | handle.set_is_ssl_error(true); |
Matt Menke | 39b7c5a | 2019-04-10 19:47:51 | [diff] [blame] | 2127 | handle.set_ssl_cert_request_info(base::MakeRefCounted<SSLCertRequestInfo>()); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2128 | EXPECT_EQ( |
| 2129 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2130 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2131 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2132 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2133 | pool_.get(), net_log_with_source)); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2134 | EXPECT_EQ(LOAD_STATE_CONNECTING, |
| 2135 | pool_->GetLoadState(TestGroupId("a"), &handle)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2136 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2137 | EXPECT_FALSE(handle.is_ssl_error()); |
Matt Menke | 39b7c5a | 2019-04-10 19:47:51 | [diff] [blame] | 2138 | EXPECT_FALSE(handle.ssl_cert_request_info()); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 2139 | |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2140 | auto entries = |
| 2141 | net_log_observer_.GetEntriesForSource(net_log_with_source.source()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2142 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2143 | EXPECT_EQ(4u, entries.size()); |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 2144 | EXPECT_TRUE(LogContainsEvent( |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2145 | entries, 0, NetLogEventType::TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2146 | NetLogEventPhase::NONE)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2147 | EXPECT_TRUE(LogContainsBeginEvent(entries, 1, NetLogEventType::SOCKET_POOL)); |
| 2148 | EXPECT_TRUE(LogContainsEvent( |
| 2149 | entries, 2, NetLogEventType::SOCKET_POOL_BOUND_TO_CONNECT_JOB, |
| 2150 | NetLogEventPhase::NONE)); |
| 2151 | EXPECT_TRUE(LogContainsEndEvent(entries, 3, NetLogEventType::SOCKET_POOL)); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2152 | } |
| 2153 | |
mmenke | 6be122f | 2015-03-09 22:22:47 | [diff] [blame] | 2154 | // Check that an async ConnectJob failure does not result in creation of a new |
| 2155 | // ConnectJob when there's another pending request also waiting on its own |
| 2156 | // ConnectJob. See http://crbug.com/463960. |
| 2157 | TEST_F(ClientSocketPoolBaseTest, AsyncFailureWithPendingRequestWithJob) { |
| 2158 | CreatePool(2, 2); |
| 2159 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); |
| 2160 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2161 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 2162 | IsError(ERR_IO_PENDING)); |
| 2163 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 2164 | IsError(ERR_IO_PENDING)); |
mmenke | 6be122f | 2015-03-09 22:22:47 | [diff] [blame] | 2165 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2166 | EXPECT_THAT(request(0)->WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
| 2167 | EXPECT_THAT(request(1)->WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
mmenke | 6be122f | 2015-03-09 22:22:47 | [diff] [blame] | 2168 | |
| 2169 | EXPECT_EQ(2, client_socket_factory_.allocation_count()); |
| 2170 | } |
| 2171 | |
[email protected] | 4d3b05d | 2010-01-27 21:27:29 | [diff] [blame] | 2172 | TEST_F(ClientSocketPoolBaseTest, TwoRequestsCancelOne) { |
[email protected] | b22b516 | 2010-03-16 07:53:10 | [diff] [blame] | 2173 | // TODO(eroman): Add back the log expectations! Removed them because the |
| 2174 | // ordering is difficult, and some may fire during destructor. |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 2175 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2176 | |
| 2177 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2178 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2179 | TestCompletionCallback callback; |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2180 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2181 | TestCompletionCallback callback2; |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2182 | |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2183 | EXPECT_EQ( |
| 2184 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2185 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2186 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2187 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2188 | pool_.get(), NetLogWithSource())); |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2189 | RecordingNetLogObserver log2; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 2190 | EXPECT_EQ( |
| 2191 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2192 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2193 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2194 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2195 | pool_.get(), NetLogWithSource())); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2196 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2197 | handle.Reset(); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2198 | |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 2199 | |
| 2200 | // 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] | 2201 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2202 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2203 | handle2.Reset(); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 2204 | |
| 2205 | // Now request 2 has actually finished. |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 2206 | // TODO(eroman): Add back log expectations. |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2207 | } |
| 2208 | |
[email protected] | 4d3b05d | 2010-01-27 21:27:29 | [diff] [blame] | 2209 | TEST_F(ClientSocketPoolBaseTest, CancelRequestLimitsJobs) { |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 2210 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 2211 | |
[email protected] | 17a0c6c | 2009-08-04 00:07:04 | [diff] [blame] | 2212 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 2213 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2214 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOWEST), IsError(ERR_IO_PENDING)); |
| 2215 | EXPECT_THAT(StartRequest(TestGroupId("a"), LOW), IsError(ERR_IO_PENDING)); |
| 2216 | EXPECT_THAT(StartRequest(TestGroupId("a"), MEDIUM), IsError(ERR_IO_PENDING)); |
| 2217 | EXPECT_THAT(StartRequest(TestGroupId("a"), HIGHEST), IsError(ERR_IO_PENDING)); |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 2218 | |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 2219 | EXPECT_EQ(kDefaultMaxSocketsPerGroup, |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2220 | static_cast<int>( |
| 2221 | pool_->NumConnectJobsInGroupForTesting(TestGroupId("a")))); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2222 | (*requests())[2]->handle()->Reset(); |
| 2223 | (*requests())[3]->handle()->Reset(); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 2224 | EXPECT_EQ(kDefaultMaxSocketsPerGroup, |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2225 | static_cast<int>( |
| 2226 | pool_->NumConnectJobsInGroupForTesting(TestGroupId("a")))); |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 2227 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2228 | (*requests())[1]->handle()->Reset(); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 2229 | EXPECT_EQ(kDefaultMaxSocketsPerGroup, |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2230 | static_cast<int>( |
| 2231 | pool_->NumConnectJobsInGroupForTesting(TestGroupId("a")))); |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 2232 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2233 | (*requests())[0]->handle()->Reset(); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 2234 | EXPECT_EQ(kDefaultMaxSocketsPerGroup, |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2235 | static_cast<int>( |
| 2236 | pool_->NumConnectJobsInGroupForTesting(TestGroupId("a")))); |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 2237 | } |
| 2238 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2239 | // When requests and ConnectJobs are not coupled, the request will get serviced |
| 2240 | // by whatever comes first. |
[email protected] | 4d3b05d | 2010-01-27 21:27:29 | [diff] [blame] | 2241 | TEST_F(ClientSocketPoolBaseTest, ReleaseSockets) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 2242 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2243 | |
| 2244 | // Start job 1 (async OK) |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 2245 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2246 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2247 | std::vector<TestSocketRequest*> request_order; |
| 2248 | size_t completion_count; // unused |
| 2249 | TestSocketRequest req1(&request_order, &completion_count); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2250 | int rv = req1.handle()->Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2251 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2252 | ClientSocketPool::RespectLimits::ENABLED, req1.callback(), |
| 2253 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2254 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2255 | EXPECT_THAT(req1.WaitForResult(), IsOk()); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2256 | |
| 2257 | // Job 1 finished OK. Start job 2 (also async OK). Request 3 is pending |
| 2258 | // without a job. |
| 2259 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 2260 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2261 | TestSocketRequest req2(&request_order, &completion_count); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2262 | rv = req2.handle()->Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2263 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2264 | ClientSocketPool::RespectLimits::ENABLED, req2.callback(), |
| 2265 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2266 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2267 | TestSocketRequest req3(&request_order, &completion_count); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2268 | rv = req3.handle()->Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2269 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2270 | ClientSocketPool::RespectLimits::ENABLED, req3.callback(), |
| 2271 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2272 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2273 | |
| 2274 | // Both Requests 2 and 3 are pending. We release socket 1 which should |
| 2275 | // service request 2. Request 3 should still be waiting. |
[email protected] | a6c59f6 | 2009-07-29 16:33:33 | [diff] [blame] | 2276 | req1.handle()->Reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 2277 | // Run the released socket wakeups. |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 2278 | base::RunLoop().RunUntilIdle(); |
[email protected] | a6c59f6 | 2009-07-29 16:33:33 | [diff] [blame] | 2279 | ASSERT_TRUE(req2.handle()->socket()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2280 | EXPECT_THAT(req2.WaitForResult(), IsOk()); |
[email protected] | a6c59f6 | 2009-07-29 16:33:33 | [diff] [blame] | 2281 | EXPECT_FALSE(req3.handle()->socket()); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2282 | |
| 2283 | // Signal job 2, which should service request 3. |
| 2284 | |
| 2285 | client_socket_factory_.SignalJobs(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2286 | EXPECT_THAT(req3.WaitForResult(), IsOk()); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2287 | |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 2288 | ASSERT_EQ(3u, request_order.size()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2289 | EXPECT_EQ(&req1, request_order[0]); |
| 2290 | EXPECT_EQ(&req2, request_order[1]); |
| 2291 | EXPECT_EQ(&req3, request_order[2]); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2292 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2293 | } |
| 2294 | |
| 2295 | // The requests are not coupled to the jobs. So, the requests should finish in |
| 2296 | // their priority / insertion order. |
[email protected] | 4d3b05d | 2010-01-27 21:27:29 | [diff] [blame] | 2297 | TEST_F(ClientSocketPoolBaseTest, PendingJobCompletionOrder) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 2298 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2299 | // First two jobs are async. |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 2300 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2301 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2302 | std::vector<TestSocketRequest*> request_order; |
| 2303 | size_t completion_count; // unused |
| 2304 | TestSocketRequest req1(&request_order, &completion_count); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2305 | int rv = req1.handle()->Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2306 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2307 | ClientSocketPool::RespectLimits::ENABLED, req1.callback(), |
| 2308 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2309 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2310 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2311 | TestSocketRequest req2(&request_order, &completion_count); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2312 | rv = req2.handle()->Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2313 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2314 | ClientSocketPool::RespectLimits::ENABLED, req2.callback(), |
| 2315 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2316 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2317 | |
| 2318 | // The pending job is sync. |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 2319 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2320 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2321 | TestSocketRequest req3(&request_order, &completion_count); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2322 | rv = req3.handle()->Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2323 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2324 | ClientSocketPool::RespectLimits::ENABLED, req3.callback(), |
| 2325 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2326 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2327 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2328 | EXPECT_THAT(req1.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
| 2329 | EXPECT_THAT(req2.WaitForResult(), IsOk()); |
| 2330 | EXPECT_THAT(req3.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2331 | |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 2332 | ASSERT_EQ(3u, request_order.size()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2333 | EXPECT_EQ(&req1, request_order[0]); |
| 2334 | EXPECT_EQ(&req2, request_order[1]); |
| 2335 | EXPECT_EQ(&req3, request_order[2]); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2336 | } |
| 2337 | |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2338 | // Test GetLoadState in the case there's only one socket request. |
| 2339 | TEST_F(ClientSocketPoolBaseTest, LoadStateOneRequest) { |
[email protected] | 211d2172 | 2009-07-22 15:48:53 | [diff] [blame] | 2340 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2341 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2342 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2343 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2344 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2345 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2346 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2347 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
| 2348 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2349 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2350 | EXPECT_EQ(LOAD_STATE_CONNECTING, handle.GetLoadState()); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2351 | |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2352 | client_socket_factory_.SetJobLoadState(0, LOAD_STATE_SSL_HANDSHAKE); |
| 2353 | EXPECT_EQ(LOAD_STATE_SSL_HANDSHAKE, handle.GetLoadState()); |
| 2354 | |
| 2355 | // No point in completing the connection, since ClientSocketHandles only |
| 2356 | // expect the LoadState to be checked while connecting. |
| 2357 | } |
| 2358 | |
| 2359 | // Test GetLoadState in the case there are two socket requests. |
| 2360 | TEST_F(ClientSocketPoolBaseTest, LoadStateTwoRequests) { |
| 2361 | CreatePool(2, 2); |
| 2362 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 2363 | |
| 2364 | ClientSocketHandle handle; |
| 2365 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2366 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2367 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2368 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
| 2369 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2370 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
haavardm | 835c1d6 | 2015-04-22 08:18:00 | [diff] [blame] | 2371 | client_socket_factory_.SetJobLoadState(0, LOAD_STATE_RESOLVING_HOST); |
| 2372 | |
| 2373 | ClientSocketHandle handle2; |
| 2374 | TestCompletionCallback callback2; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2375 | rv = handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2376 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2377 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2378 | pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2379 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
haavardm | 835c1d6 | 2015-04-22 08:18:00 | [diff] [blame] | 2380 | client_socket_factory_.SetJobLoadState(1, LOAD_STATE_RESOLVING_HOST); |
| 2381 | |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 2382 | // Each handle should reflect the state of its own job. |
haavardm | 835c1d6 | 2015-04-22 08:18:00 | [diff] [blame] | 2383 | EXPECT_EQ(LOAD_STATE_RESOLVING_HOST, handle.GetLoadState()); |
| 2384 | EXPECT_EQ(LOAD_STATE_RESOLVING_HOST, handle2.GetLoadState()); |
| 2385 | |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 2386 | // Update the state of the first job. |
haavardm | 835c1d6 | 2015-04-22 08:18:00 | [diff] [blame] | 2387 | client_socket_factory_.SetJobLoadState(0, LOAD_STATE_CONNECTING); |
| 2388 | |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 2389 | // Only the state of the first request should have changed. |
haavardm | 835c1d6 | 2015-04-22 08:18:00 | [diff] [blame] | 2390 | EXPECT_EQ(LOAD_STATE_CONNECTING, handle.GetLoadState()); |
haavardm | 835c1d6 | 2015-04-22 08:18:00 | [diff] [blame] | 2391 | EXPECT_EQ(LOAD_STATE_RESOLVING_HOST, handle2.GetLoadState()); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 2392 | |
| 2393 | // Update the state of the second job. |
| 2394 | client_socket_factory_.SetJobLoadState(1, LOAD_STATE_SSL_HANDSHAKE); |
| 2395 | |
| 2396 | // Only the state of the second request should have changed. |
| 2397 | EXPECT_EQ(LOAD_STATE_CONNECTING, handle.GetLoadState()); |
| 2398 | EXPECT_EQ(LOAD_STATE_SSL_HANDSHAKE, handle2.GetLoadState()); |
| 2399 | |
| 2400 | // Second job connects and the first request gets the socket. The |
| 2401 | // second handle switches to the state of the remaining ConnectJob. |
| 2402 | client_socket_factory_.SignalJob(1); |
| 2403 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 2404 | EXPECT_EQ(LOAD_STATE_CONNECTING, handle2.GetLoadState()); |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | // Test GetLoadState in the case the per-group limit is reached. |
| 2408 | TEST_F(ClientSocketPoolBaseTest, LoadStateGroupLimit) { |
| 2409 | CreatePool(2, 1); |
| 2410 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 2411 | |
| 2412 | ClientSocketHandle handle; |
| 2413 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2414 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2415 | TestGroupId("a"), params_, absl::nullopt, MEDIUM, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2416 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
| 2417 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2418 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2419 | EXPECT_EQ(LOAD_STATE_CONNECTING, handle.GetLoadState()); |
| 2420 | |
| 2421 | // Request another socket from the same pool, buth with a higher priority. |
| 2422 | // The first request should now be stalled at the socket group limit. |
| 2423 | ClientSocketHandle handle2; |
| 2424 | TestCompletionCallback callback2; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2425 | rv = handle2.Init(TestGroupId("a"), params_, absl::nullopt, HIGHEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2426 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2427 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2428 | pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2429 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2430 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_AVAILABLE_SOCKET, handle.GetLoadState()); |
| 2431 | EXPECT_EQ(LOAD_STATE_CONNECTING, handle2.GetLoadState()); |
| 2432 | |
| 2433 | // The first handle should remain stalled as the other socket goes through |
| 2434 | // the connect process. |
| 2435 | |
| 2436 | client_socket_factory_.SetJobLoadState(0, LOAD_STATE_SSL_HANDSHAKE); |
| 2437 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_AVAILABLE_SOCKET, handle.GetLoadState()); |
| 2438 | EXPECT_EQ(LOAD_STATE_SSL_HANDSHAKE, handle2.GetLoadState()); |
| 2439 | |
| 2440 | client_socket_factory_.SignalJob(0); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2441 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2442 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_AVAILABLE_SOCKET, handle.GetLoadState()); |
| 2443 | |
| 2444 | // Closing the second socket should cause the stalled handle to finally get a |
| 2445 | // ConnectJob. |
| 2446 | handle2.socket()->Disconnect(); |
| 2447 | handle2.Reset(); |
| 2448 | EXPECT_EQ(LOAD_STATE_CONNECTING, handle.GetLoadState()); |
| 2449 | } |
| 2450 | |
| 2451 | // Test GetLoadState in the case the per-pool limit is reached. |
| 2452 | TEST_F(ClientSocketPoolBaseTest, LoadStatePoolLimit) { |
| 2453 | CreatePool(2, 2); |
| 2454 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 2455 | |
| 2456 | ClientSocketHandle handle; |
| 2457 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2458 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2459 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2460 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
| 2461 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2462 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2463 | |
| 2464 | // Request for socket from another pool. |
| 2465 | ClientSocketHandle handle2; |
| 2466 | TestCompletionCallback callback2; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2467 | rv = handle2.Init(TestGroupId("b"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2468 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2469 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2470 | pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2471 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2472 | |
| 2473 | // Request another socket from the first pool. Request should stall at the |
| 2474 | // socket pool limit. |
| 2475 | ClientSocketHandle handle3; |
| 2476 | TestCompletionCallback callback3; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2477 | rv = handle3.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2478 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2479 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2480 | pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2481 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2482 | |
| 2483 | // The third handle should remain stalled as the other sockets in its group |
| 2484 | // goes through the connect process. |
| 2485 | |
| 2486 | EXPECT_EQ(LOAD_STATE_CONNECTING, handle.GetLoadState()); |
| 2487 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_STALLED_SOCKET_POOL, handle3.GetLoadState()); |
| 2488 | |
| 2489 | client_socket_factory_.SetJobLoadState(0, LOAD_STATE_SSL_HANDSHAKE); |
| 2490 | EXPECT_EQ(LOAD_STATE_SSL_HANDSHAKE, handle.GetLoadState()); |
| 2491 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_STALLED_SOCKET_POOL, handle3.GetLoadState()); |
| 2492 | |
| 2493 | client_socket_factory_.SignalJob(0); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2494 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 03b7c8c | 2013-07-20 04:38:55 | [diff] [blame] | 2495 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_STALLED_SOCKET_POOL, handle3.GetLoadState()); |
| 2496 | |
| 2497 | // Closing a socket should allow the stalled handle to finally get a new |
| 2498 | // ConnectJob. |
| 2499 | handle.socket()->Disconnect(); |
| 2500 | handle.Reset(); |
| 2501 | EXPECT_EQ(LOAD_STATE_CONNECTING, handle3.GetLoadState()); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 2502 | } |
| 2503 | |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 2504 | TEST_F(ClientSocketPoolBaseTest, CertError) { |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2505 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 2506 | connect_job_factory_->set_job_type(TestConnectJob::kMockCertErrorJob); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2507 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2508 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2509 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2510 | EXPECT_EQ( |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 2511 | ERR_CERT_COMMON_NAME_INVALID, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2512 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2513 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2514 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2515 | pool_.get(), NetLogWithSource())); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2516 | EXPECT_TRUE(handle.is_initialized()); |
| 2517 | EXPECT_TRUE(handle.socket()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2518 | } |
| 2519 | |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 2520 | TEST_F(ClientSocketPoolBaseTest, AsyncCertError) { |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2521 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 2522 | |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 2523 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingCertErrorJob); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2524 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2525 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2526 | EXPECT_EQ( |
| 2527 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2528 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2529 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2530 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2531 | pool_.get(), NetLogWithSource())); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2532 | EXPECT_EQ(LOAD_STATE_CONNECTING, |
| 2533 | pool_->GetLoadState(TestGroupId("a"), &handle)); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 2534 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CERT_COMMON_NAME_INVALID)); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2535 | EXPECT_TRUE(handle.is_initialized()); |
| 2536 | EXPECT_TRUE(handle.socket()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2537 | } |
| 2538 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2539 | TEST_F(ClientSocketPoolBaseTest, AdditionalErrorStateSynchronous) { |
| 2540 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 2541 | connect_job_factory_->set_job_type( |
| 2542 | TestConnectJob::kMockAdditionalErrorStateJob); |
| 2543 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2544 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2545 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2546 | EXPECT_EQ( |
| 2547 | ERR_CONNECTION_FAILED, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2548 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2549 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2550 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2551 | pool_.get(), NetLogWithSource())); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2552 | EXPECT_FALSE(handle.is_initialized()); |
| 2553 | EXPECT_FALSE(handle.socket()); |
| 2554 | EXPECT_TRUE(handle.is_ssl_error()); |
Matt Menke | 39b7c5a | 2019-04-10 19:47:51 | [diff] [blame] | 2555 | EXPECT_TRUE(handle.ssl_cert_request_info()); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2556 | } |
| 2557 | |
| 2558 | TEST_F(ClientSocketPoolBaseTest, AdditionalErrorStateAsynchronous) { |
| 2559 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 2560 | |
| 2561 | connect_job_factory_->set_job_type( |
| 2562 | TestConnectJob::kMockPendingAdditionalErrorStateJob); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2563 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2564 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2565 | EXPECT_EQ( |
| 2566 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2567 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2568 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2569 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2570 | pool_.get(), NetLogWithSource())); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2571 | EXPECT_EQ(LOAD_STATE_CONNECTING, |
| 2572 | pool_->GetLoadState(TestGroupId("a"), &handle)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2573 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2574 | EXPECT_FALSE(handle.is_initialized()); |
| 2575 | EXPECT_FALSE(handle.socket()); |
| 2576 | EXPECT_TRUE(handle.is_ssl_error()); |
Matt Menke | 39b7c5a | 2019-04-10 19:47:51 | [diff] [blame] | 2577 | EXPECT_TRUE(handle.ssl_cert_request_info()); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2578 | } |
| 2579 | |
martijn | 003cd61 | 2016-05-19 22:24:38 | [diff] [blame] | 2580 | // Make sure we can reuse sockets. |
| 2581 | TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSocketsReuse) { |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2582 | CreatePoolWithIdleTimeouts( |
| 2583 | kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2584 | base::TimeDelta(), // Time out unused sockets immediately. |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 2585 | base::Days(1)); // Don't time out used sockets. |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2586 | |
| 2587 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 2588 | |
| 2589 | ClientSocketHandle handle; |
| 2590 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2591 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2592 | TestGroupId("a"), params_, absl::nullopt, LOWEST, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2593 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
| 2594 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2595 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2596 | EXPECT_EQ(LOAD_STATE_CONNECTING, |
| 2597 | pool_->GetLoadState(TestGroupId("a"), &handle)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2598 | ASSERT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2599 | |
| 2600 | // Use and release the socket. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2601 | EXPECT_EQ(1, handle.socket()->Write(nullptr, 1, CompletionOnceCallback(), |
Ramin Halavati | 0a08cc8 | 2018-02-06 07:46:38 | [diff] [blame] | 2602 | TRAFFIC_ANNOTATION_FOR_TESTS)); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 2603 | TestLoadTimingInfoConnectedNotReused(handle); |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2604 | handle.Reset(); |
| 2605 | |
| 2606 | // Should now have one idle socket. |
| 2607 | ASSERT_EQ(1, pool_->IdleSocketCount()); |
| 2608 | |
| 2609 | // Request a new socket. This should reuse the old socket and complete |
| 2610 | // synchronously. |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2611 | NetLogWithSource net_log_with_source = |
| 2612 | NetLogWithSource::Make(NetLogSourceType::NONE); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2613 | rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2614 | TestGroupId("a"), params_, absl::nullopt, LOWEST, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2615 | ClientSocketPool::RespectLimits::ENABLED, CompletionOnceCallback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2616 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), net_log_with_source); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2617 | ASSERT_THAT(rv, IsOk()); |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2618 | EXPECT_TRUE(handle.is_reused()); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 2619 | TestLoadTimingInfoConnectedReused(handle); |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2620 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2621 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2622 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2623 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2624 | |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2625 | auto entries = |
| 2626 | net_log_observer_.GetEntriesForSource(net_log_with_source.source()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2627 | EXPECT_TRUE(LogContainsEvent( |
| 2628 | entries, 0, NetLogEventType::TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET, |
| 2629 | NetLogEventPhase::NONE)); |
| 2630 | EXPECT_TRUE(LogContainsBeginEvent(entries, 1, NetLogEventType::SOCKET_POOL)); |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2631 | EXPECT_TRUE(LogContainsEntryWithType( |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2632 | entries, 2, NetLogEventType::SOCKET_POOL_REUSED_AN_EXISTING_SOCKET)); |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2633 | } |
| 2634 | |
martijn | 003cd61 | 2016-05-19 22:24:38 | [diff] [blame] | 2635 | // Make sure we cleanup old unused sockets. |
Eric Roman | b49715e | 2018-04-24 22:41:17 | [diff] [blame] | 2636 | TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSocketsNoReuse) { |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2637 | CreatePoolWithIdleTimeouts( |
| 2638 | kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, |
| 2639 | base::TimeDelta(), // Time out unused sockets immediately |
| 2640 | base::TimeDelta()); // Time out used sockets immediately |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2641 | |
| 2642 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 2643 | |
| 2644 | // Startup two mock pending connect jobs, which will sit in the MessageLoop. |
| 2645 | |
| 2646 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2647 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2648 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2649 | TestGroupId("a"), params_, absl::nullopt, LOWEST, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2650 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
| 2651 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2652 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2653 | EXPECT_EQ(LOAD_STATE_CONNECTING, |
| 2654 | pool_->GetLoadState(TestGroupId("a"), &handle)); |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2655 | |
| 2656 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2657 | TestCompletionCallback callback2; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2658 | rv = handle2.Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2659 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2660 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2661 | pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2662 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2663 | EXPECT_EQ(LOAD_STATE_CONNECTING, |
| 2664 | pool_->GetLoadState(TestGroupId("a"), &handle2)); |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2665 | |
| 2666 | // Cancel one of the requests. Wait for the other, which will get the first |
| 2667 | // job. Release the socket. Run the loop again to make sure the second |
| 2668 | // socket is sitting idle and the first one is released (since ReleaseSocket() |
| 2669 | // just posts a DoReleaseSocket() task). |
| 2670 | |
| 2671 | handle.Reset(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2672 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 2673 | // Get the NetLogSource for the socket, so the time out reason can be checked |
| 2674 | // at the end of the test. |
| 2675 | NetLogSource net_log_source2 = handle2.socket()->NetLog().source(); |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2676 | // Use the socket. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2677 | EXPECT_EQ(1, handle2.socket()->Write(nullptr, 1, CompletionOnceCallback(), |
Ramin Halavati | 0a08cc8 | 2018-02-06 07:46:38 | [diff] [blame] | 2678 | TRAFFIC_ANNOTATION_FOR_TESTS)); |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2679 | handle2.Reset(); |
| 2680 | |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2681 | // We post all of our delayed tasks with a 2ms delay. I.e. they don't |
| 2682 | // actually become pending until 2ms after they have been created. In order |
| 2683 | // to flush all tasks, we need to wait so that we know there are no |
| 2684 | // soon-to-be-pending tasks waiting. |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 2685 | FastForwardBy(base::Milliseconds(10)); |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2686 | |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2687 | // Both sockets should now be idle. |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2688 | ASSERT_EQ(2, pool_->IdleSocketCount()); |
| 2689 | |
| 2690 | // Request a new socket. This should cleanup the unused and timed out ones. |
| 2691 | // A new socket will be created rather than reusing the idle one. |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2692 | NetLogWithSource net_log_with_source = |
| 2693 | NetLogWithSource::Make(NetLogSourceType::NONE); |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2694 | TestCompletionCallback callback3; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2695 | rv = handle.Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2696 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2697 | callback3.callback(), ClientSocketPool::ProxyAuthCallback(), |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2698 | pool_.get(), net_log_with_source); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2699 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2700 | ASSERT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2701 | EXPECT_FALSE(handle.is_reused()); |
| 2702 | |
[email protected] | e7b1c6d2c | 2012-05-05 00:54:03 | [diff] [blame] | 2703 | // Make sure the idle socket is closed. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2704 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2705 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2706 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2707 | |
Matt Reichhoff | 0049a0b7 | 2021-10-20 20:44:26 | [diff] [blame] | 2708 | auto entries = |
| 2709 | net_log_observer_.GetEntriesForSource(net_log_with_source.source()); |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2710 | EXPECT_FALSE(LogContainsEntryWithType( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2711 | entries, 1, NetLogEventType::SOCKET_POOL_REUSED_AN_EXISTING_SOCKET)); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 2712 | ExpectSocketClosedWithReason( |
| 2713 | net_log_source2, TransportClientSocketPool::kIdleTimeLimitExpired); |
[email protected] | 64770b7d | 2011-11-16 04:30:41 | [diff] [blame] | 2714 | } |
| 2715 | |
[email protected] | 2041cf34 | 2010-02-19 03:15:59 | [diff] [blame] | 2716 | // Make sure that we process all pending requests even when we're stalling |
[email protected] | 4f2abec | 2010-02-03 18:10:16 | [diff] [blame] | 2717 | // because of multiple releasing disconnected sockets. |
| 2718 | TEST_F(ClientSocketPoolBaseTest, MultipleReleasingDisconnectedSockets) { |
| 2719 | CreatePoolWithIdleTimeouts( |
| 2720 | kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, |
| 2721 | base::TimeDelta(), // Time out unused sockets immediately. |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 2722 | base::Days(1)); // Don't time out used sockets. |
[email protected] | 4f2abec | 2010-02-03 18:10:16 | [diff] [blame] | 2723 | |
| 2724 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 2725 | |
| 2726 | // Startup 4 connect jobs. Two of them will be pending. |
| 2727 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2728 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2729 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2730 | int rv = handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2731 | TestGroupId("a"), params_, absl::nullopt, LOWEST, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2732 | ClientSocketPool::RespectLimits::ENABLED, callback.callback(), |
| 2733 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2734 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 4f2abec | 2010-02-03 18:10:16 | [diff] [blame] | 2735 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2736 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2737 | TestCompletionCallback callback2; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2738 | rv = handle2.Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2739 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2740 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2741 | pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2742 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 4f2abec | 2010-02-03 18:10:16 | [diff] [blame] | 2743 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2744 | ClientSocketHandle handle3; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2745 | TestCompletionCallback callback3; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2746 | rv = handle3.Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2747 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2748 | callback3.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2749 | pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2750 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4f2abec | 2010-02-03 18:10:16 | [diff] [blame] | 2751 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2752 | ClientSocketHandle handle4; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2753 | TestCompletionCallback callback4; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2754 | rv = handle4.Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2755 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2756 | callback4.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2757 | pool_.get(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2758 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4f2abec | 2010-02-03 18:10:16 | [diff] [blame] | 2759 | |
| 2760 | // Release two disconnected sockets. |
| 2761 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2762 | handle.socket()->Disconnect(); |
| 2763 | handle.Reset(); |
| 2764 | handle2.socket()->Disconnect(); |
| 2765 | handle2.Reset(); |
[email protected] | 4f2abec | 2010-02-03 18:10:16 | [diff] [blame] | 2766 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2767 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2768 | EXPECT_FALSE(handle3.is_reused()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2769 | EXPECT_THAT(callback4.WaitForResult(), IsOk()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2770 | EXPECT_FALSE(handle4.is_reused()); |
[email protected] | 4f2abec | 2010-02-03 18:10:16 | [diff] [blame] | 2771 | } |
| 2772 | |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 2773 | // Regression test for http://crbug.com/42267. |
| 2774 | // When DoReleaseSocket() is processed for one socket, it is blocked because the |
| 2775 | // other stalled groups all have releasing sockets, so no progress can be made. |
| 2776 | TEST_F(ClientSocketPoolBaseTest, SocketLimitReleasingSockets) { |
| 2777 | CreatePoolWithIdleTimeouts( |
| 2778 | 4 /* socket limit */, 4 /* socket limit per group */, |
| 2779 | base::TimeDelta(), // Time out unused sockets immediately. |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 2780 | base::Days(1)); // Don't time out used sockets. |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 2781 | |
| 2782 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 2783 | |
| 2784 | // Max out the socket limit with 2 per group. |
| 2785 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2786 | ClientSocketHandle handle_a[4]; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2787 | TestCompletionCallback callback_a[4]; |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2788 | ClientSocketHandle handle_b[4]; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2789 | TestCompletionCallback callback_b[4]; |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 2790 | |
| 2791 | for (int i = 0; i < 2; ++i) { |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2792 | EXPECT_EQ(OK, handle_a[i].Init(TestGroupId("a"), params_, absl::nullopt, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2793 | LOWEST, SocketTag(), |
| 2794 | ClientSocketPool::RespectLimits::ENABLED, |
| 2795 | callback_a[i].callback(), |
| 2796 | ClientSocketPool::ProxyAuthCallback(), |
| 2797 | pool_.get(), NetLogWithSource())); |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2798 | EXPECT_EQ(OK, handle_b[i].Init(TestGroupId("b"), params_, absl::nullopt, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2799 | LOWEST, SocketTag(), |
| 2800 | ClientSocketPool::RespectLimits::ENABLED, |
| 2801 | callback_b[i].callback(), |
| 2802 | ClientSocketPool::ProxyAuthCallback(), |
| 2803 | pool_.get(), NetLogWithSource())); |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 2804 | } |
[email protected] | b89f7e4 | 2010-05-20 20:37:00 | [diff] [blame] | 2805 | |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 2806 | // Make 4 pending requests, 2 per group. |
| 2807 | |
| 2808 | for (int i = 2; i < 4; ++i) { |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2809 | EXPECT_EQ( |
| 2810 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2811 | handle_a[i].Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2812 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2813 | callback_a[i].callback(), |
| 2814 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 2815 | NetLogWithSource())); |
| 2816 | EXPECT_EQ( |
| 2817 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2818 | handle_b[i].Init(TestGroupId("b"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2819 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2820 | callback_b[i].callback(), |
| 2821 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 2822 | NetLogWithSource())); |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 2823 | } |
| 2824 | |
| 2825 | // Release b's socket first. The order is important, because in |
| 2826 | // DoReleaseSocket(), we'll process b's released socket, and since both b and |
| 2827 | // a are stalled, but 'a' is lower lexicographically, we'll process group 'a' |
| 2828 | // first, which has a releasing socket, so it refuses to start up another |
| 2829 | // ConnectJob. So, we used to infinite loop on this. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2830 | handle_b[0].socket()->Disconnect(); |
| 2831 | handle_b[0].Reset(); |
| 2832 | handle_a[0].socket()->Disconnect(); |
| 2833 | handle_a[0].Reset(); |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 2834 | |
| 2835 | // Used to get stuck here. |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 2836 | base::RunLoop().RunUntilIdle(); |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 2837 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2838 | handle_b[1].socket()->Disconnect(); |
| 2839 | handle_b[1].Reset(); |
| 2840 | handle_a[1].socket()->Disconnect(); |
| 2841 | handle_a[1].Reset(); |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 2842 | |
| 2843 | for (int i = 2; i < 4; ++i) { |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2844 | EXPECT_THAT(callback_b[i].WaitForResult(), IsOk()); |
| 2845 | EXPECT_THAT(callback_a[i].WaitForResult(), IsOk()); |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 2846 | } |
| 2847 | } |
| 2848 | |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 2849 | TEST_F(ClientSocketPoolBaseTest, |
| 2850 | ReleasingDisconnectedSocketsMaintainsPriorityOrder) { |
| 2851 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 2852 | |
| 2853 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 2854 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2855 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 2856 | IsError(ERR_IO_PENDING)); |
| 2857 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 2858 | IsError(ERR_IO_PENDING)); |
| 2859 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 2860 | IsError(ERR_IO_PENDING)); |
| 2861 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), |
| 2862 | IsError(ERR_IO_PENDING)); |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 2863 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2864 | EXPECT_THAT((*requests())[0]->WaitForResult(), IsOk()); |
| 2865 | EXPECT_THAT((*requests())[1]->WaitForResult(), IsOk()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2866 | EXPECT_EQ(2u, completion_count()); |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 2867 | |
| 2868 | // Releases one connection. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2869 | EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::NO_KEEP_ALIVE)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2870 | EXPECT_THAT((*requests())[2]->WaitForResult(), IsOk()); |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 2871 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2872 | EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::NO_KEEP_ALIVE)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2873 | EXPECT_THAT((*requests())[3]->WaitForResult(), IsOk()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2874 | EXPECT_EQ(4u, completion_count()); |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 2875 | |
| 2876 | EXPECT_EQ(1, GetOrderOfRequest(1)); |
| 2877 | EXPECT_EQ(2, GetOrderOfRequest(2)); |
| 2878 | EXPECT_EQ(3, GetOrderOfRequest(3)); |
| 2879 | EXPECT_EQ(4, GetOrderOfRequest(4)); |
| 2880 | |
| 2881 | // Make sure we test order of all requests made. |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2882 | EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(5)); |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 2883 | } |
| 2884 | |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2885 | class TestReleasingSocketRequest : public TestCompletionCallbackBase { |
[email protected] | 4f1e498 | 2010-03-02 18:31:04 | [diff] [blame] | 2886 | public: |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 2887 | TestReleasingSocketRequest(TransportClientSocketPool* pool, |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2888 | int expected_result, |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2889 | bool reset_releasing_handle) |
| 2890 | : pool_(pool), |
| 2891 | expected_result_(expected_result), |
Bence Béky | 8ddc249 | 2018-06-13 01:02:04 | [diff] [blame] | 2892 | reset_releasing_handle_(reset_releasing_handle) {} |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2893 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 2894 | ~TestReleasingSocketRequest() override = default; |
[email protected] | 4f1e498 | 2010-03-02 18:31:04 | [diff] [blame] | 2895 | |
| 2896 | ClientSocketHandle* handle() { return &handle_; } |
| 2897 | |
Bence Béky | 8ddc249 | 2018-06-13 01:02:04 | [diff] [blame] | 2898 | CompletionOnceCallback callback() { |
| 2899 | return base::BindOnce(&TestReleasingSocketRequest::OnComplete, |
| 2900 | base::Unretained(this)); |
| 2901 | } |
[email protected] | 4f1e498 | 2010-03-02 18:31:04 | [diff] [blame] | 2902 | |
| 2903 | private: |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2904 | void OnComplete(int result) { |
| 2905 | SetResult(result); |
| 2906 | if (reset_releasing_handle_) |
| 2907 | handle_.Reset(); |
| 2908 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2909 | EXPECT_EQ( |
| 2910 | expected_result_, |
Matt Menke | 870e19ab | 2019-04-23 16:23:03 | [diff] [blame] | 2911 | handle2_.Init( |
| 2912 | TestGroupId("a"), |
| 2913 | ClientSocketPool::SocketParams::CreateForHttpForTesting(), |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2914 | absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | 870e19ab | 2019-04-23 16:23:03 | [diff] [blame] | 2915 | ClientSocketPool::RespectLimits::ENABLED, CompletionOnceCallback(), |
| 2916 | ClientSocketPool::ProxyAuthCallback(), pool_, NetLogWithSource())); |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2917 | } |
| 2918 | |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 2919 | const raw_ptr<TransportClientSocketPool> pool_; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2920 | int expected_result_; |
| 2921 | bool reset_releasing_handle_; |
[email protected] | 4f1e498 | 2010-03-02 18:31:04 | [diff] [blame] | 2922 | ClientSocketHandle handle_; |
| 2923 | ClientSocketHandle handle2_; |
[email protected] | 4f1e498 | 2010-03-02 18:31:04 | [diff] [blame] | 2924 | }; |
| 2925 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2926 | |
| 2927 | TEST_F(ClientSocketPoolBaseTest, AdditionalErrorSocketsDontUseSlot) { |
| 2928 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 2929 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 2930 | EXPECT_THAT(StartRequest(TestGroupId("b"), DEFAULT_PRIORITY), IsOk()); |
| 2931 | EXPECT_THAT(StartRequest(TestGroupId("a"), DEFAULT_PRIORITY), IsOk()); |
| 2932 | EXPECT_THAT(StartRequest(TestGroupId("b"), DEFAULT_PRIORITY), IsOk()); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2933 | |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 2934 | EXPECT_EQ(static_cast<int>(requests_size()), |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2935 | client_socket_factory_.allocation_count()); |
| 2936 | |
| 2937 | connect_job_factory_->set_job_type( |
| 2938 | TestConnectJob::kMockPendingAdditionalErrorStateJob); |
| 2939 | TestReleasingSocketRequest req(pool_.get(), OK, false); |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2940 | EXPECT_EQ(ERR_IO_PENDING, |
| 2941 | req.handle()->Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2942 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2943 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2944 | req.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2945 | pool_.get(), NetLogWithSource())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2946 | // The next job should complete synchronously |
| 2947 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 2948 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2949 | EXPECT_THAT(req.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2950 | EXPECT_FALSE(req.handle()->is_initialized()); |
| 2951 | EXPECT_FALSE(req.handle()->socket()); |
| 2952 | EXPECT_TRUE(req.handle()->is_ssl_error()); |
Matt Menke | 39b7c5a | 2019-04-10 19:47:51 | [diff] [blame] | 2953 | EXPECT_TRUE(req.handle()->ssl_cert_request_info()); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2954 | } |
| 2955 | |
[email protected] | b6501d3d | 2010-06-03 23:53:34 | [diff] [blame] | 2956 | // http://crbug.com/44724 regression test. |
| 2957 | // We start releasing the pool when we flush on network change. When that |
| 2958 | // happens, the only active references are in the ClientSocketHandles. When a |
| 2959 | // ConnectJob completes and calls back into the last ClientSocketHandle, that |
| 2960 | // callback can release the last reference and delete the pool. After the |
| 2961 | // callback finishes, we go back to the stack frame within the now-deleted pool. |
| 2962 | // Executing any code that refers to members of the now-deleted pool can cause |
| 2963 | // crashes. |
| 2964 | TEST_F(ClientSocketPoolBaseTest, CallbackThatReleasesPool) { |
| 2965 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 2966 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); |
| 2967 | |
| 2968 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2969 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2970 | EXPECT_EQ( |
| 2971 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2972 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2973 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2974 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2975 | pool_.get(), NetLogWithSource())); |
[email protected] | b6501d3d | 2010-06-03 23:53:34 | [diff] [blame] | 2976 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 2977 | pool_->FlushWithError(ERR_NETWORK_CHANGED, "Network changed"); |
[email protected] | b6501d3d | 2010-06-03 23:53:34 | [diff] [blame] | 2978 | |
| 2979 | // We'll call back into this now. |
| 2980 | callback.WaitForResult(); |
| 2981 | } |
| 2982 | |
[email protected] | a7e3857 | 2010-06-07 18:22:24 | [diff] [blame] | 2983 | TEST_F(ClientSocketPoolBaseTest, DoNotReuseSocketAfterFlush) { |
| 2984 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 2985 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 2986 | |
| 2987 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 2988 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 2989 | EXPECT_EQ( |
| 2990 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 2991 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 2992 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 2993 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 2994 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2995 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | a7e3857 | 2010-06-07 18:22:24 | [diff] [blame] | 2996 | EXPECT_EQ(ClientSocketHandle::UNUSED, handle.reuse_type()); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 2997 | NetLogSource source = handle.socket()->NetLog().source(); |
[email protected] | a7e3857 | 2010-06-07 18:22:24 | [diff] [blame] | 2998 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 2999 | pool_->FlushWithError(ERR_NETWORK_CHANGED, "Network changed"); |
[email protected] | a7e3857 | 2010-06-07 18:22:24 | [diff] [blame] | 3000 | |
| 3001 | handle.Reset(); |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 3002 | base::RunLoop().RunUntilIdle(); |
[email protected] | a7e3857 | 2010-06-07 18:22:24 | [diff] [blame] | 3003 | |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3004 | EXPECT_EQ( |
| 3005 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3006 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3007 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 3008 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3009 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3010 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | a7e3857 | 2010-06-07 18:22:24 | [diff] [blame] | 3011 | EXPECT_EQ(ClientSocketHandle::UNUSED, handle.reuse_type()); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 3012 | |
| 3013 | ExpectSocketClosedWithReason( |
| 3014 | source, TransportClientSocketPool::kSocketGenerationOutOfDate); |
[email protected] | a7e3857 | 2010-06-07 18:22:24 | [diff] [blame] | 3015 | } |
| 3016 | |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3017 | class ConnectWithinCallback : public TestCompletionCallbackBase { |
[email protected] | 06f9246 | 2010-08-31 19:24:14 | [diff] [blame] | 3018 | public: |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3019 | ConnectWithinCallback( |
| 3020 | const ClientSocketPool::GroupId& group_id, |
Matt Menke | 84d11e56 | 2019-03-27 00:11:19 | [diff] [blame] | 3021 | const scoped_refptr<ClientSocketPool::SocketParams>& params, |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3022 | TransportClientSocketPool* pool) |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3023 | : group_id_(group_id), params_(params), pool_(pool) {} |
[email protected] | 06f9246 | 2010-08-31 19:24:14 | [diff] [blame] | 3024 | |
Peter Boström | 293b134 | 2021-09-22 17:31:43 | [diff] [blame] | 3025 | ConnectWithinCallback(const ConnectWithinCallback&) = delete; |
| 3026 | ConnectWithinCallback& operator=(const ConnectWithinCallback&) = delete; |
| 3027 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 3028 | ~ConnectWithinCallback() override = default; |
[email protected] | 06f9246 | 2010-08-31 19:24:14 | [diff] [blame] | 3029 | |
| 3030 | int WaitForNestedResult() { |
| 3031 | return nested_callback_.WaitForResult(); |
| 3032 | } |
| 3033 | |
Bence Béky | 8ddc249 | 2018-06-13 01:02:04 | [diff] [blame] | 3034 | CompletionOnceCallback callback() { |
| 3035 | return base::BindOnce(&ConnectWithinCallback::OnComplete, |
| 3036 | base::Unretained(this)); |
| 3037 | } |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3038 | |
[email protected] | 06f9246 | 2010-08-31 19:24:14 | [diff] [blame] | 3039 | private: |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3040 | void OnComplete(int result) { |
| 3041 | SetResult(result); |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3042 | EXPECT_EQ( |
| 3043 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3044 | handle_.Init(group_id_, params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3045 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 3046 | nested_callback_.callback(), |
| 3047 | ClientSocketPool::ProxyAuthCallback(), pool_, |
| 3048 | NetLogWithSource())); |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3049 | } |
| 3050 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3051 | const ClientSocketPool::GroupId group_id_; |
Matt Menke | 84d11e56 | 2019-03-27 00:11:19 | [diff] [blame] | 3052 | const scoped_refptr<ClientSocketPool::SocketParams> params_; |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 3053 | const raw_ptr<TransportClientSocketPool> pool_; |
[email protected] | 06f9246 | 2010-08-31 19:24:14 | [diff] [blame] | 3054 | ClientSocketHandle handle_; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3055 | TestCompletionCallback nested_callback_; |
[email protected] | 06f9246 | 2010-08-31 19:24:14 | [diff] [blame] | 3056 | }; |
| 3057 | |
| 3058 | TEST_F(ClientSocketPoolBaseTest, AbortAllRequestsOnFlush) { |
| 3059 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 3060 | |
| 3061 | // First job will be waiting until it gets aborted. |
| 3062 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 3063 | |
| 3064 | ClientSocketHandle handle; |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3065 | ConnectWithinCallback callback(TestGroupId("a"), params_, pool_.get()); |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3066 | EXPECT_EQ( |
| 3067 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3068 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3069 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 3070 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3071 | pool_.get(), NetLogWithSource())); |
[email protected] | 06f9246 | 2010-08-31 19:24:14 | [diff] [blame] | 3072 | |
| 3073 | // Second job will be started during the first callback, and will |
| 3074 | // asynchronously complete with OK. |
| 3075 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 3076 | pool_->FlushWithError(ERR_NETWORK_CHANGED, "Network changed"); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3077 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NETWORK_CHANGED)); |
| 3078 | EXPECT_THAT(callback.WaitForNestedResult(), IsOk()); |
[email protected] | 06f9246 | 2010-08-31 19:24:14 | [diff] [blame] | 3079 | } |
| 3080 | |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 3081 | TEST_F(ClientSocketPoolBaseTest, BackupSocketWaitsForHostResolution) { |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3082 | CreatePool(kDefaultMaxSockets, kDefaultMaxSockets, |
| 3083 | true /* enable_backup_connect_jobs */); |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 3084 | |
| 3085 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 3086 | ClientSocketHandle handle; |
| 3087 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3088 | EXPECT_EQ( |
| 3089 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3090 | handle.Init(TestGroupId("bar"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3091 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 3092 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3093 | pool_.get(), NetLogWithSource())); |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 3094 | // The backup timer fires but doesn't start a new ConnectJob while resolving |
| 3095 | // the hostname. |
| 3096 | client_socket_factory_.SetJobLoadState(0, LOAD_STATE_RESOLVING_HOST); |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 3097 | FastForwardBy( |
| 3098 | base::Milliseconds(ClientSocketPool::kMaxConnectRetryIntervalMs * 100)); |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 3099 | EXPECT_EQ(1, client_socket_factory_.allocation_count()); |
| 3100 | |
| 3101 | // Once the ConnectJob has finished resolving the hostname, the backup timer |
| 3102 | // will create a ConnectJob when it fires. |
| 3103 | client_socket_factory_.SetJobLoadState(0, LOAD_STATE_CONNECTING); |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 3104 | FastForwardBy( |
| 3105 | base::Milliseconds(ClientSocketPool::kMaxConnectRetryIntervalMs)); |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 3106 | EXPECT_EQ(2, client_socket_factory_.allocation_count()); |
| 3107 | } |
| 3108 | |
| 3109 | // Test that no backup socket is created when a ConnectJob connects before it |
| 3110 | // completes. |
| 3111 | TEST_F(ClientSocketPoolBaseTest, NoBackupSocketWhenConnected) { |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3112 | CreatePool(kDefaultMaxSockets, kDefaultMaxSockets, |
| 3113 | true /* enable_backup_connect_jobs */); |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 3114 | |
| 3115 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 3116 | ClientSocketHandle handle; |
| 3117 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3118 | EXPECT_EQ( |
| 3119 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3120 | handle.Init(TestGroupId("bar"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3121 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 3122 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3123 | pool_.get(), NetLogWithSource())); |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 3124 | // The backup timer fires but doesn't start a new ConnectJob while resolving |
| 3125 | // the hostname. |
| 3126 | client_socket_factory_.SetJobLoadState(0, LOAD_STATE_RESOLVING_HOST); |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 3127 | FastForwardBy( |
| 3128 | base::Milliseconds(ClientSocketPool::kMaxConnectRetryIntervalMs * 100)); |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 3129 | EXPECT_EQ(1, client_socket_factory_.allocation_count()); |
| 3130 | |
| 3131 | client_socket_factory_.SetJobLoadState(0, LOAD_STATE_SSL_HANDSHAKE); |
| 3132 | client_socket_factory_.SetJobHasEstablishedConnection(0); |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 3133 | FastForwardBy( |
| 3134 | base::Milliseconds(ClientSocketPool::kMaxConnectRetryIntervalMs * 100)); |
Matt Menke | 141b87f2 | 2019-01-30 02:43:03 | [diff] [blame] | 3135 | EXPECT_EQ(1, client_socket_factory_.allocation_count()); |
| 3136 | } |
| 3137 | |
[email protected] | 25eea38 | 2010-07-10 23:55:26 | [diff] [blame] | 3138 | // Cancel a pending socket request while we're at max sockets, |
| 3139 | // and verify that the backup socket firing doesn't cause a crash. |
| 3140 | TEST_F(ClientSocketPoolBaseTest, BackupSocketCancelAtMaxSockets) { |
| 3141 | // Max 4 sockets globally, max 4 sockets per group. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3142 | CreatePool(kDefaultMaxSockets, kDefaultMaxSockets, |
| 3143 | true /* enable_backup_connect_jobs */); |
[email protected] | 25eea38 | 2010-07-10 23:55:26 | [diff] [blame] | 3144 | |
[email protected] | 4baaf9d | 2010-08-31 15:15:44 | [diff] [blame] | 3145 | // Create the first socket and set to ERR_IO_PENDING. This starts the backup |
| 3146 | // timer. |
[email protected] | 25eea38 | 2010-07-10 23:55:26 | [diff] [blame] | 3147 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 3148 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3149 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3150 | EXPECT_EQ( |
| 3151 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3152 | handle.Init(TestGroupId("bar"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3153 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 3154 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3155 | pool_.get(), NetLogWithSource())); |
[email protected] | 25eea38 | 2010-07-10 23:55:26 | [diff] [blame] | 3156 | |
| 3157 | // Start (MaxSockets - 1) connected sockets to reach max sockets. |
| 3158 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 3159 | ClientSocketHandle handles[kDefaultMaxSockets]; |
| 3160 | for (int i = 1; i < kDefaultMaxSockets; ++i) { |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3161 | EXPECT_EQ(OK, handles[i].Init(TestGroupId("bar"), params_, absl::nullopt, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3162 | DEFAULT_PRIORITY, SocketTag(), |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3163 | ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3164 | callback.callback(), |
| 3165 | ClientSocketPool::ProxyAuthCallback(), |
| 3166 | pool_.get(), NetLogWithSource())); |
[email protected] | 25eea38 | 2010-07-10 23:55:26 | [diff] [blame] | 3167 | } |
| 3168 | |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 3169 | base::RunLoop().RunUntilIdle(); |
[email protected] | 25eea38 | 2010-07-10 23:55:26 | [diff] [blame] | 3170 | |
| 3171 | // Cancel the pending request. |
| 3172 | handle.Reset(); |
| 3173 | |
| 3174 | // 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] | 3175 | FastForwardBy( |
| 3176 | base::Milliseconds(ClientSocketPool::kMaxConnectRetryIntervalMs / 2 * 3)); |
[email protected] | 25eea38 | 2010-07-10 23:55:26 | [diff] [blame] | 3177 | |
[email protected] | 25eea38 | 2010-07-10 23:55:26 | [diff] [blame] | 3178 | EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count()); |
| 3179 | } |
| 3180 | |
[email protected] | 3f00be8 | 2010-09-27 19:50:02 | [diff] [blame] | 3181 | TEST_F(ClientSocketPoolBaseTest, CancelBackupSocketAfterCancelingAllRequests) { |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3182 | CreatePool(kDefaultMaxSockets, kDefaultMaxSockets, |
| 3183 | true /* enable_backup_connect_jobs */); |
[email protected] | 4baaf9d | 2010-08-31 15:15:44 | [diff] [blame] | 3184 | |
| 3185 | // Create the first socket and set to ERR_IO_PENDING. This starts the backup |
| 3186 | // timer. |
| 3187 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 3188 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3189 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3190 | EXPECT_EQ( |
| 3191 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3192 | handle.Init(TestGroupId("bar"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3193 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 3194 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3195 | pool_.get(), NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3196 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("bar"))); |
| 3197 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("bar"))); |
| 3198 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3199 | TestGroupId("bar"))); |
| 3200 | EXPECT_EQ( |
| 3201 | 0u, pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("bar"))); |
[email protected] | 4baaf9d | 2010-08-31 15:15:44 | [diff] [blame] | 3202 | |
| 3203 | // Cancel the socket request. This should cancel the backup timer. Wait for |
| 3204 | // the backup time to see if it indeed got canceled. |
| 3205 | handle.Reset(); |
| 3206 | // 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] | 3207 | FastForwardBy( |
| 3208 | base::Milliseconds(ClientSocketPool::kMaxConnectRetryIntervalMs / 2 * 3)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3209 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("bar"))); |
| 3210 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("bar"))); |
[email protected] | 4baaf9d | 2010-08-31 15:15:44 | [diff] [blame] | 3211 | } |
| 3212 | |
[email protected] | 3f00be8 | 2010-09-27 19:50:02 | [diff] [blame] | 3213 | TEST_F(ClientSocketPoolBaseTest, CancelBackupSocketAfterFinishingAllRequests) { |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3214 | CreatePool(kDefaultMaxSockets, kDefaultMaxSockets, |
| 3215 | true /* enable_backup_connect_jobs */); |
[email protected] | 3f00be8 | 2010-09-27 19:50:02 | [diff] [blame] | 3216 | |
| 3217 | // Create the first socket and set to ERR_IO_PENDING. This starts the backup |
| 3218 | // timer. |
| 3219 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 3220 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3221 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3222 | EXPECT_EQ( |
| 3223 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3224 | handle.Init(TestGroupId("bar"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3225 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 3226 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3227 | pool_.get(), NetLogWithSource())); |
[email protected] | 3f00be8 | 2010-09-27 19:50:02 | [diff] [blame] | 3228 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3229 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3230 | TestCompletionCallback callback2; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3231 | EXPECT_EQ( |
| 3232 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3233 | handle2.Init(TestGroupId("bar"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3234 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3235 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3236 | pool_.get(), NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3237 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("bar"))); |
| 3238 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("bar"))); |
[email protected] | 3f00be8 | 2010-09-27 19:50:02 | [diff] [blame] | 3239 | |
| 3240 | // Cancel request 1 and then complete request 2. With the requests finished, |
| 3241 | // the backup timer should be cancelled. |
| 3242 | handle.Reset(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3243 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 3f00be8 | 2010-09-27 19:50:02 | [diff] [blame] | 3244 | // 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] | 3245 | FastForwardBy( |
| 3246 | base::Milliseconds(ClientSocketPool::kMaxConnectRetryIntervalMs / 2 * 3)); |
[email protected] | 3f00be8 | 2010-09-27 19:50:02 | [diff] [blame] | 3247 | } |
| 3248 | |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3249 | // Test delayed socket binding for the case where we have two connects, |
| 3250 | // and while one is waiting on a connect, the other frees up. |
| 3251 | // The socket waiting on a connect should switch immediately to the freed |
| 3252 | // up socket. |
| 3253 | TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingWaitingForConnect) { |
| 3254 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 3255 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3256 | |
| 3257 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3258 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3259 | EXPECT_EQ( |
| 3260 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3261 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3262 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3263 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3264 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3265 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3266 | |
| 3267 | // No idle sockets, no pending jobs. |
| 3268 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3269 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3270 | |
| 3271 | // Create a second socket to the same host, but this one will wait. |
| 3272 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 3273 | ClientSocketHandle handle2; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3274 | EXPECT_EQ( |
| 3275 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3276 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3277 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3278 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3279 | pool_.get(), NetLogWithSource())); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3280 | // No idle sockets, and one connecting job. |
| 3281 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3282 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3283 | |
| 3284 | // Return the first handle to the pool. This will initiate the delayed |
| 3285 | // binding. |
| 3286 | handle1.Reset(); |
| 3287 | |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 3288 | base::RunLoop().RunUntilIdle(); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3289 | |
| 3290 | // Still no idle sockets, still one pending connect job. |
| 3291 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3292 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3293 | |
| 3294 | // The second socket connected, even though it was a Waiting Job. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3295 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3296 | |
| 3297 | // And we can see there is still one job waiting. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3298 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3299 | |
| 3300 | // Finally, signal the waiting Connect. |
| 3301 | client_socket_factory_.SignalJobs(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3302 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3303 | |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 3304 | base::RunLoop().RunUntilIdle(); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3305 | } |
| 3306 | |
| 3307 | // Test delayed socket binding when a group is at capacity and one |
| 3308 | // of the group's sockets frees up. |
| 3309 | TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingAtGroupCapacity) { |
| 3310 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 3311 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3312 | |
| 3313 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3314 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3315 | EXPECT_EQ( |
| 3316 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3317 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3318 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3319 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3320 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3321 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3322 | |
| 3323 | // No idle sockets, no pending jobs. |
| 3324 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3325 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3326 | |
| 3327 | // Create a second socket to the same host, but this one will wait. |
| 3328 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 3329 | ClientSocketHandle handle2; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3330 | EXPECT_EQ( |
| 3331 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3332 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3333 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3334 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3335 | pool_.get(), NetLogWithSource())); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3336 | // No idle sockets, and one connecting job. |
| 3337 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3338 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3339 | |
| 3340 | // Return the first handle to the pool. This will initiate the delayed |
| 3341 | // binding. |
| 3342 | handle1.Reset(); |
| 3343 | |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 3344 | base::RunLoop().RunUntilIdle(); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3345 | |
| 3346 | // Still no idle sockets, still one pending connect job. |
| 3347 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3348 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3349 | |
| 3350 | // The second socket connected, even though it was a Waiting Job. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3351 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3352 | |
| 3353 | // And we can see there is still one job waiting. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3354 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3355 | |
| 3356 | // Finally, signal the waiting Connect. |
| 3357 | client_socket_factory_.SignalJobs(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3358 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3359 | |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 3360 | base::RunLoop().RunUntilIdle(); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3361 | } |
| 3362 | |
| 3363 | // Test out the case where we have one socket connected, one |
| 3364 | // connecting, when the first socket finishes and goes idle. |
[email protected] | 2abfe90a | 2010-08-25 17:49:51 | [diff] [blame] | 3365 | // Although the second connection is pending, the second request |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3366 | // should complete, by taking the first socket's idle socket. |
| 3367 | TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingAtStall) { |
| 3368 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 3369 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3370 | |
| 3371 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3372 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3373 | EXPECT_EQ( |
| 3374 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3375 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3376 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3377 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3378 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3379 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3380 | |
| 3381 | // No idle sockets, no pending jobs. |
| 3382 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3383 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3384 | |
| 3385 | // Create a second socket to the same host, but this one will wait. |
| 3386 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 3387 | ClientSocketHandle handle2; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3388 | EXPECT_EQ( |
| 3389 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3390 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3391 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3392 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3393 | pool_.get(), NetLogWithSource())); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3394 | // No idle sockets, and one connecting job. |
| 3395 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3396 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3397 | |
| 3398 | // Return the first handle to the pool. This will initiate the delayed |
| 3399 | // binding. |
| 3400 | handle1.Reset(); |
| 3401 | |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 3402 | base::RunLoop().RunUntilIdle(); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3403 | |
| 3404 | // Still no idle sockets, still one pending connect job. |
| 3405 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3406 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3407 | |
| 3408 | // The second socket connected, even though it was a Waiting Job. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3409 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3410 | |
| 3411 | // And we can see there is still one job waiting. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3412 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3413 | |
| 3414 | // Finally, signal the waiting Connect. |
| 3415 | client_socket_factory_.SignalJobs(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3416 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3417 | |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 3418 | base::RunLoop().RunUntilIdle(); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 3419 | } |
| 3420 | |
[email protected] | 2abfe90a | 2010-08-25 17:49:51 | [diff] [blame] | 3421 | // Cover the case where on an available socket slot, we have one pending |
| 3422 | // request that completes synchronously, thereby making the Group empty. |
| 3423 | TEST_F(ClientSocketPoolBaseTest, SynchronouslyProcessOnePendingRequest) { |
| 3424 | const int kUnlimitedSockets = 100; |
| 3425 | const int kOneSocketPerGroup = 1; |
| 3426 | CreatePool(kUnlimitedSockets, kOneSocketPerGroup); |
| 3427 | |
| 3428 | // Make the first request asynchronous fail. |
| 3429 | // This will free up a socket slot later. |
| 3430 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); |
| 3431 | |
| 3432 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3433 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3434 | EXPECT_EQ( |
| 3435 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3436 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3437 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3438 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3439 | pool_.get(), NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3440 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | 2abfe90a | 2010-08-25 17:49:51 | [diff] [blame] | 3441 | |
| 3442 | // Make the second request synchronously fail. This should make the Group |
| 3443 | // empty. |
| 3444 | connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); |
| 3445 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3446 | TestCompletionCallback callback2; |
[email protected] | 2abfe90a | 2010-08-25 17:49:51 | [diff] [blame] | 3447 | // It'll be ERR_IO_PENDING now, but the TestConnectJob will synchronously fail |
| 3448 | // when created. |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3449 | EXPECT_EQ( |
| 3450 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3451 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3452 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3453 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3454 | pool_.get(), NetLogWithSource())); |
[email protected] | 2abfe90a | 2010-08-25 17:49:51 | [diff] [blame] | 3455 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3456 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | 2abfe90a | 2010-08-25 17:49:51 | [diff] [blame] | 3457 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3458 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
| 3459 | EXPECT_THAT(callback2.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3460 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
[email protected] | 2abfe90a | 2010-08-25 17:49:51 | [diff] [blame] | 3461 | } |
| 3462 | |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 3463 | TEST_F(ClientSocketPoolBaseTest, PreferUsedSocketToUnusedSocket) { |
| 3464 | CreatePool(kDefaultMaxSockets, kDefaultMaxSockets); |
| 3465 | |
| 3466 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3467 | |
| 3468 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3469 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3470 | EXPECT_EQ( |
| 3471 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3472 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3473 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3474 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3475 | pool_.get(), NetLogWithSource())); |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 3476 | |
| 3477 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3478 | TestCompletionCallback callback2; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3479 | EXPECT_EQ( |
| 3480 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3481 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3482 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3483 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3484 | pool_.get(), NetLogWithSource())); |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 3485 | ClientSocketHandle handle3; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3486 | TestCompletionCallback callback3; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3487 | EXPECT_EQ( |
| 3488 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3489 | handle3.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3490 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3491 | callback3.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3492 | pool_.get(), NetLogWithSource())); |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 3493 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3494 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 3495 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 3496 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 3497 | |
| 3498 | // Use the socket. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 3499 | EXPECT_EQ(1, handle1.socket()->Write(nullptr, 1, CompletionOnceCallback(), |
Ramin Halavati | 0a08cc8 | 2018-02-06 07:46:38 | [diff] [blame] | 3500 | TRAFFIC_ANNOTATION_FOR_TESTS)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 3501 | EXPECT_EQ(1, handle3.socket()->Write(nullptr, 1, CompletionOnceCallback(), |
Ramin Halavati | 0a08cc8 | 2018-02-06 07:46:38 | [diff] [blame] | 3502 | TRAFFIC_ANNOTATION_FOR_TESTS)); |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 3503 | |
| 3504 | handle1.Reset(); |
| 3505 | handle2.Reset(); |
| 3506 | handle3.Reset(); |
| 3507 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3508 | EXPECT_EQ(OK, handle1.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3509 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3510 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3511 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3512 | pool_.get(), NetLogWithSource())); |
| 3513 | EXPECT_EQ(OK, handle2.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3514 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3515 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3516 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3517 | pool_.get(), NetLogWithSource())); |
| 3518 | EXPECT_EQ(OK, handle3.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3519 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3520 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3521 | callback3.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3522 | pool_.get(), NetLogWithSource())); |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 3523 | |
| 3524 | EXPECT_TRUE(handle1.socket()->WasEverUsed()); |
| 3525 | EXPECT_TRUE(handle2.socket()->WasEverUsed()); |
| 3526 | EXPECT_FALSE(handle3.socket()->WasEverUsed()); |
| 3527 | } |
| 3528 | |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3529 | TEST_F(ClientSocketPoolBaseTest, RequestSockets) { |
| 3530 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 3531 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3532 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3533 | TestCompletionCallback preconnect_callback; |
| 3534 | EXPECT_EQ(ERR_IO_PENDING, |
| 3535 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 3536 | preconnect_callback.callback(), |
| 3537 | NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3538 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3539 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 3540 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3541 | EXPECT_EQ(2u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3542 | TestGroupId("a"))); |
| 3543 | EXPECT_EQ(2u, |
| 3544 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3545 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3546 | |
| 3547 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3548 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3549 | EXPECT_EQ( |
| 3550 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3551 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3552 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3553 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3554 | pool_.get(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3555 | |
| 3556 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3557 | TestCompletionCallback callback2; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3558 | EXPECT_EQ( |
| 3559 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3560 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3561 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3562 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3563 | pool_.get(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3564 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3565 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3566 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3567 | TestGroupId("a"))); |
| 3568 | EXPECT_EQ(0u, |
| 3569 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3570 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3571 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3572 | EXPECT_THAT(preconnect_callback.WaitForResult(), IsOk()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3573 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 3574 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3575 | handle1.Reset(); |
| 3576 | handle2.Reset(); |
| 3577 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3578 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3579 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3580 | TestGroupId("a"))); |
| 3581 | EXPECT_EQ(0u, |
| 3582 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3583 | EXPECT_EQ(2u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3584 | } |
| 3585 | |
| 3586 | TEST_F(ClientSocketPoolBaseTest, RequestSocketsWhenAlreadyHaveAConnectJob) { |
| 3587 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 3588 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3589 | |
| 3590 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3591 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3592 | EXPECT_EQ( |
| 3593 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3594 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3595 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3596 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3597 | pool_.get(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3598 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3599 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 3600 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3601 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3602 | TestGroupId("a"))); |
| 3603 | EXPECT_EQ(0u, |
| 3604 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3605 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3606 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3607 | TestCompletionCallback preconnect_callback; |
| 3608 | EXPECT_EQ(ERR_IO_PENDING, |
| 3609 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 3610 | preconnect_callback.callback(), |
| 3611 | NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3612 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3613 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3614 | EXPECT_EQ(1u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3615 | TestGroupId("a"))); |
| 3616 | EXPECT_EQ(1u, |
| 3617 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3618 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3619 | |
| 3620 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3621 | TestCompletionCallback callback2; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3622 | EXPECT_EQ( |
| 3623 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3624 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3625 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3626 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3627 | pool_.get(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3628 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3629 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3630 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3631 | TestGroupId("a"))); |
| 3632 | EXPECT_EQ(0u, |
| 3633 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3634 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3635 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3636 | EXPECT_THAT(preconnect_callback.WaitForResult(), IsOk()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3637 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 3638 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3639 | handle1.Reset(); |
| 3640 | handle2.Reset(); |
| 3641 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3642 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3643 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3644 | TestGroupId("a"))); |
| 3645 | EXPECT_EQ(0u, |
| 3646 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3647 | EXPECT_EQ(2u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3648 | } |
| 3649 | |
| 3650 | TEST_F(ClientSocketPoolBaseTest, |
| 3651 | RequestSocketsWhenAlreadyHaveMultipleConnectJob) { |
| 3652 | CreatePool(4, 4); |
| 3653 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3654 | |
| 3655 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3656 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3657 | EXPECT_EQ( |
| 3658 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3659 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3660 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3661 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3662 | pool_.get(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3663 | |
| 3664 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3665 | TestCompletionCallback callback2; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3666 | EXPECT_EQ( |
| 3667 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3668 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3669 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3670 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3671 | pool_.get(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3672 | |
| 3673 | ClientSocketHandle handle3; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3674 | TestCompletionCallback callback3; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3675 | EXPECT_EQ( |
| 3676 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3677 | handle3.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3678 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3679 | callback3.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3680 | pool_.get(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3681 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3682 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 3683 | EXPECT_EQ(3u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3684 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3685 | TestGroupId("a"))); |
| 3686 | EXPECT_EQ(0u, |
| 3687 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3688 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3689 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3690 | EXPECT_EQ( |
| 3691 | OK, pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 3692 | CompletionOnceCallback(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3693 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3694 | EXPECT_EQ(3u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3695 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3696 | TestGroupId("a"))); |
| 3697 | EXPECT_EQ(0u, |
| 3698 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3699 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3700 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3701 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 3702 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 3703 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3704 | handle1.Reset(); |
| 3705 | handle2.Reset(); |
| 3706 | handle3.Reset(); |
| 3707 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3708 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3709 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3710 | TestGroupId("a"))); |
| 3711 | EXPECT_EQ(0u, |
| 3712 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3713 | EXPECT_EQ(3u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3714 | } |
| 3715 | |
| 3716 | TEST_F(ClientSocketPoolBaseTest, RequestSocketsAtMaxSocketLimit) { |
| 3717 | CreatePool(kDefaultMaxSockets, kDefaultMaxSockets); |
| 3718 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3719 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3720 | ASSERT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3721 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3722 | TestCompletionCallback preconnect_callback; |
| 3723 | EXPECT_EQ(ERR_IO_PENDING, |
| 3724 | pool_->RequestSockets( |
| 3725 | TestGroupId("a"), params_, absl::nullopt, kDefaultMaxSockets, |
| 3726 | preconnect_callback.callback(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3727 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3728 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 3729 | EXPECT_EQ(kDefaultMaxSockets, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3730 | static_cast<int>( |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3731 | pool_->NumConnectJobsInGroupForTesting(TestGroupId("a")))); |
| 3732 | EXPECT_EQ( |
| 3733 | kDefaultMaxSockets, |
| 3734 | static_cast<int>(pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3735 | TestGroupId("a")))); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 3736 | EXPECT_EQ(kDefaultMaxSockets, |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3737 | static_cast<int>(pool_->NumUnassignedConnectJobsInGroupForTesting( |
| 3738 | TestGroupId("a")))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3739 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3740 | ASSERT_FALSE(pool_->HasGroupForTesting(TestGroupId("b"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3741 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3742 | EXPECT_EQ(OK, |
| 3743 | pool_->RequestSockets(TestGroupId("b"), params_, absl::nullopt, |
| 3744 | kDefaultMaxSockets, CompletionOnceCallback(), |
| 3745 | NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3746 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3747 | ASSERT_FALSE(pool_->HasGroupForTesting(TestGroupId("b"))); |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3748 | |
| 3749 | EXPECT_THAT(preconnect_callback.WaitForResult(), IsOk()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3750 | } |
| 3751 | |
| 3752 | TEST_F(ClientSocketPoolBaseTest, RequestSocketsHitMaxSocketLimit) { |
| 3753 | CreatePool(kDefaultMaxSockets, kDefaultMaxSockets); |
| 3754 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3755 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3756 | ASSERT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3757 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3758 | TestCompletionCallback preconnect_callback1; |
| 3759 | EXPECT_EQ(ERR_IO_PENDING, |
| 3760 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, |
| 3761 | kDefaultMaxSockets - 1, |
| 3762 | preconnect_callback1.callback(), |
| 3763 | NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3764 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3765 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 3766 | EXPECT_EQ(kDefaultMaxSockets - 1, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3767 | static_cast<int>( |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3768 | pool_->NumConnectJobsInGroupForTesting(TestGroupId("a")))); |
| 3769 | EXPECT_EQ( |
| 3770 | kDefaultMaxSockets - 1, |
| 3771 | static_cast<int>(pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3772 | TestGroupId("a")))); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 3773 | EXPECT_EQ(kDefaultMaxSockets - 1, |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3774 | static_cast<int>(pool_->NumUnassignedConnectJobsInGroupForTesting( |
| 3775 | TestGroupId("a")))); |
[email protected] | 51fdc7c | 2012-04-10 19:19:48 | [diff] [blame] | 3776 | EXPECT_FALSE(pool_->IsStalled()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3777 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3778 | ASSERT_FALSE(pool_->HasGroupForTesting(TestGroupId("b"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3779 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3780 | TestCompletionCallback preconnect_callback2; |
| 3781 | EXPECT_EQ(ERR_IO_PENDING, |
| 3782 | pool_->RequestSockets( |
| 3783 | TestGroupId("b"), params_, absl::nullopt, kDefaultMaxSockets, |
| 3784 | preconnect_callback2.callback(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3785 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3786 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("b"))); |
| 3787 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("b"))); |
[email protected] | 51fdc7c | 2012-04-10 19:19:48 | [diff] [blame] | 3788 | EXPECT_FALSE(pool_->IsStalled()); |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3789 | |
| 3790 | EXPECT_THAT(preconnect_callback1.WaitForResult(), IsOk()); |
| 3791 | EXPECT_THAT(preconnect_callback2.WaitForResult(), IsOk()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3792 | } |
| 3793 | |
| 3794 | TEST_F(ClientSocketPoolBaseTest, RequestSocketsCountIdleSockets) { |
| 3795 | CreatePool(4, 4); |
| 3796 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3797 | |
| 3798 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3799 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3800 | EXPECT_EQ( |
| 3801 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3802 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3803 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3804 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3805 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3806 | ASSERT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3807 | handle1.Reset(); |
| 3808 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3809 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 3810 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3811 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3812 | TestGroupId("a"))); |
| 3813 | EXPECT_EQ(0u, |
| 3814 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3815 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3816 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3817 | TestCompletionCallback preconnect_callback; |
| 3818 | EXPECT_EQ(ERR_IO_PENDING, |
| 3819 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 3820 | preconnect_callback.callback(), |
| 3821 | NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3822 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3823 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3824 | EXPECT_EQ(1u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3825 | TestGroupId("a"))); |
| 3826 | EXPECT_EQ(1u, |
| 3827 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3828 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3829 | |
| 3830 | EXPECT_THAT(preconnect_callback.WaitForResult(), IsOk()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3831 | } |
| 3832 | |
| 3833 | TEST_F(ClientSocketPoolBaseTest, RequestSocketsCountActiveSockets) { |
| 3834 | CreatePool(4, 4); |
| 3835 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3836 | |
| 3837 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3838 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3839 | EXPECT_EQ( |
| 3840 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3841 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3842 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3843 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3844 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3845 | ASSERT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3846 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3847 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 3848 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3849 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3850 | TestGroupId("a"))); |
| 3851 | EXPECT_EQ(0u, |
| 3852 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3853 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3854 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3855 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3856 | TestCompletionCallback preconnect_callback; |
| 3857 | EXPECT_EQ(ERR_IO_PENDING, |
| 3858 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 3859 | preconnect_callback.callback(), |
| 3860 | NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3861 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3862 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3863 | EXPECT_EQ(1u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3864 | TestGroupId("a"))); |
| 3865 | EXPECT_EQ(1u, |
| 3866 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3867 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3868 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3869 | |
| 3870 | EXPECT_THAT(preconnect_callback.WaitForResult(), IsOk()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3871 | } |
| 3872 | |
| 3873 | TEST_F(ClientSocketPoolBaseTest, RequestSocketsSynchronous) { |
| 3874 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 3875 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 3876 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3877 | EXPECT_EQ( |
| 3878 | OK, pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, |
| 3879 | kDefaultMaxSocketsPerGroup, |
| 3880 | CompletionOnceCallback(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3881 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3882 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 3883 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3884 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3885 | TestGroupId("a"))); |
| 3886 | EXPECT_EQ(0u, |
| 3887 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 3888 | EXPECT_EQ(kDefaultMaxSocketsPerGroup, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3889 | static_cast<int>(pool_->IdleSocketCountInGroup(TestGroupId("a")))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3890 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3891 | EXPECT_EQ( |
| 3892 | OK, pool_->RequestSockets(TestGroupId("b"), params_, absl::nullopt, |
| 3893 | kDefaultMaxSocketsPerGroup, |
| 3894 | CompletionOnceCallback(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3895 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3896 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("b"))); |
| 3897 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3898 | TestGroupId("b"))); |
| 3899 | EXPECT_EQ(0u, |
| 3900 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("b"))); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 3901 | EXPECT_EQ(kDefaultMaxSocketsPerGroup, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3902 | static_cast<int>(pool_->IdleSocketCountInGroup(TestGroupId("b")))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3903 | } |
| 3904 | |
[email protected] | 3c819f52 | 2010-12-02 02:03:12 | [diff] [blame] | 3905 | TEST_F(ClientSocketPoolBaseTest, RequestSocketsSynchronousError) { |
| 3906 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 3907 | connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); |
| 3908 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3909 | EXPECT_EQ( |
| 3910 | OK, pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, |
| 3911 | kDefaultMaxSocketsPerGroup, |
| 3912 | CompletionOnceCallback(), NetLogWithSource())); |
[email protected] | 3c819f52 | 2010-12-02 02:03:12 | [diff] [blame] | 3913 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3914 | ASSERT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
[email protected] | fd2e53e | 2011-01-14 20:40:52 | [diff] [blame] | 3915 | |
| 3916 | connect_job_factory_->set_job_type( |
| 3917 | TestConnectJob::kMockAdditionalErrorStateJob); |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3918 | |
| 3919 | EXPECT_EQ( |
| 3920 | OK, pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, |
| 3921 | kDefaultMaxSocketsPerGroup, |
| 3922 | CompletionOnceCallback(), NetLogWithSource())); |
[email protected] | fd2e53e | 2011-01-14 20:40:52 | [diff] [blame] | 3923 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3924 | ASSERT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
[email protected] | 3c819f52 | 2010-12-02 02:03:12 | [diff] [blame] | 3925 | } |
| 3926 | |
[email protected] | 8159a1c | 2012-06-07 00:00:10 | [diff] [blame] | 3927 | TEST_F(ClientSocketPoolBaseTest, RequestSocketsMultipleTimesDoesNothing) { |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3928 | CreatePool(4, 4); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 3929 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3930 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3931 | TestCompletionCallback preconnect_callback; |
| 3932 | EXPECT_EQ(ERR_IO_PENDING, |
| 3933 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 3934 | preconnect_callback.callback(), |
| 3935 | NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3936 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3937 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 3938 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3939 | EXPECT_EQ(2u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3940 | TestGroupId("a"))); |
| 3941 | EXPECT_EQ(2u, |
| 3942 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3943 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3944 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3945 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3946 | EXPECT_EQ( |
| 3947 | OK, pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 3948 | CompletionOnceCallback(), NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3949 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3950 | EXPECT_EQ(2u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3951 | TestGroupId("a"))); |
| 3952 | EXPECT_EQ(2u, |
| 3953 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3954 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3955 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3956 | |
| 3957 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3958 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3959 | EXPECT_EQ( |
| 3960 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3961 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3962 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3963 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3964 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 3965 | |
| 3966 | client_socket_factory_.SignalJob(0); |
| 3967 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 3968 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3969 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3970 | EXPECT_EQ(1u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3971 | TestGroupId("a"))); |
| 3972 | EXPECT_EQ(1u, |
| 3973 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3974 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3975 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3976 | |
| 3977 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 3978 | TestCompletionCallback callback2; |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 3979 | EXPECT_EQ( |
| 3980 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 3981 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 3982 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 3983 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 3984 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 3985 | client_socket_factory_.SignalJob(0); |
| 3986 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 3987 | EXPECT_THAT(preconnect_callback.WaitForResult(), IsOk()); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3988 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 3989 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3990 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 3991 | TestGroupId("a"))); |
| 3992 | EXPECT_EQ(0u, |
| 3993 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 3994 | EXPECT_EQ(2, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 3995 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 8159a1c | 2012-06-07 00:00:10 | [diff] [blame] | 3996 | |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 3997 | handle1.Reset(); |
| 3998 | handle2.Reset(); |
| 3999 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4000 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4001 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4002 | TestGroupId("a"))); |
| 4003 | EXPECT_EQ(0u, |
| 4004 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4005 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4006 | EXPECT_EQ(2u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4007 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 4008 | EXPECT_EQ( |
| 4009 | OK, pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 4010 | CompletionOnceCallback(), NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4011 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4012 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4013 | TestGroupId("a"))); |
| 4014 | EXPECT_EQ(0u, |
| 4015 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4016 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4017 | EXPECT_EQ(2u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4018 | } |
| 4019 | |
| 4020 | TEST_F(ClientSocketPoolBaseTest, RequestSocketsDifferentNumSockets) { |
| 4021 | CreatePool(4, 4); |
| 4022 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 4023 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 4024 | TestCompletionCallback preconnect_callback1; |
| 4025 | EXPECT_EQ(ERR_IO_PENDING, |
| 4026 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 1, |
| 4027 | preconnect_callback1.callback(), |
| 4028 | NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4029 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4030 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 4031 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4032 | EXPECT_EQ(1u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4033 | TestGroupId("a"))); |
| 4034 | EXPECT_EQ(1u, |
| 4035 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4036 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4037 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 4038 | TestCompletionCallback preconnect_callback2; |
| 4039 | EXPECT_EQ(ERR_IO_PENDING, |
| 4040 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 4041 | preconnect_callback2.callback(), |
| 4042 | NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4043 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4044 | EXPECT_EQ(2u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4045 | TestGroupId("a"))); |
| 4046 | EXPECT_EQ(2u, |
| 4047 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4048 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4049 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 4050 | TestCompletionCallback preconnect_callback3; |
| 4051 | EXPECT_EQ(ERR_IO_PENDING, |
| 4052 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 3, |
| 4053 | preconnect_callback3.callback(), |
| 4054 | NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4055 | EXPECT_EQ(3u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4056 | EXPECT_EQ(3u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4057 | TestGroupId("a"))); |
| 4058 | EXPECT_EQ(3u, |
| 4059 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4060 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4061 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 4062 | EXPECT_EQ( |
| 4063 | OK, pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 1, |
| 4064 | CompletionOnceCallback(), NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4065 | EXPECT_EQ(3u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4066 | EXPECT_EQ(3u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4067 | TestGroupId("a"))); |
| 4068 | EXPECT_EQ(3u, |
| 4069 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4070 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4071 | } |
| 4072 | |
| 4073 | TEST_F(ClientSocketPoolBaseTest, PreconnectJobsTakenByNormalRequests) { |
| 4074 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4075 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4076 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 4077 | TestCompletionCallback preconnect_callback; |
| 4078 | EXPECT_EQ(ERR_IO_PENDING, |
| 4079 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 1, |
| 4080 | preconnect_callback.callback(), |
| 4081 | NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4082 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4083 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 4084 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4085 | EXPECT_EQ(1u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4086 | TestGroupId("a"))); |
| 4087 | EXPECT_EQ(1u, |
| 4088 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4089 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4090 | |
| 4091 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 4092 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 4093 | EXPECT_EQ( |
| 4094 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4095 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4096 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4097 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4098 | pool_.get(), NetLogWithSource())); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4099 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4100 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4101 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4102 | TestGroupId("a"))); |
| 4103 | EXPECT_EQ(0u, |
| 4104 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4105 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4106 | |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4107 | client_socket_factory_.SignalJobs(); |
| 4108 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 4109 | EXPECT_THAT(preconnect_callback.WaitForResult(), IsOk()); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4110 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4111 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4112 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4113 | TestGroupId("a"))); |
| 4114 | EXPECT_EQ(0u, |
| 4115 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4116 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4117 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4118 | |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 4119 | // Make sure if a preconnected socket is not fully connected when a request |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 4120 | // starts, it has a connect start time. |
| 4121 | TestLoadTimingInfoConnectedNotReused(handle1); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4122 | handle1.Reset(); |
| 4123 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4124 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 4125 | } |
| 4126 | |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 4127 | // Checks that fully connected preconnect jobs have no connect times, and are |
| 4128 | // marked as reused. |
| 4129 | TEST_F(ClientSocketPoolBaseTest, ConnectedPreconnectJobsHaveNoConnectTimes) { |
| 4130 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 4131 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 4132 | |
| 4133 | EXPECT_EQ( |
| 4134 | OK, pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 1, |
| 4135 | CompletionOnceCallback(), NetLogWithSource())); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 4136 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4137 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 4138 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4139 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4140 | TestGroupId("a"))); |
| 4141 | EXPECT_EQ(0u, |
| 4142 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4143 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 4144 | |
| 4145 | ClientSocketHandle handle; |
| 4146 | TestCompletionCallback callback; |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4147 | EXPECT_EQ(OK, handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4148 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4149 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4150 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4151 | pool_.get(), NetLogWithSource())); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 4152 | |
| 4153 | // Make sure the idle socket was used. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4154 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 034df0f3 | 2013-01-07 23:17:48 | [diff] [blame] | 4155 | |
| 4156 | TestLoadTimingInfoConnectedReused(handle); |
| 4157 | handle.Reset(); |
| 4158 | TestLoadTimingInfoNotConnected(handle); |
| 4159 | } |
| 4160 | |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4161 | // http://crbug.com/64940 regression test. |
| 4162 | TEST_F(ClientSocketPoolBaseTest, PreconnectClosesIdleSocketRemovesGroup) { |
| 4163 | const int kMaxTotalSockets = 3; |
| 4164 | const int kMaxSocketsPerGroup = 2; |
| 4165 | CreatePool(kMaxTotalSockets, kMaxSocketsPerGroup); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4166 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4167 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 4168 | // Note that group id ordering matters here. "a" comes before "b", so |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4169 | // CloseOneIdleSocket() will try to close "a"'s idle socket. |
| 4170 | |
| 4171 | // Set up one idle socket in "a". |
| 4172 | ClientSocketHandle handle1; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 4173 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 4174 | EXPECT_EQ( |
| 4175 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4176 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4177 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4178 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4179 | pool_.get(), NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4180 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 4181 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4182 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4183 | TestGroupId("a"))); |
| 4184 | EXPECT_EQ(0u, |
| 4185 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4186 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4187 | |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4188 | client_socket_factory_.SignalJobs(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4189 | ASSERT_THAT(callback1.WaitForResult(), IsOk()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4190 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4191 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4192 | TestGroupId("a"))); |
| 4193 | EXPECT_EQ(0u, |
| 4194 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4195 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4196 | |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4197 | handle1.Reset(); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4198 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4199 | |
| 4200 | // Set up two active sockets in "b". |
| 4201 | ClientSocketHandle handle2; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 4202 | TestCompletionCallback callback2; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 4203 | EXPECT_EQ( |
| 4204 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4205 | handle1.Init(TestGroupId("b"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4206 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4207 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4208 | pool_.get(), NetLogWithSource())); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 4209 | EXPECT_EQ( |
| 4210 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4211 | handle2.Init(TestGroupId("b"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4212 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4213 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4214 | pool_.get(), NetLogWithSource())); |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4215 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4216 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("b"))); |
| 4217 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("b"))); |
| 4218 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4219 | TestGroupId("b"))); |
| 4220 | EXPECT_EQ(0u, |
| 4221 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("b"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4222 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("b"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4223 | |
| 4224 | client_socket_factory_.SignalJobs(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4225 | ASSERT_THAT(callback1.WaitForResult(), IsOk()); |
| 4226 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4227 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("b"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4228 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4229 | TestGroupId("b"))); |
| 4230 | EXPECT_EQ(0u, |
| 4231 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("b"))); |
| 4232 | EXPECT_EQ(2, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("b"))); |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4233 | |
| 4234 | // Now we have 1 idle socket in "a" and 2 active sockets in "b". This means |
| 4235 | // we've maxed out on sockets, since we set |kMaxTotalSockets| to 3. |
| 4236 | // Requesting 2 preconnected sockets for "a" should fail to allocate any more |
| 4237 | // sockets for "a", and "b" should still have 2 active sockets. |
| 4238 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 4239 | EXPECT_EQ( |
| 4240 | OK, pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 4241 | CompletionOnceCallback(), NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4242 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4243 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4244 | TestGroupId("a"))); |
| 4245 | EXPECT_EQ(0u, |
| 4246 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4247 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4248 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
| 4249 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("b"))); |
| 4250 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4251 | TestGroupId("b"))); |
| 4252 | EXPECT_EQ(0u, |
| 4253 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("b"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4254 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("b"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4255 | EXPECT_EQ(2, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("b"))); |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4256 | |
| 4257 | // Now release the 2 active sockets for "b". This will give us 1 idle socket |
| 4258 | // in "a" and 2 idle sockets in "b". Requesting 2 preconnected sockets for |
| 4259 | // "a" should result in closing 1 for "b". |
| 4260 | handle1.Reset(); |
| 4261 | handle2.Reset(); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4262 | EXPECT_EQ(2u, pool_->IdleSocketCountInGroup(TestGroupId("b"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4263 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("b"))); |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4264 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 4265 | TestCompletionCallback preconnect_callback; |
| 4266 | EXPECT_EQ(ERR_IO_PENDING, |
| 4267 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 2, |
| 4268 | preconnect_callback.callback(), |
| 4269 | NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4270 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4271 | EXPECT_EQ(1u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4272 | TestGroupId("a"))); |
| 4273 | EXPECT_EQ(1u, |
| 4274 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4275 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4276 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
| 4277 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("b"))); |
| 4278 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4279 | TestGroupId("b"))); |
| 4280 | EXPECT_EQ(0u, |
| 4281 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("b"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4282 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(TestGroupId("b"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4283 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("b"))); |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 4284 | } |
| 4285 | |
[email protected] | b7b8be4 | 2011-07-12 12:46:41 | [diff] [blame] | 4286 | TEST_F(ClientSocketPoolBaseTest, PreconnectWithoutBackupJob) { |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4287 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, |
| 4288 | true /* enable_backup_connect_jobs */); |
[email protected] | a9fc8fc | 2011-05-10 02:41:07 | [diff] [blame] | 4289 | |
| 4290 | // Make the ConnectJob hang until it times out, shorten the timeout. |
| 4291 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 4292 | connect_job_factory_->set_timeout_duration(base::Milliseconds(500)); |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 4293 | TestCompletionCallback preconnect_callback; |
| 4294 | EXPECT_EQ(ERR_IO_PENDING, |
| 4295 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 1, |
| 4296 | preconnect_callback.callback(), |
| 4297 | NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4298 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4299 | EXPECT_EQ(1u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4300 | TestGroupId("a"))); |
| 4301 | EXPECT_EQ(1u, |
| 4302 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4303 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | a9fc8fc | 2011-05-10 02:41:07 | [diff] [blame] | 4304 | |
[email protected] | b7b8be4 | 2011-07-12 12:46:41 | [diff] [blame] | 4305 | // Verify the backup timer doesn't create a backup job, by making |
| 4306 | // the backup job a pending job instead of a waiting job, so it |
| 4307 | // *would* complete if it were created. |
Lukasz Krakowiak | 28dcf9d6 | 2020-06-04 09:46:59 | [diff] [blame] | 4308 | base::RunLoop loop; |
[email protected] | a9fc8fc | 2011-05-10 02:41:07 | [diff] [blame] | 4309 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 4310 | base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 4311 | FROM_HERE, loop.QuitClosure(), base::Seconds(1)); |
Lukasz Krakowiak | 28dcf9d6 | 2020-06-04 09:46:59 | [diff] [blame] | 4312 | loop.Run(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4313 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
[email protected] | a9fc8fc | 2011-05-10 02:41:07 | [diff] [blame] | 4314 | } |
| 4315 | |
[email protected] | b7b8be4 | 2011-07-12 12:46:41 | [diff] [blame] | 4316 | TEST_F(ClientSocketPoolBaseTest, PreconnectWithBackupJob) { |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4317 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, |
| 4318 | true /* enable_backup_connect_jobs */); |
[email protected] | a9fc8fc | 2011-05-10 02:41:07 | [diff] [blame] | 4319 | |
| 4320 | // Make the ConnectJob hang forever. |
| 4321 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 4322 | TestCompletionCallback preconnect_callback; |
| 4323 | EXPECT_EQ(ERR_IO_PENDING, |
| 4324 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 1, |
| 4325 | preconnect_callback.callback(), |
| 4326 | NetLogWithSource())); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4327 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4328 | EXPECT_EQ(1u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4329 | TestGroupId("a"))); |
| 4330 | EXPECT_EQ(1u, |
| 4331 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4332 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
fdoray | 5eeb764 | 2016-06-22 16:11:28 | [diff] [blame] | 4333 | base::RunLoop().RunUntilIdle(); |
[email protected] | a9fc8fc | 2011-05-10 02:41:07 | [diff] [blame] | 4334 | |
| 4335 | // Make the backup job be a pending job, so it completes normally. |
| 4336 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 4337 | ClientSocketHandle handle; |
[email protected] | 6ecf2b9 | 2011-12-15 01:14:52 | [diff] [blame] | 4338 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4339 | EXPECT_EQ( |
| 4340 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4341 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4342 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 4343 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4344 | pool_.get(), NetLogWithSource())); |
[email protected] | b7b8be4 | 2011-07-12 12:46:41 | [diff] [blame] | 4345 | // Timer has started, but the backup connect job shouldn't be created yet. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4346 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4347 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4348 | TestGroupId("a"))); |
| 4349 | EXPECT_EQ(0u, |
| 4350 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4351 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4352 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4353 | ASSERT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | a9fc8fc | 2011-05-10 02:41:07 | [diff] [blame] | 4354 | |
| 4355 | // The hung connect job should still be there, but everything else should be |
| 4356 | // complete. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4357 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4358 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4359 | TestGroupId("a"))); |
| 4360 | EXPECT_EQ(1u, |
| 4361 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4362 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4363 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
[email protected] | a9fc8fc | 2011-05-10 02:41:07 | [diff] [blame] | 4364 | } |
| 4365 | |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 4366 | // Tests that a preconnect that starts out with unread data can still be used. |
| 4367 | // http://crbug.com/334467 |
| 4368 | TEST_F(ClientSocketPoolBaseTest, PreconnectWithUnreadData) { |
| 4369 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 4370 | connect_job_factory_->set_job_type(TestConnectJob::kMockUnreadDataJob); |
| 4371 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 4372 | EXPECT_EQ( |
| 4373 | OK, pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 1, |
| 4374 | CompletionOnceCallback(), NetLogWithSource())); |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 4375 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4376 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 4377 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4378 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4379 | TestGroupId("a"))); |
| 4380 | EXPECT_EQ(0u, |
| 4381 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4382 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 4383 | |
| 4384 | // Fail future jobs to be sure that handle receives the preconnected socket |
| 4385 | // rather than closing it and making a new one. |
| 4386 | connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); |
| 4387 | ClientSocketHandle handle; |
| 4388 | TestCompletionCallback callback; |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4389 | EXPECT_EQ(OK, handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4390 | TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4391 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4392 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4393 | pool_.get(), NetLogWithSource())); |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 4394 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4395 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 4396 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4397 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4398 | TestGroupId("a"))); |
| 4399 | EXPECT_EQ(0u, |
| 4400 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4401 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4402 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 4403 | |
| 4404 | // Drain the pending read. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 4405 | EXPECT_EQ(1, handle.socket()->Read(nullptr, 1, CompletionOnceCallback())); |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 4406 | |
| 4407 | TestLoadTimingInfoConnectedReused(handle); |
| 4408 | handle.Reset(); |
| 4409 | |
| 4410 | // The socket should be usable now that it's idle again. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4411 | EXPECT_EQ(1u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 4412 | } |
| 4413 | |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4414 | TEST_F(ClientSocketPoolBaseTest, RequestGetsAssignedJob) { |
| 4415 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 4416 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 4417 | |
| 4418 | ClientSocketHandle handle1; |
| 4419 | TestCompletionCallback callback1; |
| 4420 | EXPECT_EQ( |
| 4421 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4422 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4423 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4424 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4425 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4426 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4427 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4428 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4429 | TestGroupId("a"))); |
| 4430 | EXPECT_EQ(0u, |
| 4431 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4432 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4433 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4434 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4435 | &handle1)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4436 | } |
| 4437 | |
| 4438 | TEST_F(ClientSocketPoolBaseTest, MultipleRequestsGetAssignedJobs) { |
| 4439 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 4440 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 4441 | |
| 4442 | ClientSocketHandle handle1; |
| 4443 | TestCompletionCallback callback1; |
| 4444 | EXPECT_EQ( |
| 4445 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4446 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4447 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4448 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4449 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4450 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4451 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4452 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4453 | TestGroupId("a"))); |
| 4454 | EXPECT_EQ(0u, |
| 4455 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4456 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4457 | |
| 4458 | ClientSocketHandle handle2; |
| 4459 | TestCompletionCallback callback2; |
| 4460 | EXPECT_EQ( |
| 4461 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4462 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4463 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4464 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4465 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4466 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4467 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4468 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4469 | TestGroupId("a"))); |
| 4470 | EXPECT_EQ(0u, |
| 4471 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4472 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4473 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4474 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4475 | &handle1)); |
| 4476 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4477 | &handle2)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4478 | |
| 4479 | // One job completes. The other request should still have its job. |
| 4480 | client_socket_factory_.SignalJob(0); |
| 4481 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 4482 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4483 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4484 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4485 | TestGroupId("a"))); |
| 4486 | EXPECT_EQ(0u, |
| 4487 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4488 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4489 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4490 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4491 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4492 | &handle2)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4493 | } |
| 4494 | |
| 4495 | TEST_F(ClientSocketPoolBaseTest, PreconnectJobGetsAssignedToRequest) { |
| 4496 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 4497 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 4498 | |
Tsuyoshi Horo | 1d8eb53f | 2022-06-02 07:12:21 | [diff] [blame^] | 4499 | TestCompletionCallback preconnect_callback; |
| 4500 | EXPECT_EQ(ERR_IO_PENDING, |
| 4501 | pool_->RequestSockets(TestGroupId("a"), params_, absl::nullopt, 1, |
| 4502 | preconnect_callback.callback(), |
| 4503 | NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4504 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4505 | ASSERT_TRUE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 4506 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4507 | EXPECT_EQ(1u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4508 | TestGroupId("a"))); |
| 4509 | EXPECT_EQ(1u, |
| 4510 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4511 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4512 | |
| 4513 | ClientSocketHandle handle1; |
| 4514 | TestCompletionCallback callback1; |
| 4515 | EXPECT_EQ( |
| 4516 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4517 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4518 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4519 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4520 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4521 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4522 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4523 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4524 | TestGroupId("a"))); |
| 4525 | EXPECT_EQ(0u, |
| 4526 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4527 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4528 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4529 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4530 | &handle1)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4531 | } |
| 4532 | |
| 4533 | TEST_F(ClientSocketPoolBaseTest, HigherPriorityRequestStealsJob) { |
| 4534 | CreatePool(kDefaultMaxSockets, 1); |
| 4535 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 4536 | |
| 4537 | ClientSocketHandle handle1; |
| 4538 | TestCompletionCallback callback1; |
| 4539 | EXPECT_EQ( |
| 4540 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4541 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4542 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4543 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4544 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4545 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4546 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4547 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4548 | TestGroupId("a"))); |
| 4549 | EXPECT_EQ(0u, |
| 4550 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4551 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4552 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4553 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4554 | &handle1)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4555 | |
| 4556 | // Insert a higher priority request |
| 4557 | ClientSocketHandle handle2; |
| 4558 | TestCompletionCallback callback2; |
| 4559 | EXPECT_EQ( |
| 4560 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4561 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, HIGHEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4562 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4563 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4564 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4565 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4566 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4567 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4568 | TestGroupId("a"))); |
| 4569 | EXPECT_EQ(0u, |
| 4570 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4571 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4572 | |
| 4573 | // The highest priority request should steal the job from the default priority |
| 4574 | // request. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4575 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4576 | &handle2)); |
| 4577 | EXPECT_FALSE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4578 | &handle1)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4579 | } |
| 4580 | |
| 4581 | TEST_F(ClientSocketPoolBaseTest, RequestStealsJobFromLowestRequestWithJob) { |
| 4582 | CreatePool(3, 3); |
| 4583 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 4584 | |
| 4585 | ClientSocketHandle handle_lowest; |
| 4586 | TestCompletionCallback callback_lowest; |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4587 | EXPECT_EQ( |
| 4588 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4589 | handle_lowest.Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4590 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 4591 | callback_lowest.callback(), |
| 4592 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 4593 | NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4594 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4595 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4596 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4597 | TestGroupId("a"))); |
| 4598 | EXPECT_EQ(0u, |
| 4599 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4600 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4601 | |
| 4602 | ClientSocketHandle handle_highest; |
| 4603 | TestCompletionCallback callback_highest; |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4604 | EXPECT_EQ( |
| 4605 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4606 | handle_highest.Init(TestGroupId("a"), params_, absl::nullopt, HIGHEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4607 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 4608 | callback_highest.callback(), |
| 4609 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 4610 | NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4611 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4612 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4613 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4614 | TestGroupId("a"))); |
| 4615 | EXPECT_EQ(0u, |
| 4616 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4617 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4618 | |
| 4619 | ClientSocketHandle handle_low; |
| 4620 | TestCompletionCallback callback_low; |
| 4621 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4622 | handle_low.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4623 | TestGroupId("a"), params_, absl::nullopt, LOW, SocketTag(), |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4624 | ClientSocketPool::RespectLimits::ENABLED, |
| 4625 | callback_low.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4626 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4627 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4628 | EXPECT_EQ(3u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4629 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4630 | TestGroupId("a"))); |
| 4631 | EXPECT_EQ(0u, |
| 4632 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4633 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4634 | |
| 4635 | ClientSocketHandle handle_lowest2; |
| 4636 | TestCompletionCallback callback_lowest2; |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4637 | EXPECT_EQ( |
| 4638 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4639 | handle_lowest2.Init(TestGroupId("a"), params_, absl::nullopt, LOWEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4640 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 4641 | callback_lowest2.callback(), |
| 4642 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 4643 | NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4644 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4645 | EXPECT_EQ(3u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4646 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4647 | TestGroupId("a"))); |
| 4648 | EXPECT_EQ(0u, |
| 4649 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4650 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4651 | |
| 4652 | // The top three requests in the queue should have jobs. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4653 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4654 | &handle_highest)); |
| 4655 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4656 | &handle_low)); |
| 4657 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4658 | &handle_lowest)); |
| 4659 | EXPECT_FALSE(pool_->RequestInGroupWithHandleHasJobForTesting( |
| 4660 | TestGroupId("a"), &handle_lowest2)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4661 | |
| 4662 | // Add another request with medium priority. It should steal the job from the |
| 4663 | // lowest priority request with a job. |
| 4664 | ClientSocketHandle handle_medium; |
| 4665 | TestCompletionCallback callback_medium; |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4666 | EXPECT_EQ( |
| 4667 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4668 | handle_medium.Init(TestGroupId("a"), params_, absl::nullopt, MEDIUM, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4669 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 4670 | callback_medium.callback(), |
| 4671 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 4672 | NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4673 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4674 | EXPECT_EQ(3u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4675 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4676 | TestGroupId("a"))); |
| 4677 | EXPECT_EQ(0u, |
| 4678 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4679 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
| 4680 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4681 | &handle_highest)); |
| 4682 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4683 | &handle_medium)); |
| 4684 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4685 | &handle_low)); |
| 4686 | EXPECT_FALSE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4687 | &handle_lowest)); |
| 4688 | EXPECT_FALSE(pool_->RequestInGroupWithHandleHasJobForTesting( |
| 4689 | TestGroupId("a"), &handle_lowest2)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4690 | } |
| 4691 | |
| 4692 | TEST_F(ClientSocketPoolBaseTest, ReprioritizeRequestStealsJob) { |
| 4693 | CreatePool(kDefaultMaxSockets, 1); |
| 4694 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 4695 | |
| 4696 | ClientSocketHandle handle1; |
| 4697 | TestCompletionCallback callback1; |
| 4698 | EXPECT_EQ( |
| 4699 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4700 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4701 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4702 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4703 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4704 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4705 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4706 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4707 | TestGroupId("a"))); |
| 4708 | EXPECT_EQ(0u, |
| 4709 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4710 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4711 | |
| 4712 | ClientSocketHandle handle2; |
| 4713 | TestCompletionCallback callback2; |
| 4714 | EXPECT_EQ( |
| 4715 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4716 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4717 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4718 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4719 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4720 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4721 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4722 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4723 | TestGroupId("a"))); |
| 4724 | EXPECT_EQ(0u, |
| 4725 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4726 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4727 | |
| 4728 | // 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] | 4729 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4730 | &handle1)); |
| 4731 | EXPECT_FALSE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4732 | &handle2)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4733 | |
| 4734 | // Reprioritizing the second request places it above the first, and it steals |
| 4735 | // the job from the first request. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4736 | pool_->SetPriority(TestGroupId("a"), &handle2, HIGHEST); |
| 4737 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4738 | &handle2)); |
| 4739 | EXPECT_FALSE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4740 | &handle1)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4741 | } |
| 4742 | |
| 4743 | TEST_F(ClientSocketPoolBaseTest, CancelRequestReassignsJob) { |
| 4744 | CreatePool(kDefaultMaxSockets, 1); |
| 4745 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 4746 | |
| 4747 | ClientSocketHandle handle1; |
| 4748 | TestCompletionCallback callback1; |
| 4749 | EXPECT_EQ( |
| 4750 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4751 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4752 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4753 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4754 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4755 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4756 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4757 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4758 | TestGroupId("a"))); |
| 4759 | EXPECT_EQ(0u, |
| 4760 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4761 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4762 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4763 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4764 | &handle1)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4765 | |
| 4766 | ClientSocketHandle handle2; |
| 4767 | TestCompletionCallback callback2; |
| 4768 | EXPECT_EQ( |
| 4769 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4770 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4771 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4772 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4773 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4774 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4775 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4776 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4777 | TestGroupId("a"))); |
| 4778 | EXPECT_EQ(0u, |
| 4779 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4780 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4781 | |
| 4782 | // The second request doesn't get a job because we are the limit. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4783 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4784 | &handle1)); |
| 4785 | EXPECT_FALSE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4786 | &handle2)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4787 | |
| 4788 | // The second request should get a job upon cancelling the first request. |
| 4789 | handle1.Reset(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4790 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4791 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4792 | TestGroupId("a"))); |
| 4793 | EXPECT_EQ(0u, |
| 4794 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4795 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4796 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4797 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4798 | &handle2)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4799 | } |
| 4800 | |
| 4801 | TEST_F(ClientSocketPoolBaseTest, JobCompletionReassignsJob) { |
| 4802 | CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 4803 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 4804 | |
| 4805 | ClientSocketHandle handle1; |
| 4806 | TestCompletionCallback callback1; |
| 4807 | EXPECT_EQ( |
| 4808 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4809 | handle1.Init(TestGroupId("a"), params_, absl::nullopt, HIGHEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4810 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4811 | callback1.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4812 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4813 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4814 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4815 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4816 | TestGroupId("a"))); |
| 4817 | EXPECT_EQ(0u, |
| 4818 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4819 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4820 | |
| 4821 | ClientSocketHandle handle2; |
| 4822 | TestCompletionCallback callback2; |
| 4823 | EXPECT_EQ( |
| 4824 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4825 | handle2.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4826 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4827 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4828 | pool_.get(), NetLogWithSource())); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4829 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4830 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4831 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4832 | TestGroupId("a"))); |
| 4833 | EXPECT_EQ(0u, |
| 4834 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4835 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4836 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4837 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4838 | &handle1)); |
| 4839 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4840 | &handle2)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4841 | |
| 4842 | // The lower-priority job completes first. The higher-priority request should |
| 4843 | // get the socket, and the lower-priority request should get the remaining |
| 4844 | // job. |
| 4845 | client_socket_factory_.SignalJob(1); |
| 4846 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4847 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4848 | EXPECT_EQ(0u, pool_->NumNeverAssignedConnectJobsInGroupForTesting( |
| 4849 | TestGroupId("a"))); |
| 4850 | EXPECT_EQ(0u, |
| 4851 | pool_->NumUnassignedConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 4852 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4853 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4854 | EXPECT_TRUE(handle1.socket()); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4855 | EXPECT_TRUE(pool_->RequestInGroupWithHandleHasJobForTesting(TestGroupId("a"), |
| 4856 | &handle2)); |
Lily Chen | ecebf93 | 2018-11-02 17:15:43 | [diff] [blame] | 4857 | } |
| 4858 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 4859 | class MockLayeredPool : public HigherLayeredPool { |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4860 | public: |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4861 | MockLayeredPool(TransportClientSocketPool* pool, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4862 | const ClientSocketPool::GroupId& group_id) |
| 4863 | : pool_(pool), group_id_(group_id), can_release_connection_(true) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 4864 | pool_->AddHigherLayeredPool(this); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4865 | } |
| 4866 | |
Daniel Cheng | 4496d082 | 2018-04-26 21:52:15 | [diff] [blame] | 4867 | ~MockLayeredPool() override { pool_->RemoveHigherLayeredPool(this); } |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4868 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4869 | int RequestSocket(TransportClientSocketPool* pool) { |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4870 | return handle_.Init( |
Matt Menke | 870e19ab | 2019-04-23 16:23:03 | [diff] [blame] | 4871 | group_id_, ClientSocketPool::SocketParams::CreateForHttpForTesting(), |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4872 | absl::nullopt, DEFAULT_PRIORITY, SocketTag(), |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4873 | ClientSocketPool::RespectLimits::ENABLED, callback_.callback(), |
| 4874 | ClientSocketPool::ProxyAuthCallback(), pool, NetLogWithSource()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4875 | } |
| 4876 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 4877 | int RequestSocketWithoutLimits(TransportClientSocketPool* pool) { |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4878 | return handle_.Init( |
Matt Menke | 870e19ab | 2019-04-23 16:23:03 | [diff] [blame] | 4879 | group_id_, ClientSocketPool::SocketParams::CreateForHttpForTesting(), |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4880 | absl::nullopt, MAXIMUM_PRIORITY, SocketTag(), |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4881 | ClientSocketPool::RespectLimits::DISABLED, callback_.callback(), |
| 4882 | ClientSocketPool::ProxyAuthCallback(), pool, NetLogWithSource()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4883 | } |
| 4884 | |
| 4885 | bool ReleaseOneConnection() { |
| 4886 | if (!handle_.is_initialized() || !can_release_connection_) { |
| 4887 | return false; |
| 4888 | } |
| 4889 | handle_.socket()->Disconnect(); |
| 4890 | handle_.Reset(); |
| 4891 | return true; |
| 4892 | } |
| 4893 | |
| 4894 | void set_can_release_connection(bool can_release_connection) { |
| 4895 | can_release_connection_ = can_release_connection; |
| 4896 | } |
| 4897 | |
| 4898 | MOCK_METHOD0(CloseOneIdleConnection, bool()); |
| 4899 | |
| 4900 | private: |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 4901 | const raw_ptr<TransportClientSocketPool> pool_; |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4902 | ClientSocketHandle handle_; |
| 4903 | TestCompletionCallback callback_; |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4904 | const ClientSocketPool::GroupId group_id_; |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4905 | bool can_release_connection_; |
| 4906 | }; |
| 4907 | |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4908 | // Tests the basic case of closing an idle socket in a higher layered pool when |
| 4909 | // a new request is issued and the lower layer pool is stalled. |
| 4910 | TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketsHeldByLayeredPoolWhenNeeded) { |
| 4911 | CreatePool(1, 1); |
| 4912 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 4913 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4914 | MockLayeredPool mock_layered_pool(pool_.get(), TestGroupId("foo")); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4915 | EXPECT_THAT(mock_layered_pool.RequestSocket(pool_.get()), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4916 | EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection()) |
| 4917 | .WillOnce(Invoke(&mock_layered_pool, |
| 4918 | &MockLayeredPool::ReleaseOneConnection)); |
| 4919 | ClientSocketHandle handle; |
| 4920 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 4921 | EXPECT_EQ( |
| 4922 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4923 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4924 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 4925 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4926 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4927 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4928 | } |
| 4929 | |
Matt Menke | 83367864 | 2019-03-05 22:05:51 | [diff] [blame] | 4930 | // Tests the case that trying to close an idle socket in a higher layered pool |
| 4931 | // fails. |
| 4932 | TEST_F(ClientSocketPoolBaseTest, |
| 4933 | CloseIdleSocketsHeldByLayeredPoolWhenNeededFails) { |
| 4934 | CreatePool(1, 1); |
| 4935 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 4936 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4937 | MockLayeredPool mock_layered_pool(pool_.get(), TestGroupId("foo")); |
Matt Menke | 83367864 | 2019-03-05 22:05:51 | [diff] [blame] | 4938 | mock_layered_pool.set_can_release_connection(false); |
| 4939 | EXPECT_THAT(mock_layered_pool.RequestSocket(pool_.get()), IsOk()); |
| 4940 | EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection()) |
| 4941 | .WillOnce(Invoke(&mock_layered_pool, |
| 4942 | &MockLayeredPool::ReleaseOneConnection)); |
| 4943 | ClientSocketHandle handle; |
| 4944 | TestCompletionCallback callback; |
| 4945 | EXPECT_EQ( |
| 4946 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4947 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4948 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 4949 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4950 | pool_.get(), NetLogWithSource())); |
Matt Menke | 83367864 | 2019-03-05 22:05:51 | [diff] [blame] | 4951 | base::RunLoop().RunUntilIdle(); |
| 4952 | EXPECT_FALSE(callback.have_result()); |
| 4953 | } |
| 4954 | |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4955 | // Same as above, but the idle socket is in the same group as the stalled |
| 4956 | // socket, and closes the only other request in its group when closing requests |
| 4957 | // in higher layered pools. This generally shouldn't happen, but it may be |
| 4958 | // possible if a higher level pool issues a request and the request is |
| 4959 | // subsequently cancelled. Even if it's not possible, best not to crash. |
| 4960 | TEST_F(ClientSocketPoolBaseTest, |
| 4961 | CloseIdleSocketsHeldByLayeredPoolWhenNeededSameGroup) { |
| 4962 | CreatePool(2, 2); |
| 4963 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 4964 | |
| 4965 | // Need a socket in another group for the pool to be stalled (If a group |
| 4966 | // has the maximum number of connections already, it's not stalled). |
| 4967 | ClientSocketHandle handle1; |
| 4968 | TestCompletionCallback callback1; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4969 | EXPECT_EQ(OK, handle1.Init(TestGroupId("group1"), params_, absl::nullopt, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4970 | DEFAULT_PRIORITY, SocketTag(), |
| 4971 | ClientSocketPool::RespectLimits::ENABLED, |
| 4972 | callback1.callback(), |
| 4973 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 4974 | NetLogWithSource())); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4975 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 4976 | MockLayeredPool mock_layered_pool(pool_.get(), TestGroupId("group2")); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4977 | EXPECT_THAT(mock_layered_pool.RequestSocket(pool_.get()), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4978 | EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection()) |
| 4979 | .WillOnce(Invoke(&mock_layered_pool, |
| 4980 | &MockLayeredPool::ReleaseOneConnection)); |
| 4981 | ClientSocketHandle handle; |
| 4982 | TestCompletionCallback callback2; |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4983 | EXPECT_EQ(ERR_IO_PENDING, |
| 4984 | handle.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 4985 | TestGroupId("group2"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 4986 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 4987 | callback2.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 4988 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4989 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 4990 | } |
| 4991 | |
| 4992 | // Tests the case when an idle socket can be closed when a new request is |
| 4993 | // issued, and the new request belongs to a group that was previously stalled. |
| 4994 | TEST_F(ClientSocketPoolBaseTest, |
| 4995 | CloseIdleSocketsHeldByLayeredPoolInSameGroupWhenNeeded) { |
| 4996 | CreatePool(2, 2); |
| 4997 | std::list<TestConnectJob::JobType> job_types; |
| 4998 | job_types.push_back(TestConnectJob::kMockJob); |
| 4999 | job_types.push_back(TestConnectJob::kMockJob); |
| 5000 | job_types.push_back(TestConnectJob::kMockJob); |
| 5001 | job_types.push_back(TestConnectJob::kMockJob); |
| 5002 | connect_job_factory_->set_job_types(&job_types); |
| 5003 | |
| 5004 | ClientSocketHandle handle1; |
| 5005 | TestCompletionCallback callback1; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5006 | EXPECT_EQ(OK, handle1.Init(TestGroupId("group1"), params_, absl::nullopt, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5007 | DEFAULT_PRIORITY, SocketTag(), |
| 5008 | ClientSocketPool::RespectLimits::ENABLED, |
| 5009 | callback1.callback(), |
| 5010 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 5011 | NetLogWithSource())); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5012 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5013 | MockLayeredPool mock_layered_pool(pool_.get(), TestGroupId("group2")); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5014 | EXPECT_THAT(mock_layered_pool.RequestSocket(pool_.get()), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5015 | EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection()) |
| 5016 | .WillRepeatedly(Invoke(&mock_layered_pool, |
| 5017 | &MockLayeredPool::ReleaseOneConnection)); |
| 5018 | mock_layered_pool.set_can_release_connection(false); |
| 5019 | |
| 5020 | // The third request is made when the socket pool is in a stalled state. |
| 5021 | ClientSocketHandle handle3; |
| 5022 | TestCompletionCallback callback3; |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5023 | EXPECT_EQ(ERR_IO_PENDING, |
| 5024 | handle3.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5025 | TestGroupId("group3"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5026 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 5027 | callback3.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 5028 | pool_.get(), NetLogWithSource())); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5029 | |
| 5030 | base::RunLoop().RunUntilIdle(); |
| 5031 | EXPECT_FALSE(callback3.have_result()); |
| 5032 | |
| 5033 | // The fourth request is made when the pool is no longer stalled. The third |
| 5034 | // request should be serviced first, since it was issued first and has the |
| 5035 | // same priority. |
| 5036 | mock_layered_pool.set_can_release_connection(true); |
| 5037 | ClientSocketHandle handle4; |
| 5038 | TestCompletionCallback callback4; |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5039 | EXPECT_EQ(ERR_IO_PENDING, |
| 5040 | handle4.Init( |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5041 | TestGroupId("group3"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5042 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 5043 | callback4.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 5044 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5045 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5046 | EXPECT_FALSE(callback4.have_result()); |
| 5047 | |
| 5048 | // Closing a handle should free up another socket slot. |
| 5049 | handle1.Reset(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5050 | EXPECT_THAT(callback4.WaitForResult(), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5051 | } |
| 5052 | |
| 5053 | // Tests the case when an idle socket can be closed when a new request is |
| 5054 | // issued, and the new request belongs to a group that was previously stalled. |
| 5055 | // |
| 5056 | // The two differences from the above test are that the stalled requests are not |
| 5057 | // in the same group as the layered pool's request, and the the fourth request |
| 5058 | // has a higher priority than the third one, so gets a socket first. |
| 5059 | TEST_F(ClientSocketPoolBaseTest, |
| 5060 | CloseIdleSocketsHeldByLayeredPoolInSameGroupWhenNeeded2) { |
| 5061 | CreatePool(2, 2); |
| 5062 | std::list<TestConnectJob::JobType> job_types; |
| 5063 | job_types.push_back(TestConnectJob::kMockJob); |
| 5064 | job_types.push_back(TestConnectJob::kMockJob); |
| 5065 | job_types.push_back(TestConnectJob::kMockJob); |
| 5066 | job_types.push_back(TestConnectJob::kMockJob); |
| 5067 | connect_job_factory_->set_job_types(&job_types); |
| 5068 | |
| 5069 | ClientSocketHandle handle1; |
| 5070 | TestCompletionCallback callback1; |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5071 | EXPECT_EQ(OK, handle1.Init(TestGroupId("group1"), params_, absl::nullopt, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5072 | DEFAULT_PRIORITY, SocketTag(), |
| 5073 | ClientSocketPool::RespectLimits::ENABLED, |
| 5074 | callback1.callback(), |
| 5075 | ClientSocketPool::ProxyAuthCallback(), pool_.get(), |
| 5076 | NetLogWithSource())); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5077 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5078 | MockLayeredPool mock_layered_pool(pool_.get(), TestGroupId("group2")); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5079 | EXPECT_THAT(mock_layered_pool.RequestSocket(pool_.get()), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5080 | EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection()) |
| 5081 | .WillRepeatedly(Invoke(&mock_layered_pool, |
| 5082 | &MockLayeredPool::ReleaseOneConnection)); |
| 5083 | mock_layered_pool.set_can_release_connection(false); |
| 5084 | |
| 5085 | // The third request is made when the socket pool is in a stalled state. |
| 5086 | ClientSocketHandle handle3; |
| 5087 | TestCompletionCallback callback3; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 5088 | EXPECT_EQ( |
| 5089 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5090 | handle3.Init(TestGroupId("group3"), params_, absl::nullopt, MEDIUM, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5091 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 5092 | callback3.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 5093 | pool_.get(), NetLogWithSource())); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5094 | |
| 5095 | base::RunLoop().RunUntilIdle(); |
| 5096 | EXPECT_FALSE(callback3.have_result()); |
| 5097 | |
| 5098 | // The fourth request is made when the pool is no longer stalled. This |
| 5099 | // request has a higher priority than the third request, so is serviced first. |
| 5100 | mock_layered_pool.set_can_release_connection(true); |
| 5101 | ClientSocketHandle handle4; |
| 5102 | TestCompletionCallback callback4; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 5103 | EXPECT_EQ( |
| 5104 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5105 | handle4.Init(TestGroupId("group3"), params_, absl::nullopt, HIGHEST, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5106 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 5107 | callback4.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 5108 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5109 | EXPECT_THAT(callback4.WaitForResult(), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5110 | EXPECT_FALSE(callback3.have_result()); |
| 5111 | |
| 5112 | // Closing a handle should free up another socket slot. |
| 5113 | handle1.Reset(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5114 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5115 | } |
| 5116 | |
| 5117 | TEST_F(ClientSocketPoolBaseTest, |
| 5118 | CloseMultipleIdleSocketsHeldByLayeredPoolWhenNeeded) { |
| 5119 | CreatePool(1, 1); |
| 5120 | connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 5121 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5122 | MockLayeredPool mock_layered_pool1(pool_.get(), TestGroupId("foo")); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5123 | EXPECT_THAT(mock_layered_pool1.RequestSocket(pool_.get()), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5124 | EXPECT_CALL(mock_layered_pool1, CloseOneIdleConnection()) |
| 5125 | .WillRepeatedly(Invoke(&mock_layered_pool1, |
| 5126 | &MockLayeredPool::ReleaseOneConnection)); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5127 | MockLayeredPool mock_layered_pool2(pool_.get(), TestGroupId("bar")); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5128 | EXPECT_THAT(mock_layered_pool2.RequestSocketWithoutLimits(pool_.get()), |
| 5129 | IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5130 | EXPECT_CALL(mock_layered_pool2, CloseOneIdleConnection()) |
| 5131 | .WillRepeatedly(Invoke(&mock_layered_pool2, |
| 5132 | &MockLayeredPool::ReleaseOneConnection)); |
| 5133 | ClientSocketHandle handle; |
| 5134 | TestCompletionCallback callback; |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 5135 | EXPECT_EQ( |
| 5136 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5137 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5138 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 5139 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 5140 | pool_.get(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5141 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 58e562f | 2013-04-22 17:32:20 | [diff] [blame] | 5142 | } |
| 5143 | |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5144 | // Test that when a socket pool and group are at their limits, a request |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5145 | // with RespectLimits::DISABLED triggers creation of a new socket, and gets the |
| 5146 | // socket instead of a request with the same priority that was issued earlier, |
| 5147 | // but has RespectLimits::ENABLED. |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5148 | TEST_F(ClientSocketPoolBaseTest, IgnoreLimits) { |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5149 | CreatePool(1, 1); |
| 5150 | |
| 5151 | // Issue a request to reach the socket pool limit. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5152 | EXPECT_EQ(OK, StartRequestWithIgnoreLimits( |
| 5153 | TestGroupId("a"), MAXIMUM_PRIORITY, |
| 5154 | ClientSocketPool::RespectLimits::ENABLED)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5155 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5156 | |
| 5157 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 5158 | |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5159 | EXPECT_EQ(ERR_IO_PENDING, StartRequestWithIgnoreLimits( |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5160 | TestGroupId("a"), MAXIMUM_PRIORITY, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5161 | ClientSocketPool::RespectLimits::ENABLED)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5162 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5163 | |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5164 | // Issue a request that ignores the limits, so a new ConnectJob is |
| 5165 | // created. |
| 5166 | EXPECT_EQ(ERR_IO_PENDING, StartRequestWithIgnoreLimits( |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5167 | TestGroupId("a"), MAXIMUM_PRIORITY, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5168 | ClientSocketPool::RespectLimits::DISABLED)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5169 | ASSERT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5170 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5171 | EXPECT_THAT(request(2)->WaitForResult(), IsOk()); |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5172 | EXPECT_FALSE(request(1)->have_result()); |
| 5173 | } |
| 5174 | |
[email protected] | c55fabd | 2013-11-04 23:26:56 | [diff] [blame] | 5175 | // Test that when a socket pool and group are at their limits, a ConnectJob |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5176 | // issued for a request with RespectLimits::DISABLED is not cancelled when a |
| 5177 | // request with RespectLimits::ENABLED issued to the same group is cancelled. |
[email protected] | c55fabd | 2013-11-04 23:26:56 | [diff] [blame] | 5178 | TEST_F(ClientSocketPoolBaseTest, IgnoreLimitsCancelOtherJob) { |
[email protected] | c55fabd | 2013-11-04 23:26:56 | [diff] [blame] | 5179 | CreatePool(1, 1); |
| 5180 | |
| 5181 | // Issue a request to reach the socket pool limit. |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5182 | EXPECT_EQ(OK, StartRequestWithIgnoreLimits( |
| 5183 | TestGroupId("a"), MAXIMUM_PRIORITY, |
| 5184 | ClientSocketPool::RespectLimits::ENABLED)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5185 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | c55fabd | 2013-11-04 23:26:56 | [diff] [blame] | 5186 | |
| 5187 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 5188 | |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5189 | EXPECT_EQ(ERR_IO_PENDING, StartRequestWithIgnoreLimits( |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5190 | TestGroupId("a"), MAXIMUM_PRIORITY, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5191 | ClientSocketPool::RespectLimits::ENABLED)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5192 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | c55fabd | 2013-11-04 23:26:56 | [diff] [blame] | 5193 | |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5194 | // Issue a request with RespectLimits::DISABLED, so a new ConnectJob is |
| 5195 | // created. |
| 5196 | EXPECT_EQ(ERR_IO_PENDING, StartRequestWithIgnoreLimits( |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5197 | TestGroupId("a"), MAXIMUM_PRIORITY, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5198 | ClientSocketPool::RespectLimits::DISABLED)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5199 | ASSERT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5200 | |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 5201 | // Cancel the pending request with RespectLimits::ENABLED. The ConnectJob |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5202 | // should not be cancelled. |
| 5203 | request(1)->handle()->Reset(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5204 | ASSERT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5205 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5206 | EXPECT_THAT(request(2)->WaitForResult(), IsOk()); |
[email protected] | b021ece6 | 2013-06-11 11:06:33 | [diff] [blame] | 5207 | EXPECT_FALSE(request(1)->have_result()); |
| 5208 | } |
| 5209 | |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5210 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthNoAuthCallback) { |
| 5211 | CreatePool(1, 1); |
| 5212 | |
| 5213 | connect_job_factory_->set_job_type(TestConnectJob::kMockAuthChallengeOnceJob); |
| 5214 | |
| 5215 | ClientSocketHandle handle; |
| 5216 | TestCompletionCallback callback; |
| 5217 | EXPECT_EQ( |
| 5218 | ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5219 | handle.Init(TestGroupId("a"), params_, absl::nullopt, DEFAULT_PRIORITY, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5220 | SocketTag(), ClientSocketPool::RespectLimits::ENABLED, |
| 5221 | callback.callback(), ClientSocketPool::ProxyAuthCallback(), |
| 5222 | pool_.get(), NetLogWithSource())); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5223 | |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5224 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5225 | |
| 5226 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_PROXY_AUTH_REQUESTED)); |
| 5227 | EXPECT_FALSE(handle.is_initialized()); |
| 5228 | EXPECT_FALSE(handle.socket()); |
| 5229 | |
| 5230 | // The group should now be empty, and thus be deleted. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5231 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5232 | } |
| 5233 | |
| 5234 | class TestAuthHelper { |
| 5235 | public: |
| 5236 | TestAuthHelper() = default; |
Peter Boström | 293b134 | 2021-09-22 17:31:43 | [diff] [blame] | 5237 | |
| 5238 | TestAuthHelper(const TestAuthHelper&) = delete; |
| 5239 | TestAuthHelper& operator=(const TestAuthHelper&) = delete; |
| 5240 | |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5241 | ~TestAuthHelper() = default; |
| 5242 | |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5243 | void InitHandle( |
Matt Menke | 84d11e56 | 2019-03-27 00:11:19 | [diff] [blame] | 5244 | scoped_refptr<ClientSocketPool::SocketParams> params, |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5245 | TransportClientSocketPool* pool, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5246 | RequestPriority priority = DEFAULT_PRIORITY, |
| 5247 | ClientSocketPool::RespectLimits respect_limits = |
| 5248 | ClientSocketPool::RespectLimits::ENABLED, |
| 5249 | const ClientSocketPool::GroupId& group_id_in = TestGroupId("a")) { |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5250 | EXPECT_EQ(ERR_IO_PENDING, |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 5251 | handle_.Init(group_id_in, params, absl::nullopt, priority, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 5252 | SocketTag(), respect_limits, callback_.callback(), |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5253 | base::BindRepeating(&TestAuthHelper::AuthCallback, |
| 5254 | base::Unretained(this)), |
| 5255 | pool, NetLogWithSource())); |
| 5256 | } |
| 5257 | |
| 5258 | void WaitForAuth() { |
| 5259 | run_loop_ = std::make_unique<base::RunLoop>(); |
| 5260 | run_loop_->Run(); |
| 5261 | run_loop_.reset(); |
| 5262 | } |
| 5263 | |
| 5264 | void WaitForAuthAndRestartSync() { |
| 5265 | restart_sync_ = true; |
| 5266 | WaitForAuth(); |
| 5267 | restart_sync_ = false; |
| 5268 | } |
| 5269 | |
| 5270 | void WaitForAuthAndResetHandleSync() { |
| 5271 | reset_handle_sync_ = true; |
| 5272 | WaitForAuth(); |
| 5273 | reset_handle_sync_ = false; |
| 5274 | } |
| 5275 | |
| 5276 | void RestartWithAuth() { |
| 5277 | DCHECK(restart_with_auth_callback_); |
| 5278 | std::move(restart_with_auth_callback_).Run(); |
| 5279 | } |
| 5280 | |
| 5281 | int WaitForResult() { |
| 5282 | int result = callback_.WaitForResult(); |
| 5283 | // There shouldn't be any callback waiting to be invoked once the request is |
| 5284 | // complete. |
| 5285 | EXPECT_FALSE(restart_with_auth_callback_); |
| 5286 | // The socket should only be initialized on success. |
| 5287 | EXPECT_EQ(result == OK, handle_.is_initialized()); |
| 5288 | EXPECT_EQ(result == OK, handle_.socket() != nullptr); |
| 5289 | return result; |
| 5290 | } |
| 5291 | |
| 5292 | ClientSocketHandle* handle() { return &handle_; } |
| 5293 | int auth_count() const { return auth_count_; } |
| 5294 | int have_result() const { return callback_.have_result(); } |
| 5295 | |
| 5296 | private: |
| 5297 | void AuthCallback(const HttpResponseInfo& response, |
| 5298 | HttpAuthController* auth_controller, |
| 5299 | base::OnceClosure restart_with_auth_callback) { |
| 5300 | EXPECT_FALSE(restart_with_auth_callback_); |
| 5301 | EXPECT_TRUE(restart_with_auth_callback); |
| 5302 | |
| 5303 | // Once there's a result, this method shouldn't be invoked again. |
| 5304 | EXPECT_FALSE(callback_.have_result()); |
| 5305 | |
| 5306 | ++auth_count_; |
| 5307 | run_loop_->Quit(); |
| 5308 | if (restart_sync_) { |
| 5309 | std::move(restart_with_auth_callback).Run(); |
| 5310 | return; |
| 5311 | } |
| 5312 | |
| 5313 | restart_with_auth_callback_ = std::move(restart_with_auth_callback); |
| 5314 | |
| 5315 | if (reset_handle_sync_) { |
| 5316 | handle_.Reset(); |
| 5317 | return; |
| 5318 | } |
| 5319 | } |
| 5320 | |
| 5321 | std::unique_ptr<base::RunLoop> run_loop_; |
| 5322 | base::OnceClosure restart_with_auth_callback_; |
| 5323 | |
| 5324 | bool restart_sync_ = false; |
| 5325 | bool reset_handle_sync_ = false; |
| 5326 | |
| 5327 | ClientSocketHandle handle_; |
| 5328 | int auth_count_ = 0; |
| 5329 | TestCompletionCallback callback_; |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5330 | }; |
| 5331 | |
| 5332 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthOnce) { |
| 5333 | CreatePool(1, 1); |
| 5334 | connect_job_factory_->set_job_type(TestConnectJob::kMockAuthChallengeOnceJob); |
| 5335 | |
| 5336 | TestAuthHelper auth_helper; |
| 5337 | auth_helper.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5338 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 5339 | EXPECT_EQ(LOAD_STATE_CONNECTING, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5340 | pool_->GetLoadState(TestGroupId("a"), auth_helper.handle())); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5341 | |
| 5342 | auth_helper.WaitForAuth(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5343 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 5344 | EXPECT_EQ(LOAD_STATE_ESTABLISHING_PROXY_TUNNEL, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5345 | pool_->GetLoadState(TestGroupId("a"), auth_helper.handle())); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5346 | |
| 5347 | auth_helper.RestartWithAuth(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5348 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 5349 | EXPECT_EQ(LOAD_STATE_ESTABLISHING_PROXY_TUNNEL, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5350 | pool_->GetLoadState(TestGroupId("a"), auth_helper.handle())); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5351 | |
| 5352 | EXPECT_THAT(auth_helper.WaitForResult(), IsOk()); |
| 5353 | EXPECT_EQ(1, auth_helper.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5354 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 5355 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5356 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5357 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5358 | } |
| 5359 | |
| 5360 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthOnceSync) { |
| 5361 | CreatePool(1, 1); |
| 5362 | connect_job_factory_->set_job_type(TestConnectJob::kMockAuthChallengeOnceJob); |
| 5363 | |
| 5364 | TestAuthHelper auth_helper; |
| 5365 | auth_helper.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5366 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 5367 | EXPECT_EQ(LOAD_STATE_CONNECTING, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5368 | pool_->GetLoadState(TestGroupId("a"), auth_helper.handle())); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5369 | |
| 5370 | auth_helper.WaitForAuthAndRestartSync(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5371 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 5372 | EXPECT_EQ(LOAD_STATE_ESTABLISHING_PROXY_TUNNEL, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5373 | pool_->GetLoadState(TestGroupId("a"), auth_helper.handle())); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5374 | |
| 5375 | EXPECT_THAT(auth_helper.WaitForResult(), IsOk()); |
| 5376 | EXPECT_EQ(1, auth_helper.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5377 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 5378 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5379 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5380 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5381 | } |
| 5382 | |
| 5383 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthOnceFails) { |
| 5384 | CreatePool(1, 1); |
| 5385 | connect_job_factory_->set_job_type( |
| 5386 | TestConnectJob::kMockAuthChallengeOnceFailingJob); |
| 5387 | |
| 5388 | TestAuthHelper auth_helper; |
| 5389 | auth_helper.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5390 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5391 | |
| 5392 | auth_helper.WaitForAuth(); |
| 5393 | auth_helper.RestartWithAuth(); |
| 5394 | EXPECT_THAT(auth_helper.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
| 5395 | |
| 5396 | EXPECT_EQ(1, auth_helper.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5397 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5398 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5399 | } |
| 5400 | |
| 5401 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthOnceSyncFails) { |
| 5402 | CreatePool(1, 1); |
| 5403 | connect_job_factory_->set_job_type( |
| 5404 | TestConnectJob::kMockAuthChallengeOnceFailingJob); |
| 5405 | |
| 5406 | TestAuthHelper auth_helper; |
| 5407 | auth_helper.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5408 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5409 | |
| 5410 | auth_helper.WaitForAuthAndRestartSync(); |
| 5411 | EXPECT_THAT(auth_helper.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
| 5412 | |
| 5413 | EXPECT_EQ(1, auth_helper.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5414 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5415 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5416 | } |
| 5417 | |
| 5418 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthOnceDeleteHandle) { |
| 5419 | CreatePool(1, 1); |
| 5420 | connect_job_factory_->set_job_type(TestConnectJob::kMockAuthChallengeOnceJob); |
| 5421 | |
| 5422 | TestAuthHelper auth_helper; |
| 5423 | auth_helper.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5424 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5425 | |
| 5426 | auth_helper.WaitForAuth(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5427 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5428 | |
| 5429 | auth_helper.handle()->Reset(); |
| 5430 | |
| 5431 | EXPECT_EQ(1, auth_helper.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5432 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5433 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5434 | EXPECT_FALSE(auth_helper.handle()->is_initialized()); |
| 5435 | EXPECT_FALSE(auth_helper.handle()->socket()); |
| 5436 | } |
| 5437 | |
| 5438 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthOnceDeleteHandleSync) { |
| 5439 | CreatePool(1, 1); |
| 5440 | connect_job_factory_->set_job_type(TestConnectJob::kMockAuthChallengeOnceJob); |
| 5441 | |
| 5442 | TestAuthHelper auth_helper; |
| 5443 | auth_helper.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5444 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5445 | |
| 5446 | auth_helper.WaitForAuthAndResetHandleSync(); |
| 5447 | EXPECT_EQ(1, auth_helper.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5448 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5449 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5450 | EXPECT_FALSE(auth_helper.handle()->is_initialized()); |
| 5451 | EXPECT_FALSE(auth_helper.handle()->socket()); |
| 5452 | } |
| 5453 | |
| 5454 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthOnceFlushWithError) { |
| 5455 | CreatePool(1, 1); |
| 5456 | connect_job_factory_->set_job_type(TestConnectJob::kMockAuthChallengeOnceJob); |
| 5457 | |
| 5458 | TestAuthHelper auth_helper; |
| 5459 | auth_helper.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5460 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5461 | |
| 5462 | auth_helper.WaitForAuth(); |
| 5463 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 5464 | pool_->FlushWithError(ERR_FAILED, "Network changed"); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5465 | base::RunLoop().RunUntilIdle(); |
| 5466 | |
| 5467 | // When flushing the socket pool, bound sockets should delay returning the |
| 5468 | // error until completion. |
| 5469 | EXPECT_FALSE(auth_helper.have_result()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5470 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5471 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5472 | |
| 5473 | auth_helper.RestartWithAuth(); |
| 5474 | // The callback should be called asynchronously. |
| 5475 | EXPECT_FALSE(auth_helper.have_result()); |
| 5476 | |
| 5477 | EXPECT_THAT(auth_helper.WaitForResult(), IsError(ERR_FAILED)); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5478 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5479 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5480 | } |
| 5481 | |
| 5482 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthTwice) { |
| 5483 | CreatePool(1, 1); |
| 5484 | connect_job_factory_->set_job_type( |
| 5485 | TestConnectJob::kMockAuthChallengeTwiceJob); |
| 5486 | |
| 5487 | TestAuthHelper auth_helper; |
| 5488 | auth_helper.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5489 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 5490 | EXPECT_EQ(LOAD_STATE_CONNECTING, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5491 | pool_->GetLoadState(TestGroupId("a"), auth_helper.handle())); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5492 | |
| 5493 | auth_helper.WaitForAuth(); |
| 5494 | auth_helper.RestartWithAuth(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5495 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5496 | EXPECT_EQ(1, auth_helper.auth_count()); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 5497 | EXPECT_EQ(LOAD_STATE_ESTABLISHING_PROXY_TUNNEL, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5498 | pool_->GetLoadState(TestGroupId("a"), auth_helper.handle())); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5499 | |
| 5500 | auth_helper.WaitForAuth(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5501 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 5502 | EXPECT_EQ(2, auth_helper.auth_count()); |
| 5503 | EXPECT_EQ(LOAD_STATE_ESTABLISHING_PROXY_TUNNEL, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5504 | pool_->GetLoadState(TestGroupId("a"), auth_helper.handle())); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 5505 | |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5506 | auth_helper.RestartWithAuth(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5507 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5508 | EXPECT_EQ(2, auth_helper.auth_count()); |
Matt Menke | 4b69f93 | 2019-03-04 16:20:01 | [diff] [blame] | 5509 | EXPECT_EQ(LOAD_STATE_ESTABLISHING_PROXY_TUNNEL, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5510 | pool_->GetLoadState(TestGroupId("a"), auth_helper.handle())); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5511 | |
| 5512 | EXPECT_THAT(auth_helper.WaitForResult(), IsOk()); |
| 5513 | EXPECT_EQ(2, auth_helper.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5514 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 5515 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5516 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5517 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5518 | } |
| 5519 | |
| 5520 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthTwiceFails) { |
| 5521 | CreatePool(1, 1); |
| 5522 | connect_job_factory_->set_job_type( |
| 5523 | TestConnectJob::kMockAuthChallengeTwiceFailingJob); |
| 5524 | |
| 5525 | TestAuthHelper auth_helper; |
| 5526 | auth_helper.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5527 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5528 | |
| 5529 | auth_helper.WaitForAuth(); |
| 5530 | auth_helper.RestartWithAuth(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5531 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5532 | EXPECT_EQ(1, auth_helper.auth_count()); |
| 5533 | |
| 5534 | auth_helper.WaitForAuth(); |
| 5535 | auth_helper.RestartWithAuth(); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5536 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5537 | EXPECT_EQ(2, auth_helper.auth_count()); |
| 5538 | |
| 5539 | EXPECT_THAT(auth_helper.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
| 5540 | EXPECT_EQ(2, auth_helper.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5541 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5542 | EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 5543 | } |
| 5544 | |
| 5545 | // Makes sure that when a bound request is destroyed, a new ConnectJob is |
| 5546 | // created, if needed. |
| 5547 | TEST_F(ClientSocketPoolBaseTest, |
| 5548 | ProxyAuthCreateNewConnectJobOnDestroyBoundRequest) { |
| 5549 | CreatePool(1 /* max_sockets */, 1 /* max_sockets_per_group */); |
| 5550 | connect_job_factory_->set_job_type( |
| 5551 | TestConnectJob::kMockAuthChallengeOnceFailingJob); |
| 5552 | |
| 5553 | // First request creates a ConnectJob. |
| 5554 | TestAuthHelper auth_helper1; |
| 5555 | auth_helper1.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5556 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5557 | |
| 5558 | // A second request come in, but no new ConnectJob is needed, since the limit |
| 5559 | // has been reached. |
| 5560 | TestAuthHelper auth_helper2; |
| 5561 | auth_helper2.InitHandle(params_, pool_.get()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5562 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5563 | |
| 5564 | // Run until the auth callback for the first request is invoked. |
| 5565 | auth_helper1.WaitForAuth(); |
| 5566 | EXPECT_EQ(0, auth_helper2.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5567 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 5568 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5569 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5570 | |
| 5571 | // Make connect jobs succeed, then cancel the first request, which should |
| 5572 | // destroy the bound ConnectJob, and cause a new ConnectJob to start. |
| 5573 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 5574 | auth_helper1.handle()->Reset(); |
| 5575 | EXPECT_EQ(0, auth_helper2.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5576 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5577 | |
| 5578 | // The second ConnectJob should succeed. |
| 5579 | EXPECT_THAT(auth_helper2.WaitForResult(), IsOk()); |
| 5580 | EXPECT_EQ(0, auth_helper2.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5581 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5582 | } |
| 5583 | |
| 5584 | // Makes sure that when a bound request is destroyed, a new ConnectJob is |
| 5585 | // created for another group, if needed. |
| 5586 | TEST_F(ClientSocketPoolBaseTest, |
| 5587 | ProxyAuthCreateNewConnectJobOnDestroyBoundRequestDifferentGroups) { |
| 5588 | CreatePool(1 /* max_sockets */, 1 /* max_sockets_per_group */); |
| 5589 | connect_job_factory_->set_job_type( |
| 5590 | TestConnectJob::kMockAuthChallengeOnceFailingJob); |
| 5591 | |
| 5592 | // First request creates a ConnectJob. |
| 5593 | TestAuthHelper auth_helper1; |
| 5594 | auth_helper1.InitHandle(params_, pool_.get(), DEFAULT_PRIORITY); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5595 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5596 | |
| 5597 | // A second request come in, but no new ConnectJob is needed, since the limit |
| 5598 | // has been reached. |
| 5599 | TestAuthHelper auth_helper2; |
| 5600 | auth_helper2.InitHandle(params_, pool_.get(), DEFAULT_PRIORITY, |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5601 | ClientSocketPool::RespectLimits::ENABLED, |
| 5602 | TestGroupId("b")); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5603 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 5604 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("b"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5605 | |
| 5606 | // Run until the auth callback for the first request is invoked. |
| 5607 | auth_helper1.WaitForAuth(); |
| 5608 | EXPECT_EQ(0, auth_helper2.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5609 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 5610 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5611 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5612 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("b"))); |
| 5613 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("b"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5614 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("b"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5615 | |
| 5616 | // Make connect jobs succeed, then cancel the first request, which should |
| 5617 | // destroy the bound ConnectJob, and cause a new ConnectJob to start for the |
| 5618 | // other group. |
| 5619 | connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 5620 | auth_helper1.handle()->Reset(); |
| 5621 | EXPECT_EQ(0, auth_helper2.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5622 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 5623 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("b"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5624 | |
| 5625 | // The second ConnectJob should succeed. |
| 5626 | EXPECT_THAT(auth_helper2.WaitForResult(), IsOk()); |
| 5627 | EXPECT_EQ(0, auth_helper2.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5628 | EXPECT_FALSE(pool_->HasGroupForTesting(TestGroupId("a"))); |
| 5629 | EXPECT_EQ(0u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("b"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5630 | } |
| 5631 | |
| 5632 | // Test that once an auth challenge is bound, that's the request that gets all |
| 5633 | // subsequent calls and the socket itself. |
| 5634 | TEST_F(ClientSocketPoolBaseTest, ProxyAuthStaysBound) { |
| 5635 | CreatePool(1, 1); |
| 5636 | connect_job_factory_->set_job_type( |
| 5637 | TestConnectJob::kMockAuthChallengeTwiceJob); |
| 5638 | |
| 5639 | // First request creates a ConnectJob. |
| 5640 | TestAuthHelper auth_helper1; |
| 5641 | auth_helper1.InitHandle(params_, pool_.get(), LOWEST); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5642 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5643 | |
| 5644 | // A second, higher priority request is made. |
| 5645 | TestAuthHelper auth_helper2; |
| 5646 | auth_helper2.InitHandle(params_, pool_.get(), LOW); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5647 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5648 | |
| 5649 | // Run until the auth callback for the second request is invoked. |
| 5650 | auth_helper2.WaitForAuth(); |
| 5651 | EXPECT_EQ(0, auth_helper1.auth_count()); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5652 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 5653 | EXPECT_EQ(0, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | c6b3edf7 | 2019-03-19 17:00:39 | [diff] [blame] | 5654 | EXPECT_EQ(0u, pool_->IdleSocketCountInGroup(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5655 | |
| 5656 | // Start a higher priority job. It shouldn't be able to steal |auth_helper2|'s |
| 5657 | // ConnectJob. |
| 5658 | TestAuthHelper auth_helper3; |
| 5659 | auth_helper3.InitHandle(params_, pool_.get(), HIGHEST); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5660 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5661 | |
| 5662 | // Start a higher job that ignores limits, creating a hanging socket. It |
| 5663 | // shouldn't be able to steal |auth_helper2|'s ConnectJob. |
| 5664 | connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 5665 | TestAuthHelper auth_helper4; |
| 5666 | auth_helper4.InitHandle(params_, pool_.get(), HIGHEST, |
| 5667 | ClientSocketPool::RespectLimits::DISABLED); |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5668 | EXPECT_EQ(2u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5669 | |
| 5670 | // Restart with auth, and |auth_helper2|'s auth method should be invoked |
| 5671 | // again. |
| 5672 | auth_helper2.RestartWithAuth(); |
| 5673 | auth_helper2.WaitForAuth(); |
| 5674 | EXPECT_EQ(0, auth_helper1.auth_count()); |
| 5675 | EXPECT_FALSE(auth_helper1.have_result()); |
| 5676 | EXPECT_EQ(2, auth_helper2.auth_count()); |
| 5677 | EXPECT_FALSE(auth_helper2.have_result()); |
| 5678 | EXPECT_EQ(0, auth_helper3.auth_count()); |
| 5679 | EXPECT_FALSE(auth_helper3.have_result()); |
| 5680 | EXPECT_EQ(0, auth_helper4.auth_count()); |
| 5681 | EXPECT_FALSE(auth_helper4.have_result()); |
| 5682 | |
| 5683 | // Advance auth again, and |auth_helper2| should get the socket. |
| 5684 | auth_helper2.RestartWithAuth(); |
| 5685 | EXPECT_THAT(auth_helper2.WaitForResult(), IsOk()); |
| 5686 | // The hung ConnectJob for the RespectLimits::DISABLED request is still in the |
| 5687 | // socket pool. |
Matt Menke | 9fa17d5 | 2019-03-25 19:12:26 | [diff] [blame] | 5688 | EXPECT_EQ(1u, pool_->NumConnectJobsInGroupForTesting(TestGroupId("a"))); |
| 5689 | EXPECT_EQ(1, pool_->NumActiveSocketsInGroupForTesting(TestGroupId("a"))); |
Matt Menke | b57663b3 | 2019-03-01 17:17:10 | [diff] [blame] | 5690 | EXPECT_EQ(0, auth_helper1.auth_count()); |
| 5691 | EXPECT_FALSE(auth_helper1.have_result()); |
| 5692 | EXPECT_EQ(0, auth_helper3.auth_count()); |
| 5693 | EXPECT_FALSE(auth_helper3.have_result()); |
| 5694 | EXPECT_EQ(0, auth_helper4.auth_count()); |
| 5695 | EXPECT_FALSE(auth_helper4.have_result()); |
| 5696 | |
| 5697 | // If the socket is returned to the socket pool, the RespectLimits::DISABLED |
| 5698 | // socket request should be able to claim it. |
| 5699 | auth_helper2.handle()->Reset(); |
| 5700 | EXPECT_THAT(auth_helper4.WaitForResult(), IsOk()); |
| 5701 | EXPECT_EQ(0, auth_helper1.auth_count()); |
| 5702 | EXPECT_FALSE(auth_helper1.have_result()); |
| 5703 | EXPECT_EQ(0, auth_helper3.auth_count()); |
| 5704 | EXPECT_FALSE(auth_helper3.have_result()); |
| 5705 | EXPECT_EQ(0, auth_helper4.auth_count()); |
| 5706 | } |
| 5707 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5708 | enum class RefreshType { |
| 5709 | kServer, |
| 5710 | kProxy, |
| 5711 | }; |
| 5712 | |
| 5713 | // Common base class to test RefreshGroup() when called from either |
| 5714 | // OnSSLConfigForServerChanged() matching a specific group or the pool's proxy. |
| 5715 | // |
| 5716 | // Tests which test behavior specific to one or the other case should use |
| 5717 | // ClientSocketPoolBaseTest directly. In particular, there is no "other group" |
| 5718 | // when the pool's proxy matches. |
| 5719 | class ClientSocketPoolBaseRefreshTest |
| 5720 | : public ClientSocketPoolBaseTest, |
| 5721 | public testing::WithParamInterface<RefreshType> { |
| 5722 | public: |
| 5723 | void CreatePoolForRefresh(int max_sockets, |
| 5724 | int max_sockets_per_group, |
| 5725 | bool enable_backup_connect_jobs = false) { |
| 5726 | switch (GetParam()) { |
| 5727 | case RefreshType::kServer: |
| 5728 | CreatePool(max_sockets, max_sockets_per_group, |
| 5729 | enable_backup_connect_jobs); |
| 5730 | break; |
| 5731 | case RefreshType::kProxy: |
| 5732 | CreatePoolWithIdleTimeouts( |
| 5733 | max_sockets, max_sockets_per_group, kUnusedIdleSocketTimeout, |
| 5734 | ClientSocketPool::used_idle_socket_timeout(), |
| 5735 | enable_backup_connect_jobs, |
Eric Orth | 5ccc3f0 | 2021-09-23 00:01:57 | [diff] [blame] | 5736 | PacResultElementToProxyServer("HTTPS myproxy:70")); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5737 | break; |
| 5738 | } |
| 5739 | } |
| 5740 | |
| 5741 | static ClientSocketPool::GroupId GetGroupId() { |
Eric Orth | a2e777321 | 2021-06-22 21:49:55 | [diff] [blame] | 5742 | return TestGroupId("a", 443, url::kHttpsScheme); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 5743 | } |
| 5744 | |
David Benjamin | 6dd7e88 | 2019-10-10 02:35:23 | [diff] [blame] | 5745 | static ClientSocketPool::GroupId GetGroupIdInPartition() { |
| 5746 | // Note this GroupId will match GetGroupId() unless |
| 5747 | // kPartitionConnectionsByNetworkIsolationKey is enabled. |
Matt Menke | 4807a9a | 2020-11-21 00:14:41 | [diff] [blame] | 5748 | const SchemefulSite kSite(GURL("https://b/")); |
| 5749 | const NetworkIsolationKey kNetworkIsolationKey(kSite, kSite); |
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, |
| 5752 | kNetworkIsolationKey); |
| 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 |