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

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

Issue 8836002: Revert 113300 - Revert of 112134 of Revert 112130 - Close idle connections / SPDY sessions when n... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: 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 implementation. 64 // Socket implementation.
53 virtual int Read( 65 virtual int Read(
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 connect_job_factory) {} 423 connect_job_factory) {}
412 424
413 virtual ~TestClientSocketPool() {} 425 virtual ~TestClientSocketPool() {}
414 426
415 virtual int RequestSocket( 427 virtual int RequestSocket(
416 const std::string& group_name, 428 const std::string& group_name,
417 const void* params, 429 const void* params,
418 net::RequestPriority priority, 430 net::RequestPriority priority,
419 ClientSocketHandle* handle, 431 ClientSocketHandle* handle,
420 OldCompletionCallback* callback, 432 OldCompletionCallback* callback,
421 const BoundNetLog& net_log) { 433 const BoundNetLog& net_log) OVERRIDE {
422 const scoped_refptr<TestSocketParams>* casted_socket_params = 434 const scoped_refptr<TestSocketParams>* casted_socket_params =
423 static_cast<const scoped_refptr<TestSocketParams>*>(params); 435 static_cast<const scoped_refptr<TestSocketParams>*>(params);
424 return base_.RequestSocket(group_name, *casted_socket_params, priority, 436 return base_.RequestSocket(group_name, *casted_socket_params, priority,
425 handle, callback, net_log); 437 handle, callback, net_log);
426 } 438 }
427 439
428 virtual void RequestSockets(const std::string& group_name, 440 virtual void RequestSockets(const std::string& group_name,
429 const void* params, 441 const void* params,
430 int num_sockets, 442 int num_sockets,
431 const BoundNetLog& net_log) { 443 const BoundNetLog& net_log) OVERRIDE {
432 const scoped_refptr<TestSocketParams>* casted_params = 444 const scoped_refptr<TestSocketParams>* casted_params =
433 static_cast<const scoped_refptr<TestSocketParams>*>(params); 445 static_cast<const scoped_refptr<TestSocketParams>*>(params);
434 446
435 base_.RequestSockets(group_name, *casted_params, num_sockets, net_log); 447 base_.RequestSockets(group_name, *casted_params, num_sockets, net_log);
436 } 448 }
437 449
438 virtual void CancelRequest( 450 virtual void CancelRequest(
439 const std::string& group_name, 451 const std::string& group_name,
440 ClientSocketHandle* handle) { 452 ClientSocketHandle* handle) OVERRIDE {
441 base_.CancelRequest(group_name, handle); 453 base_.CancelRequest(group_name, handle);
442 } 454 }
443 455
444 virtual void ReleaseSocket( 456 virtual void ReleaseSocket(
445 const std::string& group_name, 457 const std::string& group_name,
446 StreamSocket* socket, 458 StreamSocket* socket,
447 int id) { 459 int id) OVERRIDE {
448 base_.ReleaseSocket(group_name, socket, id); 460 base_.ReleaseSocket(group_name, socket, id);
449 } 461 }
450 462
451 virtual void Flush() { 463 virtual void Flush() OVERRIDE {
452 base_.Flush(); 464 base_.Flush();
453 } 465 }
454 466
455 virtual void CloseIdleSockets() { 467 virtual bool IsStalled() const OVERRIDE {
468 return base_.IsStalled();
469 }
470
471 virtual void CloseIdleSockets() OVERRIDE {
456 base_.CloseIdleSockets(); 472 base_.CloseIdleSockets();
457 } 473 }
458 474
459 virtual int IdleSocketCount() const { return base_.idle_socket_count(); } 475 virtual int IdleSocketCount() const OVERRIDE {
476 return base_.idle_socket_count();
477 }
460 478
461 virtual int IdleSocketCountInGroup(const std::string& group_name) const { 479 virtual int IdleSocketCountInGroup(
480 const std::string& group_name) const OVERRIDE {
462 return base_.IdleSocketCountInGroup(group_name); 481 return base_.IdleSocketCountInGroup(group_name);
463 } 482 }
464 483
465 virtual LoadState GetLoadState(const std::string& group_name, 484 virtual LoadState GetLoadState(
466 const ClientSocketHandle* handle) const { 485 const std::string& group_name,
486 const ClientSocketHandle* handle) const OVERRIDE {
467 return base_.GetLoadState(group_name, handle); 487 return base_.GetLoadState(group_name, handle);
468 } 488 }
469 489
470 virtual DictionaryValue* GetInfoAsValue(const std::string& name, 490 virtual void AddLayeredPool(LayeredPool* pool) OVERRIDE {
471 const std::string& type, 491 base_.AddLayeredPool(pool);
472 bool include_nested_pools) const { 492 }
493
494 virtual void RemoveLayeredPool(LayeredPool* pool) OVERRIDE {
495 base_.RemoveLayeredPool(pool);
496 }
497
498 virtual DictionaryValue* GetInfoAsValue(
499 const std::string& name,
500 const std::string& type,
501 bool include_nested_pools) const OVERRIDE {
473 return base_.GetInfoAsValue(name, type); 502 return base_.GetInfoAsValue(name, type);
474 } 503 }
475 504
476 virtual base::TimeDelta ConnectionTimeout() const { 505 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE {
477 return base_.ConnectionTimeout(); 506 return base_.ConnectionTimeout();
478 } 507 }
479 508
480 virtual ClientSocketPoolHistograms* histograms() const { 509 virtual ClientSocketPoolHistograms* histograms() const OVERRIDE {
481 return base_.histograms(); 510 return base_.histograms();
482 } 511 }
483 512
484 const TestClientSocketPoolBase* base() const { return &base_; } 513 const TestClientSocketPoolBase* base() const { return &base_; }
485 514
486 int NumConnectJobsInGroup(const std::string& group_name) const { 515 int NumConnectJobsInGroup(const std::string& group_name) const {
487 return base_.NumConnectJobsInGroup(group_name); 516 return base_.NumConnectJobsInGroup(group_name);
488 } 517 }
489 518
490 int NumActiveSocketsInGroup(const std::string& group_name) const { 519 int NumActiveSocketsInGroup(const std::string& group_name) const {
491 return base_.NumActiveSocketsInGroup(group_name); 520 return base_.NumActiveSocketsInGroup(group_name);
492 } 521 }
493 522
494 bool HasGroup(const std::string& group_name) const { 523 bool HasGroup(const std::string& group_name) const {
495 return base_.HasGroup(group_name); 524 return base_.HasGroup(group_name);
496 } 525 }
497 526
498 void CleanupTimedOutIdleSockets() { base_.CleanupIdleSockets(false); } 527 void CleanupTimedOutIdleSockets() { base_.CleanupIdleSockets(false); }
499 528
500 void EnableConnectBackupJobs() { base_.EnableConnectBackupJobs(); } 529 void EnableConnectBackupJobs() { base_.EnableConnectBackupJobs(); }
501 530
531 bool CloseOneIdleConnectionInLayeredPool() {
532 return base_.CloseOneIdleConnectionInLayeredPool();
533 }
534
502 private: 535 private:
503 TestClientSocketPoolBase base_; 536 TestClientSocketPoolBase base_;
504 537
505 DISALLOW_COPY_AND_ASSIGN(TestClientSocketPool); 538 DISALLOW_COPY_AND_ASSIGN(TestClientSocketPool);
506 }; 539 };
507 540
508 } // namespace 541 } // namespace
509 542
510 REGISTER_SOCKET_PARAMS_FOR_POOL(TestClientSocketPool, TestSocketParams); 543 REGISTER_SOCKET_PARAMS_FOR_POOL(TestClientSocketPool, TestSocketParams);
511 544
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 EXPECT_EQ(1, pool_->IdleSocketCount()); 1190 EXPECT_EQ(1, pool_->IdleSocketCount());
1158 } 1191 }
1159 1192
1160 TEST_F(ClientSocketPoolBaseTest, WaitForStalledSocketAtSocketLimit) { 1193 TEST_F(ClientSocketPoolBaseTest, WaitForStalledSocketAtSocketLimit) {
1161 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 1194 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
1162 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); 1195 connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
1163 1196
1164 ClientSocketHandle stalled_handle; 1197 ClientSocketHandle stalled_handle;
1165 TestOldCompletionCallback callback; 1198 TestOldCompletionCallback callback;
1166 { 1199 {
1200 EXPECT_FALSE(pool_->IsStalled());
1167 ClientSocketHandle handles[kDefaultMaxSockets]; 1201 ClientSocketHandle handles[kDefaultMaxSockets];
1168 for (int i = 0; i < kDefaultMaxSockets; ++i) { 1202 for (int i = 0; i < kDefaultMaxSockets; ++i) {
1169 TestOldCompletionCallback callback; 1203 TestOldCompletionCallback callback;
1170 EXPECT_EQ(OK, handles[i].Init(base::StringPrintf( 1204 EXPECT_EQ(OK, handles[i].Init(base::StringPrintf(
1171 "Take 2: %d", i), 1205 "Take 2: %d", i),
1172 params_, 1206 params_,
1173 kDefaultPriority, 1207 kDefaultPriority,
1174 &callback, 1208 &callback,
1175 pool_.get(), 1209 pool_.get(),
1176 BoundNetLog())); 1210 BoundNetLog()));
1177 } 1211 }
1178 1212
1179 EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count()); 1213 EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count());
1180 EXPECT_EQ(0, pool_->IdleSocketCount()); 1214 EXPECT_EQ(0, pool_->IdleSocketCount());
1215 EXPECT_FALSE(pool_->IsStalled());
1181 1216
1182 // Now we will hit the socket limit. 1217 // Now we will hit the socket limit.
1183 EXPECT_EQ(ERR_IO_PENDING, stalled_handle.Init("foo", 1218 EXPECT_EQ(ERR_IO_PENDING, stalled_handle.Init("foo",
1184 params_, 1219 params_,
1185 kDefaultPriority, 1220 kDefaultPriority,
1186 &callback, 1221 &callback,
1187 pool_.get(), 1222 pool_.get(),
1188 BoundNetLog())); 1223 BoundNetLog()));
1224 EXPECT_TRUE(pool_->IsStalled());
1189 1225
1190 // Dropping out of scope will close all handles and return them to idle. 1226 // Dropping out of scope will close all handles and return them to idle.
1191 } 1227 }
1192 1228
1193 // But if we wait for it, the released idle sockets will be closed in 1229 // But if we wait for it, the released idle sockets will be closed in
1194 // preference of the waiting request. 1230 // preference of the waiting request.
1195 EXPECT_EQ(OK, callback.WaitForResult()); 1231 EXPECT_EQ(OK, callback.WaitForResult());
1196 1232
1197 EXPECT_EQ(kDefaultMaxSockets + 1, client_socket_factory_.allocation_count()); 1233 EXPECT_EQ(kDefaultMaxSockets + 1, client_socket_factory_.allocation_count());
1198 EXPECT_EQ(3, pool_->IdleSocketCount()); 1234 EXPECT_EQ(3, pool_->IdleSocketCount());
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after
1997 // job. Release the socket. Run the loop again to make sure the second 2033 // job. Release the socket. Run the loop again to make sure the second
1998 // socket is sitting idle and the first one is released (since ReleaseSocket() 2034 // socket is sitting idle and the first one is released (since ReleaseSocket()
1999 // just posts a DoReleaseSocket() task). 2035 // just posts a DoReleaseSocket() task).
2000 2036
2001 handle.Reset(); 2037 handle.Reset();
2002 EXPECT_EQ(OK, callback2.WaitForResult()); 2038 EXPECT_EQ(OK, callback2.WaitForResult());
2003 // Use the socket. 2039 // Use the socket.
2004 EXPECT_EQ(1, handle2.socket()->Write(NULL, 1, NULL)); 2040 EXPECT_EQ(1, handle2.socket()->Write(NULL, 1, NULL));
2005 handle2.Reset(); 2041 handle2.Reset();
2006 2042
2007 // The idle socket timeout value was set to 10 milliseconds. Wait 20 2043 // The idle socket timeout value was set to 10 milliseconds. Wait 100
2008 // milliseconds so the sockets timeout. 2044 // milliseconds so the sockets timeout.
2009 base::PlatformThread::Sleep(20); 2045 base::PlatformThread::Sleep(100);
2010 MessageLoop::current()->RunAllPending(); 2046 MessageLoop::current()->RunAllPending();
2011 2047
2012 ASSERT_EQ(2, pool_->IdleSocketCount()); 2048 ASSERT_EQ(2, pool_->IdleSocketCount());
2013 2049
2014 // Request a new socket. This should cleanup the unused and timed out ones. 2050 // Request a new socket. This should cleanup the unused and timed out ones.
2015 // A new socket will be created rather than reusing the idle one. 2051 // A new socket will be created rather than reusing the idle one.
2016 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 2052 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
2017 rv = handle.Init("a", 2053 rv = handle.Init("a",
2018 params_, 2054 params_,
2019 LOWEST, 2055 LOWEST,
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after
3026 CreatePool(kDefaultMaxSockets, kDefaultMaxSockets); 3062 CreatePool(kDefaultMaxSockets, kDefaultMaxSockets);
3027 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); 3063 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
3028 3064
3029 ASSERT_FALSE(pool_->HasGroup("a")); 3065 ASSERT_FALSE(pool_->HasGroup("a"));
3030 3066
3031 pool_->RequestSockets("a", &params_, kDefaultMaxSockets - 1, 3067 pool_->RequestSockets("a", &params_, kDefaultMaxSockets - 1,
3032 BoundNetLog()); 3068 BoundNetLog());
3033 3069
3034 ASSERT_TRUE(pool_->HasGroup("a")); 3070 ASSERT_TRUE(pool_->HasGroup("a"));
3035 EXPECT_EQ(kDefaultMaxSockets - 1, pool_->NumConnectJobsInGroup("a")); 3071 EXPECT_EQ(kDefaultMaxSockets - 1, pool_->NumConnectJobsInGroup("a"));
3072 EXPECT_FALSE(pool_->IsStalled());
3036 3073
3037 ASSERT_FALSE(pool_->HasGroup("b")); 3074 ASSERT_FALSE(pool_->HasGroup("b"));
3038 3075
3039 pool_->RequestSockets("b", &params_, kDefaultMaxSockets, 3076 pool_->RequestSockets("b", &params_, kDefaultMaxSockets,
3040 BoundNetLog()); 3077 BoundNetLog());
3041 3078
3042 ASSERT_TRUE(pool_->HasGroup("b")); 3079 ASSERT_TRUE(pool_->HasGroup("b"));
3043 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("b")); 3080 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("b"));
3081 EXPECT_FALSE(pool_->IsStalled());
3044 } 3082 }
3045 3083
3046 TEST_F(ClientSocketPoolBaseTest, RequestSocketsCountIdleSockets) { 3084 TEST_F(ClientSocketPoolBaseTest, RequestSocketsCountIdleSockets) {
3047 CreatePool(4, 4); 3085 CreatePool(4, 4);
3048 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); 3086 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
3049 3087
3050 ClientSocketHandle handle1; 3088 ClientSocketHandle handle1;
3051 TestOldCompletionCallback callback1; 3089 TestOldCompletionCallback callback1;
3052 EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a", 3090 EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a",
3053 params_, 3091 params_,
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
3352 EXPECT_EQ(0, pool_->NumActiveSocketsInGroup("a")); 3390 EXPECT_EQ(0, pool_->NumActiveSocketsInGroup("a"));
3353 ASSERT_EQ(OK, callback.WaitForResult()); 3391 ASSERT_EQ(OK, callback.WaitForResult());
3354 3392
3355 // The hung connect job should still be there, but everything else should be 3393 // The hung connect job should still be there, but everything else should be
3356 // complete. 3394 // complete.
3357 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); 3395 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
3358 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); 3396 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a"));
3359 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); 3397 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a"));
3360 } 3398 }
3361 3399
3400 class MockLayeredPool : public LayeredPool {
3401 public:
3402 MockLayeredPool(TestClientSocketPool* pool,
3403 const std::string& group_name)
3404 : pool_(pool),
3405 params_(new TestSocketParams),
3406 group_name_(group_name) {
3407 pool_->AddLayeredPool(this);
3408 }
3409
3410 ~MockLayeredPool() {
3411 pool_->RemoveLayeredPool(this);
3412 }
3413
3414 int RequestSocket(TestClientSocketPool* pool) {
3415 return handle_.Init(group_name_, params_, kDefaultPriority, &callback_,
3416 pool, BoundNetLog());
3417 }
3418
3419 int RequestSocketWithoutLimits(TestClientSocketPool* pool) {
3420 params_->set_ignore_limits(true);
3421 return handle_.Init(group_name_, params_, kDefaultPriority, &callback_,
3422 pool, BoundNetLog());
3423 }
3424
3425 bool ReleaseOneConnection() {
3426 if (!handle_.is_initialized()) {
3427 return false;
3428 }
3429 handle_.socket()->Disconnect();
3430 handle_.Reset();
3431 return true;
3432 }
3433
3434 MOCK_METHOD0(CloseOneIdleConnection, bool());
3435
3436 private:
3437 TestClientSocketPool* const pool_;
3438 scoped_refptr<TestSocketParams> params_;
3439 ClientSocketHandle handle_;
3440 TestOldCompletionCallback callback_;
3441 const std::string group_name_;
3442 };
3443
3444 TEST_F(ClientSocketPoolBaseTest, FailToCloseIdleSocketsNotHeldByLayeredPool) {
3445 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
3446 connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
3447
3448 MockLayeredPool mock_layered_pool(pool_.get(), "foo");
3449 EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection())
3450 .WillOnce(Return(false));
3451 EXPECT_EQ(OK, mock_layered_pool.RequestSocket(pool_.get()));
3452 EXPECT_FALSE(pool_->CloseOneIdleConnectionInLayeredPool());
3453 }
3454
3455 TEST_F(ClientSocketPoolBaseTest, ForciblyCloseIdleSocketsHeldByLayeredPool) {
3456 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
3457 connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
3458
3459 MockLayeredPool mock_layered_pool(pool_.get(), "foo");
3460 EXPECT_EQ(OK, mock_layered_pool.RequestSocket(pool_.get()));
3461 EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection())
3462 .WillOnce(Invoke(&mock_layered_pool,
3463 &MockLayeredPool::ReleaseOneConnection));
3464 EXPECT_TRUE(pool_->CloseOneIdleConnectionInLayeredPool());
3465 }
3466
3467 TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketsHeldByLayeredPoolWhenNeeded) {
3468 CreatePool(1, 1);
3469 connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
3470
3471 MockLayeredPool mock_layered_pool(pool_.get(), "foo");
3472 EXPECT_EQ(OK, mock_layered_pool.RequestSocket(pool_.get()));
3473 EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection())
3474 .WillOnce(Invoke(&mock_layered_pool,
3475 &MockLayeredPool::ReleaseOneConnection));
3476 ClientSocketHandle handle;
3477 TestOldCompletionCallback callback;
3478 EXPECT_EQ(OK, handle.Init("a",
3479 params_,
3480 kDefaultPriority,
3481 &callback,
3482 pool_.get(),
3483 BoundNetLog()));
3484 }
3485
3486 TEST_F(ClientSocketPoolBaseTest,
3487 CloseMultipleIdleSocketsHeldByLayeredPoolWhenNeeded) {
3488 CreatePool(1, 1);
3489 connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
3490
3491 MockLayeredPool mock_layered_pool1(pool_.get(), "foo");
3492 EXPECT_EQ(OK, mock_layered_pool1.RequestSocket(pool_.get()));
3493 EXPECT_CALL(mock_layered_pool1, CloseOneIdleConnection())
3494 .WillRepeatedly(Invoke(&mock_layered_pool1,
3495 &MockLayeredPool::ReleaseOneConnection));
3496 MockLayeredPool mock_layered_pool2(pool_.get(), "bar");
3497 EXPECT_EQ(OK, mock_layered_pool2.RequestSocketWithoutLimits(pool_.get()));
3498 EXPECT_CALL(mock_layered_pool2, CloseOneIdleConnection())
3499 .WillRepeatedly(Invoke(&mock_layered_pool2,
3500 &MockLayeredPool::ReleaseOneConnection));
3501 ClientSocketHandle handle;
3502 TestOldCompletionCallback callback;
3503 EXPECT_EQ(OK, handle.Init("a",
3504 params_,
3505 kDefaultPriority,
3506 &callback,
3507 pool_.get(),
3508 BoundNetLog()));
3509 }
3510
3362 } // namespace 3511 } // namespace
3363 3512
3364 } // namespace net 3513 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698