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

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

Issue 11428150: LoadTiming implementation in net, part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix a header or two Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/socket/transport_client_socket_pool.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/socket/transport_client_socket_pool.h" 5 #include "net/socket/transport_client_socket_pool.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/threading/platform_thread.h" 13 #include "base/threading/platform_thread.h"
14 #include "net/base/capturing_net_log.h"
14 #include "net/base/ip_endpoint.h" 15 #include "net/base/ip_endpoint.h"
16 #include "net/base/load_timing_info.h"
15 #include "net/base/mock_host_resolver.h" 17 #include "net/base/mock_host_resolver.h"
16 #include "net/base/net_errors.h" 18 #include "net/base/net_errors.h"
17 #include "net/base/net_util.h" 19 #include "net/base/net_util.h"
18 #include "net/base/test_completion_callback.h" 20 #include "net/base/test_completion_callback.h"
19 #include "net/socket/client_socket_factory.h" 21 #include "net/socket/client_socket_factory.h"
20 #include "net/socket/client_socket_handle.h" 22 #include "net/socket/client_socket_handle.h"
21 #include "net/socket/client_socket_pool_histograms.h" 23 #include "net/socket/client_socket_pool_histograms.h"
22 #include "net/socket/socket_test_util.h" 24 #include "net/socket/socket_test_util.h"
23 #include "net/socket/stream_socket.h" 25 #include "net/socket/stream_socket.h"
24 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
25 27
26 namespace net { 28 namespace net {
27 29
28 using internal::ClientSocketPoolBaseHelper; 30 using internal::ClientSocketPoolBaseHelper;
29 31
30 namespace { 32 namespace {
31 33
32 const int kMaxSockets = 32; 34 const int kMaxSockets = 32;
33 const int kMaxSocketsPerGroup = 6; 35 const int kMaxSocketsPerGroup = 6;
34 const net::RequestPriority kDefaultPriority = LOW; 36 const net::RequestPriority kDefaultPriority = LOW;
35 37
38 // Make sure |handle| sets load times correctly when it has been assigned a
39 // reused socket.
40 void TestLoadTimingInfoConnectedReused(const ClientSocketHandle& handle) {
41 LoadTimingInfo load_timing_info;
42 // Only pass true in as |is_reused|, as in general, HttpStream types should
43 // have stricter concepts of reuse than socket pools.
44 EXPECT_TRUE(handle.GetLoadTimingInfo(true, &load_timing_info));
45
46 EXPECT_TRUE(load_timing_info.socket_reused);
47 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id);
48
49 EXPECT_TRUE(load_timing_info.connect_timing.connect_start.is_null());
50 EXPECT_TRUE(load_timing_info.connect_timing.connect_end.is_null());
51 EXPECT_TRUE(load_timing_info.connect_timing.dns_start.is_null());
52 EXPECT_TRUE(load_timing_info.connect_timing.dns_end.is_null());
53 EXPECT_TRUE(load_timing_info.connect_timing.ssl_start.is_null());
54 EXPECT_TRUE(load_timing_info.connect_timing.ssl_end.is_null());
55 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null());
56 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null());
57 EXPECT_TRUE(load_timing_info.send_start.is_null());
58 EXPECT_TRUE(load_timing_info.send_end.is_null());
59 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null());
60 }
61
62 // Make sure |handle| sets load times correctly when it has been assigned a
63 // fresh socket. Also runs TestLoadTimingInfoConnectedReused, since the owner
64 // of a connection where |is_reused| is false may consider the connection
65 // reused.
66 void TestLoadTimingInfoConnectedNotReused(const ClientSocketHandle& handle) {
67 EXPECT_FALSE(handle.is_reused());
68
69 LoadTimingInfo load_timing_info;
70 EXPECT_TRUE(handle.GetLoadTimingInfo(false, &load_timing_info));
71
72 EXPECT_FALSE(load_timing_info.socket_reused);
73 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id);
74
75 EXPECT_FALSE(load_timing_info.connect_timing.dns_start.is_null());
76 EXPECT_LE(load_timing_info.connect_timing.dns_start,
77 load_timing_info.connect_timing.dns_end);
78 EXPECT_LE(load_timing_info.connect_timing.dns_end,
79 load_timing_info.connect_timing.connect_start);
80 EXPECT_LE(load_timing_info.connect_timing.connect_start,
81 load_timing_info.connect_timing.connect_end);
82
83 EXPECT_TRUE(load_timing_info.connect_timing.ssl_start.is_null());
84 EXPECT_TRUE(load_timing_info.connect_timing.ssl_end.is_null());
85 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null());
86 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null());
87 EXPECT_TRUE(load_timing_info.send_start.is_null());
88 EXPECT_TRUE(load_timing_info.send_end.is_null());
89 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null());
90
91 TestLoadTimingInfoConnectedReused(handle);
92 }
93
36 void SetIPv4Address(IPEndPoint* address) { 94 void SetIPv4Address(IPEndPoint* address) {
37 IPAddressNumber number; 95 IPAddressNumber number;
38 CHECK(ParseIPLiteralToNumber("1.1.1.1", &number)); 96 CHECK(ParseIPLiteralToNumber("1.1.1.1", &number));
39 *address = IPEndPoint(number, 80); 97 *address = IPEndPoint(number, 80);
40 } 98 }
41 99
42 void SetIPv6Address(IPEndPoint* address) { 100 void SetIPv6Address(IPEndPoint* address) {
43 IPAddressNumber number; 101 IPAddressNumber number;
44 CHECK(ParseIPLiteralToNumber("1:abcd::3:4:ff", &number)); 102 CHECK(ParseIPLiteralToNumber("1:abcd::3:4:ff", &number));
45 *address = IPEndPoint(number, 80); 103 *address = IPEndPoint(number, 80);
46 } 104 }
47 105
48 class MockClientSocket : public StreamSocket { 106 class MockClientSocket : public StreamSocket {
49 public: 107 public:
50 MockClientSocket(const AddressList& addrlist) 108 MockClientSocket(const AddressList& addrlist, net::NetLog* net_log)
51 : connected_(false), 109 : connected_(false),
52 addrlist_(addrlist) {} 110 addrlist_(addrlist),
111 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) {
112 }
53 113
54 // StreamSocket implementation. 114 // StreamSocket implementation.
55 virtual int Connect(const CompletionCallback& callback) { 115 virtual int Connect(const CompletionCallback& callback) {
56 connected_ = true; 116 connected_ = true;
57 return OK; 117 return OK;
58 } 118 }
59 virtual void Disconnect() { 119 virtual void Disconnect() {
60 connected_ = false; 120 connected_ = false;
61 } 121 }
62 virtual bool IsConnected() const { 122 virtual bool IsConnected() const {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 virtual bool SetSendBufferSize(int32 size) { return true; } 172 virtual bool SetSendBufferSize(int32 size) { return true; }
113 173
114 private: 174 private:
115 bool connected_; 175 bool connected_;
116 const AddressList addrlist_; 176 const AddressList addrlist_;
117 BoundNetLog net_log_; 177 BoundNetLog net_log_;
118 }; 178 };
119 179
120 class MockFailingClientSocket : public StreamSocket { 180 class MockFailingClientSocket : public StreamSocket {
121 public: 181 public:
122 MockFailingClientSocket(const AddressList& addrlist) : addrlist_(addrlist) {} 182 MockFailingClientSocket(const AddressList& addrlist, net::NetLog* net_log)
183 : addrlist_(addrlist),
184 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) {
185 }
123 186
124 // StreamSocket implementation. 187 // StreamSocket implementation.
125 virtual int Connect(const CompletionCallback& callback) { 188 virtual int Connect(const CompletionCallback& callback) {
126 return ERR_CONNECTION_FAILED; 189 return ERR_CONNECTION_FAILED;
127 } 190 }
128 191
129 virtual void Disconnect() {} 192 virtual void Disconnect() {}
130 193
131 virtual bool IsConnected() const { 194 virtual bool IsConnected() const {
132 return false; 195 return false;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 class MockPendingClientSocket : public StreamSocket { 246 class MockPendingClientSocket : public StreamSocket {
184 public: 247 public:
185 // |should_connect| indicates whether the socket should successfully complete 248 // |should_connect| indicates whether the socket should successfully complete
186 // or fail. 249 // or fail.
187 // |should_stall| indicates that this socket should never connect. 250 // |should_stall| indicates that this socket should never connect.
188 // |delay_ms| is the delay, in milliseconds, before simulating a connect. 251 // |delay_ms| is the delay, in milliseconds, before simulating a connect.
189 MockPendingClientSocket( 252 MockPendingClientSocket(
190 const AddressList& addrlist, 253 const AddressList& addrlist,
191 bool should_connect, 254 bool should_connect,
192 bool should_stall, 255 bool should_stall,
193 base::TimeDelta delay) 256 base::TimeDelta delay,
257 net::NetLog* net_log)
194 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 258 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
195 should_connect_(should_connect), 259 should_connect_(should_connect),
196 should_stall_(should_stall), 260 should_stall_(should_stall),
197 delay_(delay), 261 delay_(delay),
198 is_connected_(false), 262 is_connected_(false),
199 addrlist_(addrlist) {} 263 addrlist_(addrlist),
264 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) {
265 }
200 266
201 // StreamSocket implementation. 267 // StreamSocket implementation.
202 virtual int Connect(const CompletionCallback& callback) { 268 virtual int Connect(const CompletionCallback& callback) {
203 MessageLoop::current()->PostDelayedTask( 269 MessageLoop::current()->PostDelayedTask(
204 FROM_HERE, 270 FROM_HERE,
205 base::Bind(&MockPendingClientSocket::DoCallback, 271 base::Bind(&MockPendingClientSocket::DoCallback,
206 weak_factory_.GetWeakPtr(), callback), 272 weak_factory_.GetWeakPtr(), callback),
207 delay_); 273 delay_);
208 return ERR_IO_PENDING; 274 return ERR_IO_PENDING;
209 } 275 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 MOCK_CLIENT_SOCKET, 358 MOCK_CLIENT_SOCKET,
293 MOCK_FAILING_CLIENT_SOCKET, 359 MOCK_FAILING_CLIENT_SOCKET,
294 MOCK_PENDING_CLIENT_SOCKET, 360 MOCK_PENDING_CLIENT_SOCKET,
295 MOCK_PENDING_FAILING_CLIENT_SOCKET, 361 MOCK_PENDING_FAILING_CLIENT_SOCKET,
296 // A delayed socket will pause before connecting through the message loop. 362 // A delayed socket will pause before connecting through the message loop.
297 MOCK_DELAYED_CLIENT_SOCKET, 363 MOCK_DELAYED_CLIENT_SOCKET,
298 // A stalled socket that never connects at all. 364 // A stalled socket that never connects at all.
299 MOCK_STALLED_CLIENT_SOCKET, 365 MOCK_STALLED_CLIENT_SOCKET,
300 }; 366 };
301 367
302 MockClientSocketFactory() 368 explicit MockClientSocketFactory(NetLog* net_log)
303 : allocation_count_(0), client_socket_type_(MOCK_CLIENT_SOCKET), 369 : net_log_(net_log), allocation_count_(0),
304 client_socket_types_(NULL), client_socket_index_(0), 370 client_socket_type_(MOCK_CLIENT_SOCKET), client_socket_types_(NULL),
305 client_socket_index_max_(0), 371 client_socket_index_(0), client_socket_index_max_(0),
306 delay_(base::TimeDelta::FromMilliseconds( 372 delay_(base::TimeDelta::FromMilliseconds(
307 ClientSocketPool::kMaxConnectRetryIntervalMs)) {} 373 ClientSocketPool::kMaxConnectRetryIntervalMs)) {}
308 374
309 virtual DatagramClientSocket* CreateDatagramClientSocket( 375 virtual DatagramClientSocket* CreateDatagramClientSocket(
310 DatagramSocket::BindType bind_type, 376 DatagramSocket::BindType bind_type,
311 const RandIntCallback& rand_int_cb, 377 const RandIntCallback& rand_int_cb,
312 NetLog* net_log, 378 NetLog* net_log,
313 const NetLog::Source& source) { 379 const NetLog::Source& source) {
314 NOTREACHED(); 380 NOTREACHED();
315 return NULL; 381 return NULL;
316 } 382 }
317 383
318 virtual StreamSocket* CreateTransportClientSocket( 384 virtual StreamSocket* CreateTransportClientSocket(
319 const AddressList& addresses, 385 const AddressList& addresses,
320 NetLog* /* net_log */, 386 NetLog* /* net_log */,
321 const NetLog::Source& /* source */) { 387 const NetLog::Source& /* source */) {
322 allocation_count_++; 388 allocation_count_++;
323 389
324 ClientSocketType type = client_socket_type_; 390 ClientSocketType type = client_socket_type_;
325 if (client_socket_types_ && 391 if (client_socket_types_ &&
326 client_socket_index_ < client_socket_index_max_) { 392 client_socket_index_ < client_socket_index_max_) {
327 type = client_socket_types_[client_socket_index_++]; 393 type = client_socket_types_[client_socket_index_++];
328 } 394 }
329 395
330 switch (type) { 396 switch (type) {
331 case MOCK_CLIENT_SOCKET: 397 case MOCK_CLIENT_SOCKET:
332 return new MockClientSocket(addresses); 398 return new MockClientSocket(addresses, net_log_);
333 case MOCK_FAILING_CLIENT_SOCKET: 399 case MOCK_FAILING_CLIENT_SOCKET:
334 return new MockFailingClientSocket(addresses); 400 return new MockFailingClientSocket(addresses, net_log_);
335 case MOCK_PENDING_CLIENT_SOCKET: 401 case MOCK_PENDING_CLIENT_SOCKET:
336 return new MockPendingClientSocket( 402 return new MockPendingClientSocket(
337 addresses, true, false, base::TimeDelta()); 403 addresses, true, false, base::TimeDelta(), net_log_);
338 case MOCK_PENDING_FAILING_CLIENT_SOCKET: 404 case MOCK_PENDING_FAILING_CLIENT_SOCKET:
339 return new MockPendingClientSocket( 405 return new MockPendingClientSocket(
340 addresses, false, false, base::TimeDelta()); 406 addresses, false, false, base::TimeDelta(), net_log_);
341 case MOCK_DELAYED_CLIENT_SOCKET: 407 case MOCK_DELAYED_CLIENT_SOCKET:
342 return new MockPendingClientSocket(addresses, true, false, delay_); 408 return new MockPendingClientSocket(
409 addresses, true, false, delay_, net_log_);
343 case MOCK_STALLED_CLIENT_SOCKET: 410 case MOCK_STALLED_CLIENT_SOCKET:
344 return new MockPendingClientSocket( 411 return new MockPendingClientSocket(
345 addresses, true, true, base::TimeDelta()); 412 addresses, true, true, base::TimeDelta(), net_log_);
346 default: 413 default:
347 NOTREACHED(); 414 NOTREACHED();
348 return new MockClientSocket(addresses); 415 return new MockClientSocket(addresses, net_log_);
349 } 416 }
350 } 417 }
351 418
352 virtual SSLClientSocket* CreateSSLClientSocket( 419 virtual SSLClientSocket* CreateSSLClientSocket(
353 ClientSocketHandle* transport_socket, 420 ClientSocketHandle* transport_socket,
354 const HostPortPair& host_and_port, 421 const HostPortPair& host_and_port,
355 const SSLConfig& ssl_config, 422 const SSLConfig& ssl_config,
356 const SSLClientSocketContext& context) { 423 const SSLClientSocketContext& context) {
357 NOTIMPLEMENTED(); 424 NOTIMPLEMENTED();
358 return NULL; 425 return NULL;
(...skipping 14 matching lines...) Expand all
373 void set_client_socket_types(ClientSocketType* type_list, int num_types) { 440 void set_client_socket_types(ClientSocketType* type_list, int num_types) {
374 DCHECK_GT(num_types, 0); 441 DCHECK_GT(num_types, 0);
375 client_socket_types_ = type_list; 442 client_socket_types_ = type_list;
376 client_socket_index_ = 0; 443 client_socket_index_ = 0;
377 client_socket_index_max_ = num_types; 444 client_socket_index_max_ = num_types;
378 } 445 }
379 446
380 void set_delay(base::TimeDelta delay) { delay_ = delay; } 447 void set_delay(base::TimeDelta delay) { delay_ = delay; }
381 448
382 private: 449 private:
450 NetLog* net_log_;
383 int allocation_count_; 451 int allocation_count_;
384 ClientSocketType client_socket_type_; 452 ClientSocketType client_socket_type_;
385 ClientSocketType* client_socket_types_; 453 ClientSocketType* client_socket_types_;
386 int client_socket_index_; 454 int client_socket_index_;
387 int client_socket_index_max_; 455 int client_socket_index_max_;
388 base::TimeDelta delay_; 456 base::TimeDelta delay_;
389 }; 457 };
390 458
391 class TransportClientSocketPoolTest : public testing::Test { 459 class TransportClientSocketPoolTest : public testing::Test {
392 protected: 460 protected:
393 TransportClientSocketPoolTest() 461 TransportClientSocketPoolTest()
394 : connect_backup_jobs_enabled_( 462 : connect_backup_jobs_enabled_(
395 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(true)), 463 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(true)),
396 params_( 464 params_(
397 new TransportSocketParams(HostPortPair("www.google.com", 80), 465 new TransportSocketParams(HostPortPair("www.google.com", 80),
398 kDefaultPriority, false, false, 466 kDefaultPriority, false, false,
399 OnHostResolutionCallback())), 467 OnHostResolutionCallback())),
400 low_params_( 468 low_params_(
401 new TransportSocketParams(HostPortPair("www.google.com", 80), 469 new TransportSocketParams(HostPortPair("www.google.com", 80),
402 LOW, false, false, 470 LOW, false, false,
403 OnHostResolutionCallback())), 471 OnHostResolutionCallback())),
404 histograms_(new ClientSocketPoolHistograms("TCPUnitTest")), 472 histograms_(new ClientSocketPoolHistograms("TCPUnitTest")),
405 host_resolver_(new MockHostResolver), 473 host_resolver_(new MockHostResolver),
474 client_socket_factory_(&net_log_),
406 pool_(kMaxSockets, 475 pool_(kMaxSockets,
407 kMaxSocketsPerGroup, 476 kMaxSocketsPerGroup,
408 histograms_.get(), 477 histograms_.get(),
409 host_resolver_.get(), 478 host_resolver_.get(),
410 &client_socket_factory_, 479 &client_socket_factory_,
411 NULL) { 480 NULL) {
412 } 481 }
413 482
414 ~TransportClientSocketPoolTest() { 483 ~TransportClientSocketPoolTest() {
415 internal::ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled( 484 internal::ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(
(...skipping 17 matching lines...) Expand all
433 } 502 }
434 503
435 void ReleaseAllConnections(ClientSocketPoolTest::KeepAlive keep_alive) { 504 void ReleaseAllConnections(ClientSocketPoolTest::KeepAlive keep_alive) {
436 test_base_.ReleaseAllConnections(keep_alive); 505 test_base_.ReleaseAllConnections(keep_alive);
437 } 506 }
438 507
439 ScopedVector<TestSocketRequest>* requests() { return test_base_.requests(); } 508 ScopedVector<TestSocketRequest>* requests() { return test_base_.requests(); }
440 size_t completion_count() const { return test_base_.completion_count(); } 509 size_t completion_count() const { return test_base_.completion_count(); }
441 510
442 bool connect_backup_jobs_enabled_; 511 bool connect_backup_jobs_enabled_;
512 CapturingNetLog net_log_;
443 scoped_refptr<TransportSocketParams> params_; 513 scoped_refptr<TransportSocketParams> params_;
444 scoped_refptr<TransportSocketParams> low_params_; 514 scoped_refptr<TransportSocketParams> low_params_;
445 scoped_ptr<ClientSocketPoolHistograms> histograms_; 515 scoped_ptr<ClientSocketPoolHistograms> histograms_;
446 scoped_ptr<MockHostResolver> host_resolver_; 516 scoped_ptr<MockHostResolver> host_resolver_;
447 MockClientSocketFactory client_socket_factory_; 517 MockClientSocketFactory client_socket_factory_;
448 TransportClientSocketPool pool_; 518 TransportClientSocketPool pool_;
449 ClientSocketPoolTest test_base_; 519 ClientSocketPoolTest test_base_;
450 }; 520 };
451 521
452 TEST(TransportConnectJobTest, MakeAddrListStartWithIPv4) { 522 TEST(TransportConnectJobTest, MakeAddrListStartWithIPv4) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 ClientSocketHandle handle; 595 ClientSocketHandle handle;
526 int rv = handle.Init("a", low_params_, LOW, callback.callback(), &pool_, 596 int rv = handle.Init("a", low_params_, LOW, callback.callback(), &pool_,
527 BoundNetLog()); 597 BoundNetLog());
528 EXPECT_EQ(ERR_IO_PENDING, rv); 598 EXPECT_EQ(ERR_IO_PENDING, rv);
529 EXPECT_FALSE(handle.is_initialized()); 599 EXPECT_FALSE(handle.is_initialized());
530 EXPECT_FALSE(handle.socket()); 600 EXPECT_FALSE(handle.socket());
531 601
532 EXPECT_EQ(OK, callback.WaitForResult()); 602 EXPECT_EQ(OK, callback.WaitForResult());
533 EXPECT_TRUE(handle.is_initialized()); 603 EXPECT_TRUE(handle.is_initialized());
534 EXPECT_TRUE(handle.socket()); 604 EXPECT_TRUE(handle.socket());
535 605 TestLoadTimingInfoConnectedNotReused(handle);
536 handle.Reset();
537 } 606 }
538 607
539 TEST_F(TransportClientSocketPoolTest, InitHostResolutionFailure) { 608 TEST_F(TransportClientSocketPoolTest, InitHostResolutionFailure) {
540 host_resolver_->rules()->AddSimulatedFailure("unresolvable.host.name"); 609 host_resolver_->rules()->AddSimulatedFailure("unresolvable.host.name");
541 TestCompletionCallback callback; 610 TestCompletionCallback callback;
542 ClientSocketHandle handle; 611 ClientSocketHandle handle;
543 HostPortPair host_port_pair("unresolvable.host.name", 80); 612 HostPortPair host_port_pair("unresolvable.host.name", 80);
544 scoped_refptr<TransportSocketParams> dest(new TransportSocketParams( 613 scoped_refptr<TransportSocketParams> dest(new TransportSocketParams(
545 host_port_pair, kDefaultPriority, false, false, 614 host_port_pair, kDefaultPriority, false, false,
546 OnHostResolutionCallback())); 615 OnHostResolutionCallback()));
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 ASSERT_LE(kNumRequests, kMaxSockets); // Otherwise the test will hang. 961 ASSERT_LE(kNumRequests, kMaxSockets); // Otherwise the test will hang.
893 962
894 // Queue up all the requests 963 // Queue up all the requests
895 for (int i = 0; i < kNumRequests; i++) 964 for (int i = 0; i < kNumRequests; i++)
896 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); 965 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority));
897 966
898 for (int i = 0; i < kNumRequests; i++) 967 for (int i = 0; i < kNumRequests; i++)
899 EXPECT_EQ(ERR_CONNECTION_FAILED, (*requests())[i]->WaitForResult()); 968 EXPECT_EQ(ERR_CONNECTION_FAILED, (*requests())[i]->WaitForResult());
900 } 969 }
901 970
971 TEST_F(TransportClientSocketPoolTest, IdleSocketLoadTiming) {
972 TestCompletionCallback callback;
973 ClientSocketHandle handle;
974 int rv = handle.Init("a", low_params_, LOW, callback.callback(), &pool_,
975 BoundNetLog());
976 EXPECT_EQ(ERR_IO_PENDING, rv);
977 EXPECT_FALSE(handle.is_initialized());
978 EXPECT_FALSE(handle.socket());
979
980 EXPECT_EQ(OK, callback.WaitForResult());
981 EXPECT_TRUE(handle.is_initialized());
982 EXPECT_TRUE(handle.socket());
983 TestLoadTimingInfoConnectedNotReused(handle);
984
985 handle.Reset();
986 // Need to run all pending to release the socket back to the pool.
987 MessageLoop::current()->RunUntilIdle();
988
989 // Now we should have 1 idle socket.
990 EXPECT_EQ(1, pool_.IdleSocketCount());
991
992 rv = handle.Init("a", low_params_, LOW, callback.callback(), &pool_,
993 BoundNetLog());
994 EXPECT_EQ(OK, rv);
995 EXPECT_EQ(0, pool_.IdleSocketCount());
996 TestLoadTimingInfoConnectedReused(handle);
997 }
998
902 TEST_F(TransportClientSocketPoolTest, ResetIdleSocketsOnIPAddressChange) { 999 TEST_F(TransportClientSocketPoolTest, ResetIdleSocketsOnIPAddressChange) {
903 TestCompletionCallback callback; 1000 TestCompletionCallback callback;
904 ClientSocketHandle handle; 1001 ClientSocketHandle handle;
905 int rv = handle.Init("a", low_params_, LOW, callback.callback(), &pool_, 1002 int rv = handle.Init("a", low_params_, LOW, callback.callback(), &pool_,
906 BoundNetLog()); 1003 BoundNetLog());
907 EXPECT_EQ(ERR_IO_PENDING, rv); 1004 EXPECT_EQ(ERR_IO_PENDING, rv);
908 EXPECT_FALSE(handle.is_initialized()); 1005 EXPECT_FALSE(handle.is_initialized());
909 EXPECT_FALSE(handle.socket()); 1006 EXPECT_FALSE(handle.socket());
910 1007
911 EXPECT_EQ(OK, callback.WaitForResult()); 1008 EXPECT_EQ(OK, callback.WaitForResult());
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 EXPECT_TRUE(handle.socket()); 1371 EXPECT_TRUE(handle.socket());
1275 IPEndPoint endpoint; 1372 IPEndPoint endpoint;
1276 handle.socket()->GetLocalAddress(&endpoint); 1373 handle.socket()->GetLocalAddress(&endpoint);
1277 EXPECT_EQ(kIPv4AddressSize, endpoint.address().size()); 1374 EXPECT_EQ(kIPv4AddressSize, endpoint.address().size());
1278 EXPECT_EQ(1, client_socket_factory_.allocation_count()); 1375 EXPECT_EQ(1, client_socket_factory_.allocation_count());
1279 } 1376 }
1280 1377
1281 } // namespace 1378 } // namespace
1282 1379
1283 } // namespace net 1380 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/transport_client_socket_pool.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698