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

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

Issue 8340012: Close idle connections / SPDY sessions when needed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests. Created 9 years 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/socket/client_socket_pool_base.h" 5 #include "net/socket/client_socket_pool_base.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
14 #include "base/threading/platform_thread.h" 14 #include "base/threading/platform_thread.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
17 #include "net/base/net_log.h" 17 #include "net/base/net_log.h"
18 #include "net/base/net_log_unittest.h" 18 #include "net/base/net_log_unittest.h"
19 #include "net/base/request_priority.h" 19 #include "net/base/request_priority.h"
20 #include "net/base/test_completion_callback.h" 20 #include "net/base/test_completion_callback.h"
21 #include "net/http/http_response_headers.h" 21 #include "net/http/http_response_headers.h"
22 #include "net/socket/client_socket_factory.h" 22 #include "net/socket/client_socket_factory.h"
23 #include "net/socket/client_socket_handle.h" 23 #include "net/socket/client_socket_handle.h"
24 #include "net/socket/client_socket_pool_histograms.h" 24 #include "net/socket/client_socket_pool_histograms.h"
25 #include "net/socket/socket_test_util.h" 25 #include "net/socket/socket_test_util.h"
26 #include "net/socket/ssl_host_info.h" 26 #include "net/socket/ssl_host_info.h"
27 #include "net/socket/stream_socket.h" 27 #include "net/socket/stream_socket.h"
28 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
29 30
31 using ::testing::Invoke;
32 using ::testing::Return;
33
30 namespace net { 34 namespace net {
31 35
32 namespace { 36 namespace {
33 37
34 const int kDefaultMaxSockets = 4; 38 const int kDefaultMaxSockets = 4;
35 const int kDefaultMaxSocketsPerGroup = 2; 39 const int kDefaultMaxSocketsPerGroup = 2;
36 const net::RequestPriority kDefaultPriority = MEDIUM; 40 const net::RequestPriority kDefaultPriority = MEDIUM;
37 41
38 class TestSocketParams : public base::RefCounted<TestSocketParams> { 42 class TestSocketParams : public base::RefCounted<TestSocketParams> {
39 public: 43 public:
40 bool ignore_limits() { return false; } 44 TestSocketParams() : ignore_limits_(false) {}
45
46 void set_ignore_limits(bool ignore_limits) {
47 ignore_limits_ = ignore_limits;
48 }
49 bool ignore_limits() { return ignore_limits_; }
50
41 private: 51 private:
42 friend class base::RefCounted<TestSocketParams>; 52 friend class base::RefCounted<TestSocketParams>;
43 ~TestSocketParams() {} 53 ~TestSocketParams() {}
54
55 bool ignore_limits_;
44 }; 56 };
45 typedef ClientSocketPoolBase<TestSocketParams> TestClientSocketPoolBase; 57 typedef ClientSocketPoolBase<TestSocketParams> TestClientSocketPoolBase;
46 58
47 class MockClientSocket : public StreamSocket { 59 class MockClientSocket : public StreamSocket {
48 public: 60 public:
49 MockClientSocket() : connected_(false), was_used_to_convey_data_(false), 61 MockClientSocket() : connected_(false), was_used_to_convey_data_(false),
50 num_bytes_read_(0) {} 62 num_bytes_read_(0) {}
51 63
52 // Socket methods: 64 // Socket methods:
53 virtual int Read( 65 virtual int Read(
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 ClientSocketPoolHistograms* histograms, 410 ClientSocketPoolHistograms* histograms,
399 base::TimeDelta unused_idle_socket_timeout, 411 base::TimeDelta unused_idle_socket_timeout,
400 base::TimeDelta used_idle_socket_timeout, 412 base::TimeDelta used_idle_socket_timeout,
401 TestClientSocketPoolBase::ConnectJobFactory* connect_job_factory) 413 TestClientSocketPoolBase::ConnectJobFactory* connect_job_factory)
402 : base_(max_sockets, max_sockets_per_group, histograms, 414 : base_(max_sockets, max_sockets_per_group, histograms,
403 unused_idle_socket_timeout, used_idle_socket_timeout, 415 unused_idle_socket_timeout, used_idle_socket_timeout,
404 connect_job_factory) {} 416 connect_job_factory) {}
405 417
406 virtual ~TestClientSocketPool() {} 418 virtual ~TestClientSocketPool() {}
407 419
420 void AddLayeredPool(LayeredPool* pool) {
mmenke 2011/11/28 17:47:14 virtual/OVERRIDE
mmenke 2011/11/28 17:47:14 nit: These two should go in the same place they a
willchan no longer on Chromium 2011/11/29 23:14:52 Done.
willchan no longer on Chromium 2011/11/29 23:14:52 Done.
421 base_.AddLayeredPool(pool);
422 }
423
424 void RemoveLayeredPool(LayeredPool* pool) {
mmenke 2011/11/28 17:47:14 virtual/OVERRIDE
willchan no longer on Chromium 2011/11/29 23:14:52 Done.
425 base_.RemoveLayeredPool(pool);
426 }
427
408 virtual int RequestSocket( 428 virtual int RequestSocket(
409 const std::string& group_name, 429 const std::string& group_name,
410 const void* params, 430 const void* params,
411 net::RequestPriority priority, 431 net::RequestPriority priority,
412 ClientSocketHandle* handle, 432 ClientSocketHandle* handle,
413 OldCompletionCallback* callback, 433 OldCompletionCallback* callback,
414 const BoundNetLog& net_log) { 434 const BoundNetLog& net_log) {
mmenke 2011/11/28 17:47:14 nit: OVERRIDE
willchan no longer on Chromium 2011/11/29 23:14:52 Done.
415 const scoped_refptr<TestSocketParams>* casted_socket_params = 435 const scoped_refptr<TestSocketParams>* casted_socket_params =
416 static_cast<const scoped_refptr<TestSocketParams>*>(params); 436 static_cast<const scoped_refptr<TestSocketParams>*>(params);
417 return base_.RequestSocket(group_name, *casted_socket_params, priority, 437 return base_.RequestSocket(group_name, *casted_socket_params, priority,
418 handle, callback, net_log); 438 handle, callback, net_log);
419 } 439 }
420 440
421 virtual void RequestSockets(const std::string& group_name, 441 virtual void RequestSockets(const std::string& group_name,
422 const void* params, 442 const void* params,
423 int num_sockets, 443 int num_sockets,
424 const BoundNetLog& net_log) { 444 const BoundNetLog& net_log) OVERRIDE {
425 const scoped_refptr<TestSocketParams>* casted_params = 445 const scoped_refptr<TestSocketParams>* casted_params =
426 static_cast<const scoped_refptr<TestSocketParams>*>(params); 446 static_cast<const scoped_refptr<TestSocketParams>*>(params);
427 447
428 base_.RequestSockets(group_name, *casted_params, num_sockets, net_log); 448 base_.RequestSockets(group_name, *casted_params, num_sockets, net_log);
429 } 449 }
430 450
431 virtual void CancelRequest( 451 virtual void CancelRequest(
432 const std::string& group_name, 452 const std::string& group_name,
433 ClientSocketHandle* handle) { 453 ClientSocketHandle* handle) OVERRIDE {
434 base_.CancelRequest(group_name, handle); 454 base_.CancelRequest(group_name, handle);
435 } 455 }
436 456
437 virtual void ReleaseSocket( 457 virtual void ReleaseSocket(
438 const std::string& group_name, 458 const std::string& group_name,
439 StreamSocket* socket, 459 StreamSocket* socket,
440 int id) { 460 int id) OVERRIDE {
441 base_.ReleaseSocket(group_name, socket, id); 461 base_.ReleaseSocket(group_name, socket, id);
442 } 462 }
443 463
444 virtual void Flush() { 464 virtual void Flush() OVERRIDE {
445 base_.Flush(); 465 base_.Flush();
446 } 466 }
447 467
448 virtual void CloseIdleSockets() { 468 virtual bool IsStalled() const OVERRIDE {
469 return base_.IsStalled();
470 }
471
472 virtual void CloseIdleSockets() OVERRIDE {
449 base_.CloseIdleSockets(); 473 base_.CloseIdleSockets();
450 } 474 }
451 475
452 virtual int IdleSocketCount() const { return base_.idle_socket_count(); } 476 virtual int IdleSocketCount() const OVERRIDE {
477 return base_.idle_socket_count();
478 }
453 479
454 virtual int IdleSocketCountInGroup(const std::string& group_name) const { 480 virtual int IdleSocketCountInGroup(
481 const std::string& group_name) const OVERRIDE {
455 return base_.IdleSocketCountInGroup(group_name); 482 return base_.IdleSocketCountInGroup(group_name);
456 } 483 }
457 484
458 virtual LoadState GetLoadState(const std::string& group_name, 485 virtual LoadState GetLoadState(
459 const ClientSocketHandle* handle) const { 486 const std::string& group_name,
487 const ClientSocketHandle* handle) const OVERRIDE {
460 return base_.GetLoadState(group_name, handle); 488 return base_.GetLoadState(group_name, handle);
461 } 489 }
462 490
463 virtual DictionaryValue* GetInfoAsValue(const std::string& name, 491 virtual DictionaryValue* GetInfoAsValue(
464 const std::string& type, 492 const std::string& name,
465 bool include_nested_pools) const { 493 const std::string& type,
494 bool include_nested_pools) const OVERRIDE {
466 return base_.GetInfoAsValue(name, type); 495 return base_.GetInfoAsValue(name, type);
467 } 496 }
468 497
469 virtual base::TimeDelta ConnectionTimeout() const { 498 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE {
470 return base_.ConnectionTimeout(); 499 return base_.ConnectionTimeout();
471 } 500 }
472 501
473 virtual ClientSocketPoolHistograms* histograms() const { 502 virtual ClientSocketPoolHistograms* histograms() const OVERRIDE {
474 return base_.histograms(); 503 return base_.histograms();
475 } 504 }
476 505
477 const TestClientSocketPoolBase* base() const { return &base_; } 506 const TestClientSocketPoolBase* base() const { return &base_; }
478 507
479 int NumConnectJobsInGroup(const std::string& group_name) const { 508 int NumConnectJobsInGroup(const std::string& group_name) const {
480 return base_.NumConnectJobsInGroup(group_name); 509 return base_.NumConnectJobsInGroup(group_name);
481 } 510 }
482 511
483 int NumActiveSocketsInGroup(const std::string& group_name) const { 512 int NumActiveSocketsInGroup(const std::string& group_name) const {
484 return base_.NumActiveSocketsInGroup(group_name); 513 return base_.NumActiveSocketsInGroup(group_name);
485 } 514 }
486 515
487 bool HasGroup(const std::string& group_name) const { 516 bool HasGroup(const std::string& group_name) const {
488 return base_.HasGroup(group_name); 517 return base_.HasGroup(group_name);
489 } 518 }
490 519
491 void CleanupTimedOutIdleSockets() { base_.CleanupIdleSockets(false); } 520 void CleanupTimedOutIdleSockets() { base_.CleanupIdleSockets(false); }
492 521
493 void EnableConnectBackupJobs() { base_.EnableConnectBackupJobs(); } 522 void EnableConnectBackupJobs() { base_.EnableConnectBackupJobs(); }
494 523
524 bool CloseOneIdleConnectionInLayeredPool() {
525 return base_.CloseOneIdleConnectionInLayeredPool();
526 }
527
495 private: 528 private:
496 TestClientSocketPoolBase base_; 529 TestClientSocketPoolBase base_;
497 530
498 DISALLOW_COPY_AND_ASSIGN(TestClientSocketPool); 531 DISALLOW_COPY_AND_ASSIGN(TestClientSocketPool);
499 }; 532 };
500 533
501 } // namespace 534 } // namespace
502 535
503 REGISTER_SOCKET_PARAMS_FOR_POOL(TestClientSocketPool, TestSocketParams); 536 REGISTER_SOCKET_PARAMS_FOR_POOL(TestClientSocketPool, TestSocketParams);
504 537
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 EXPECT_EQ(1, pool_->IdleSocketCount()); 1183 EXPECT_EQ(1, pool_->IdleSocketCount());
1151 } 1184 }
1152 1185
1153 TEST_F(ClientSocketPoolBaseTest, WaitForStalledSocketAtSocketLimit) { 1186 TEST_F(ClientSocketPoolBaseTest, WaitForStalledSocketAtSocketLimit) {
1154 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 1187 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
1155 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); 1188 connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
1156 1189
1157 ClientSocketHandle stalled_handle; 1190 ClientSocketHandle stalled_handle;
1158 TestOldCompletionCallback callback; 1191 TestOldCompletionCallback callback;
1159 { 1192 {
1193 EXPECT_FALSE(pool_->IsStalled());
1160 ClientSocketHandle handles[kDefaultMaxSockets]; 1194 ClientSocketHandle handles[kDefaultMaxSockets];
1161 for (int i = 0; i < kDefaultMaxSockets; ++i) { 1195 for (int i = 0; i < kDefaultMaxSockets; ++i) {
1162 TestOldCompletionCallback callback; 1196 TestOldCompletionCallback callback;
1163 EXPECT_EQ(OK, handles[i].Init(base::StringPrintf( 1197 EXPECT_EQ(OK, handles[i].Init(base::StringPrintf(
1164 "Take 2: %d", i), 1198 "Take 2: %d", i),
1165 params_, 1199 params_,
1166 kDefaultPriority, 1200 kDefaultPriority,
1167 &callback, 1201 &callback,
1168 pool_.get(), 1202 pool_.get(),
1169 BoundNetLog())); 1203 BoundNetLog()));
1170 } 1204 }
1171 1205
1172 EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count()); 1206 EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count());
1173 EXPECT_EQ(0, pool_->IdleSocketCount()); 1207 EXPECT_EQ(0, pool_->IdleSocketCount());
1208 EXPECT_FALSE(pool_->IsStalled());
1174 1209
1175 // Now we will hit the socket limit. 1210 // Now we will hit the socket limit.
1176 EXPECT_EQ(ERR_IO_PENDING, stalled_handle.Init("foo", 1211 EXPECT_EQ(ERR_IO_PENDING, stalled_handle.Init("foo",
1177 params_, 1212 params_,
1178 kDefaultPriority, 1213 kDefaultPriority,
1179 &callback, 1214 &callback,
1180 pool_.get(), 1215 pool_.get(),
1181 BoundNetLog())); 1216 BoundNetLog()));
1217 EXPECT_TRUE(pool_->IsStalled());
1182 1218
1183 // Dropping out of scope will close all handles and return them to idle. 1219 // Dropping out of scope will close all handles and return them to idle.
1184 } 1220 }
1185 1221
1186 // But if we wait for it, the released idle sockets will be closed in 1222 // But if we wait for it, the released idle sockets will be closed in
1187 // preference of the waiting request. 1223 // preference of the waiting request.
1188 EXPECT_EQ(OK, callback.WaitForResult()); 1224 EXPECT_EQ(OK, callback.WaitForResult());
1189 1225
1190 EXPECT_EQ(kDefaultMaxSockets + 1, client_socket_factory_.allocation_count()); 1226 EXPECT_EQ(kDefaultMaxSockets + 1, client_socket_factory_.allocation_count());
1191 EXPECT_EQ(3, pool_->IdleSocketCount()); 1227 EXPECT_EQ(3, pool_->IdleSocketCount());
(...skipping 1827 matching lines...) Expand 10 before | Expand all | Expand 10 after
3019 CreatePool(kDefaultMaxSockets, kDefaultMaxSockets); 3055 CreatePool(kDefaultMaxSockets, kDefaultMaxSockets);
3020 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); 3056 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
3021 3057
3022 ASSERT_FALSE(pool_->HasGroup("a")); 3058 ASSERT_FALSE(pool_->HasGroup("a"));
3023 3059
3024 pool_->RequestSockets("a", &params_, kDefaultMaxSockets - 1, 3060 pool_->RequestSockets("a", &params_, kDefaultMaxSockets - 1,
3025 BoundNetLog()); 3061 BoundNetLog());
3026 3062
3027 ASSERT_TRUE(pool_->HasGroup("a")); 3063 ASSERT_TRUE(pool_->HasGroup("a"));
3028 EXPECT_EQ(kDefaultMaxSockets - 1, pool_->NumConnectJobsInGroup("a")); 3064 EXPECT_EQ(kDefaultMaxSockets - 1, pool_->NumConnectJobsInGroup("a"));
3065 EXPECT_FALSE(pool_->IsStalled());
3029 3066
3030 ASSERT_FALSE(pool_->HasGroup("b")); 3067 ASSERT_FALSE(pool_->HasGroup("b"));
3031 3068
3032 pool_->RequestSockets("b", &params_, kDefaultMaxSockets, 3069 pool_->RequestSockets("b", &params_, kDefaultMaxSockets,
3033 BoundNetLog()); 3070 BoundNetLog());
3034 3071
3035 ASSERT_TRUE(pool_->HasGroup("b")); 3072 ASSERT_TRUE(pool_->HasGroup("b"));
3036 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("b")); 3073 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("b"));
3074 EXPECT_FALSE(pool_->IsStalled());
3037 } 3075 }
3038 3076
3039 TEST_F(ClientSocketPoolBaseTest, RequestSocketsCountIdleSockets) { 3077 TEST_F(ClientSocketPoolBaseTest, RequestSocketsCountIdleSockets) {
3040 CreatePool(4, 4); 3078 CreatePool(4, 4);
3041 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); 3079 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
3042 3080
3043 ClientSocketHandle handle1; 3081 ClientSocketHandle handle1;
3044 TestOldCompletionCallback callback1; 3082 TestOldCompletionCallback callback1;
3045 EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a", 3083 EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a",
3046 params_, 3084 params_,
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
3345 EXPECT_EQ(0, pool_->NumActiveSocketsInGroup("a")); 3383 EXPECT_EQ(0, pool_->NumActiveSocketsInGroup("a"));
3346 ASSERT_EQ(OK, callback.WaitForResult()); 3384 ASSERT_EQ(OK, callback.WaitForResult());
3347 3385
3348 // The hung connect job should still be there, but everything else should be 3386 // The hung connect job should still be there, but everything else should be
3349 // complete. 3387 // complete.
3350 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); 3388 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
3351 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); 3389 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a"));
3352 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); 3390 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a"));
3353 } 3391 }
3354 3392
3393 class MockLayeredPool : public LayeredPool {
3394 public:
3395 MockLayeredPool(TestClientSocketPool* pool,
3396 const std::string& group_name)
3397 : pool_(pool),
3398 params_(new TestSocketParams),
3399 group_name_(group_name) {
3400 pool_->AddLayeredPool(this);
3401 }
3402
3403 ~MockLayeredPool() {
3404 pool_->RemoveLayeredPool(this);
3405 }
3406
3407 int RequestSocket(TestClientSocketPool* pool) {
3408 return handle_.Init(group_name_, params_, kDefaultPriority, &callback_,
3409 pool, BoundNetLog());
3410 }
3411
3412 int RequestSocketWithoutLimits(TestClientSocketPool* pool) {
3413 params_->set_ignore_limits(true);
3414 return handle_.Init(group_name_, params_, kDefaultPriority, &callback_,
3415 pool, BoundNetLog());
3416 }
3417
3418 bool ReleaseOneConnection() {
3419 if (!handle_.is_initialized()) {
3420 return false;
3421 }
3422 handle_.socket()->Disconnect();
3423 handle_.Reset();
3424 return true;
3425 }
3426
3427 MOCK_METHOD0(CloseOneIdleConnection, bool());
3428
3429 private:
3430 TestClientSocketPool* const pool_;
3431 scoped_refptr<TestSocketParams> params_;
3432 ClientSocketHandle handle_;
3433 TestOldCompletionCallback callback_;
3434 const std::string group_name_;
3435 };
3436
3437 TEST_F(ClientSocketPoolBaseTest, FailToCloseIdleSocketsNotHeldByLayeredPool) {
3438 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
3439 connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
3440
3441 MockLayeredPool mock_layered_pool(pool_.get(), "foo");
3442 EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection())
3443 .WillOnce(Return(false));
3444 EXPECT_EQ(OK, mock_layered_pool.RequestSocket(pool_.get()));
3445 EXPECT_FALSE(pool_->CloseOneIdleConnectionInLayeredPool());
3446 }
3447
3448 TEST_F(ClientSocketPoolBaseTest, ForciblyCloseIdleSocketsHeldByLayeredPool) {
3449 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
3450 connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
3451
3452 MockLayeredPool mock_layered_pool(pool_.get(), "foo");
3453 EXPECT_EQ(OK, mock_layered_pool.RequestSocket(pool_.get()));
3454 EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection())
3455 .WillOnce(Invoke(&mock_layered_pool,
3456 &MockLayeredPool::ReleaseOneConnection));
3457 EXPECT_TRUE(pool_->CloseOneIdleConnectionInLayeredPool());
3458 }
3459
3460 TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketsHeldByLayeredPoolWhenNeeded) {
3461 CreatePool(1, 1);
3462 connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
3463
3464 MockLayeredPool mock_layered_pool(pool_.get(), "foo");
3465 EXPECT_EQ(OK, mock_layered_pool.RequestSocket(pool_.get()));
3466 EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection())
3467 .WillOnce(Invoke(&mock_layered_pool,
3468 &MockLayeredPool::ReleaseOneConnection));
3469 ClientSocketHandle handle;
3470 TestOldCompletionCallback callback;
3471 EXPECT_EQ(OK, handle.Init("a",
3472 params_,
3473 kDefaultPriority,
3474 &callback,
3475 pool_.get(),
3476 BoundNetLog()));
3477 }
3478
3479 TEST_F(ClientSocketPoolBaseTest,
3480 CloseMultipleIdleSocketsHeldByLayeredPoolWhenNeeded) {
3481 CreatePool(1, 1);
3482 connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
3483
3484 MockLayeredPool mock_layered_pool1(pool_.get(), "foo");
3485 EXPECT_EQ(OK, mock_layered_pool1.RequestSocket(pool_.get()));
3486 EXPECT_CALL(mock_layered_pool1, CloseOneIdleConnection())
3487 .Times(1).WillRepeatedly(Invoke(&mock_layered_pool1,
3488 &MockLayeredPool::ReleaseOneConnection));
3489 MockLayeredPool mock_layered_pool2(pool_.get(), "bar");
3490 EXPECT_EQ(OK, mock_layered_pool2.RequestSocketWithoutLimits(pool_.get()));
3491 EXPECT_CALL(mock_layered_pool2, CloseOneIdleConnection())
3492 .Times(2).WillRepeatedly(Invoke(&mock_layered_pool2,
3493 &MockLayeredPool::ReleaseOneConnection));
3494 ClientSocketHandle handle;
3495 TestOldCompletionCallback callback;
3496 EXPECT_EQ(OK, handle.Init("a",
3497 params_,
3498 kDefaultPriority,
3499 &callback,
3500 pool_.get(),
3501 BoundNetLog()));
3502 }
3503
3355 } // namespace 3504 } // namespace
3356 3505
3357 } // namespace net 3506 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698