| OLD | NEW |
| 1 // Copyright (c) 2012 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/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/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 16 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
| 17 #include "base/threading/platform_thread.h" | 17 #include "base/threading/platform_thread.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 20 #include "net/base/net_log.h" | 20 #include "net/base/net_log.h" |
| 21 #include "net/base/net_log_unittest.h" | 21 #include "net/base/net_log_unittest.h" |
| 22 #include "net/base/request_priority.h" | 22 #include "net/base/request_priority.h" |
| 23 #include "net/base/test_completion_callback.h" | 23 #include "net/base/test_completion_callback.h" |
| 24 #include "net/http/http_response_headers.h" | 24 #include "net/http/http_response_headers.h" |
| 25 #include "net/socket/client_socket_factory.h" | 25 #include "net/socket/client_socket_factory.h" |
| 26 #include "net/socket/client_socket_handle.h" | 26 #include "net/socket/client_socket_handle.h" |
| 27 #include "net/socket/client_socket_pool_histograms.h" | 27 #include "net/socket/client_socket_pool_histograms.h" |
| 28 #include "net/socket/socket_test_util.h" | 28 #include "net/socket/socket_test_util.h" |
| 29 #include "net/socket/ssl_host_info.h" | 29 #include "net/socket/ssl_host_info.h" |
| 30 #include "net/socket/stream_socket.h" | 30 #include "net/socket/stream_socket.h" |
| 31 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 32 | 33 |
| 34 using ::testing::Invoke; |
| 35 using ::testing::Return; |
| 36 |
| 33 namespace net { | 37 namespace net { |
| 34 | 38 |
| 35 namespace { | 39 namespace { |
| 36 | 40 |
| 37 const int kDefaultMaxSockets = 4; | 41 const int kDefaultMaxSockets = 4; |
| 38 const int kDefaultMaxSocketsPerGroup = 2; | 42 const int kDefaultMaxSocketsPerGroup = 2; |
| 39 const net::RequestPriority kDefaultPriority = MEDIUM; | 43 const net::RequestPriority kDefaultPriority = MEDIUM; |
| 40 | 44 |
| 41 class TestSocketParams : public base::RefCounted<TestSocketParams> { | 45 class TestSocketParams : public base::RefCounted<TestSocketParams> { |
| 42 public: | 46 public: |
| 43 bool ignore_limits() { return false; } | 47 TestSocketParams() : ignore_limits_(false) {} |
| 48 |
| 49 void set_ignore_limits(bool ignore_limits) { |
| 50 ignore_limits_ = ignore_limits; |
| 51 } |
| 52 bool ignore_limits() { return ignore_limits_; } |
| 53 |
| 44 private: | 54 private: |
| 45 friend class base::RefCounted<TestSocketParams>; | 55 friend class base::RefCounted<TestSocketParams>; |
| 46 ~TestSocketParams() {} | 56 ~TestSocketParams() {} |
| 57 |
| 58 bool ignore_limits_; |
| 47 }; | 59 }; |
| 48 typedef ClientSocketPoolBase<TestSocketParams> TestClientSocketPoolBase; | 60 typedef ClientSocketPoolBase<TestSocketParams> TestClientSocketPoolBase; |
| 49 | 61 |
| 50 class MockClientSocket : public StreamSocket { | 62 class MockClientSocket : public StreamSocket { |
| 51 public: | 63 public: |
| 52 MockClientSocket() : connected_(false), was_used_to_convey_data_(false), | 64 MockClientSocket() : connected_(false), was_used_to_convey_data_(false), |
| 53 num_bytes_read_(0) {} | 65 num_bytes_read_(0) {} |
| 54 | 66 |
| 55 // Socket implementation. | 67 // Socket implementation. |
| 56 virtual int Read( | 68 virtual int Read( |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 const std::string& group_name, | 452 const std::string& group_name, |
| 441 StreamSocket* socket, | 453 StreamSocket* socket, |
| 442 int id) OVERRIDE { | 454 int id) OVERRIDE { |
| 443 base_.ReleaseSocket(group_name, socket, id); | 455 base_.ReleaseSocket(group_name, socket, id); |
| 444 } | 456 } |
| 445 | 457 |
| 446 virtual void Flush() OVERRIDE { | 458 virtual void Flush() OVERRIDE { |
| 447 base_.Flush(); | 459 base_.Flush(); |
| 448 } | 460 } |
| 449 | 461 |
| 462 virtual bool IsStalled() const OVERRIDE { |
| 463 return base_.IsStalled(); |
| 464 } |
| 465 |
| 450 virtual void CloseIdleSockets() OVERRIDE { | 466 virtual void CloseIdleSockets() OVERRIDE { |
| 451 base_.CloseIdleSockets(); | 467 base_.CloseIdleSockets(); |
| 452 } | 468 } |
| 453 | 469 |
| 454 virtual int IdleSocketCount() const OVERRIDE { | 470 virtual int IdleSocketCount() const OVERRIDE { |
| 455 return base_.idle_socket_count(); | 471 return base_.idle_socket_count(); |
| 456 } | 472 } |
| 457 | 473 |
| 458 virtual int IdleSocketCountInGroup( | 474 virtual int IdleSocketCountInGroup( |
| 459 const std::string& group_name) const OVERRIDE { | 475 const std::string& group_name) const OVERRIDE { |
| 460 return base_.IdleSocketCountInGroup(group_name); | 476 return base_.IdleSocketCountInGroup(group_name); |
| 461 } | 477 } |
| 462 | 478 |
| 463 virtual LoadState GetLoadState( | 479 virtual LoadState GetLoadState( |
| 464 const std::string& group_name, | 480 const std::string& group_name, |
| 465 const ClientSocketHandle* handle) const OVERRIDE { | 481 const ClientSocketHandle* handle) const OVERRIDE { |
| 466 return base_.GetLoadState(group_name, handle); | 482 return base_.GetLoadState(group_name, handle); |
| 467 } | 483 } |
| 468 | 484 |
| 485 virtual void AddLayeredPool(LayeredPool* pool) OVERRIDE { |
| 486 base_.AddLayeredPool(pool); |
| 487 } |
| 488 |
| 489 virtual void RemoveLayeredPool(LayeredPool* pool) OVERRIDE { |
| 490 base_.RemoveLayeredPool(pool); |
| 491 } |
| 492 |
| 469 virtual DictionaryValue* GetInfoAsValue( | 493 virtual DictionaryValue* GetInfoAsValue( |
| 470 const std::string& name, | 494 const std::string& name, |
| 471 const std::string& type, | 495 const std::string& type, |
| 472 bool include_nested_pools) const OVERRIDE { | 496 bool include_nested_pools) const OVERRIDE { |
| 473 return base_.GetInfoAsValue(name, type); | 497 return base_.GetInfoAsValue(name, type); |
| 474 } | 498 } |
| 475 | 499 |
| 476 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE { | 500 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE { |
| 477 return base_.ConnectionTimeout(); | 501 return base_.ConnectionTimeout(); |
| 478 } | 502 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 492 } | 516 } |
| 493 | 517 |
| 494 bool HasGroup(const std::string& group_name) const { | 518 bool HasGroup(const std::string& group_name) const { |
| 495 return base_.HasGroup(group_name); | 519 return base_.HasGroup(group_name); |
| 496 } | 520 } |
| 497 | 521 |
| 498 void CleanupTimedOutIdleSockets() { base_.CleanupIdleSockets(false); } | 522 void CleanupTimedOutIdleSockets() { base_.CleanupIdleSockets(false); } |
| 499 | 523 |
| 500 void EnableConnectBackupJobs() { base_.EnableConnectBackupJobs(); } | 524 void EnableConnectBackupJobs() { base_.EnableConnectBackupJobs(); } |
| 501 | 525 |
| 526 bool CloseOneIdleConnectionInLayeredPool() { |
| 527 return base_.CloseOneIdleConnectionInLayeredPool(); |
| 528 } |
| 529 |
| 502 private: | 530 private: |
| 503 TestClientSocketPoolBase base_; | 531 TestClientSocketPoolBase base_; |
| 504 | 532 |
| 505 DISALLOW_COPY_AND_ASSIGN(TestClientSocketPool); | 533 DISALLOW_COPY_AND_ASSIGN(TestClientSocketPool); |
| 506 }; | 534 }; |
| 507 | 535 |
| 508 } // namespace | 536 } // namespace |
| 509 | 537 |
| 510 REGISTER_SOCKET_PARAMS_FOR_POOL(TestClientSocketPool, TestSocketParams); | 538 REGISTER_SOCKET_PARAMS_FOR_POOL(TestClientSocketPool, TestSocketParams); |
| 511 | 539 |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1157 EXPECT_EQ(1, pool_->IdleSocketCount()); | 1185 EXPECT_EQ(1, pool_->IdleSocketCount()); |
| 1158 } | 1186 } |
| 1159 | 1187 |
| 1160 TEST_F(ClientSocketPoolBaseTest, WaitForStalledSocketAtSocketLimit) { | 1188 TEST_F(ClientSocketPoolBaseTest, WaitForStalledSocketAtSocketLimit) { |
| 1161 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1189 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1162 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); | 1190 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 1163 | 1191 |
| 1164 ClientSocketHandle stalled_handle; | 1192 ClientSocketHandle stalled_handle; |
| 1165 TestCompletionCallback callback; | 1193 TestCompletionCallback callback; |
| 1166 { | 1194 { |
| 1195 EXPECT_FALSE(pool_->IsStalled()); |
| 1167 ClientSocketHandle handles[kDefaultMaxSockets]; | 1196 ClientSocketHandle handles[kDefaultMaxSockets]; |
| 1168 for (int i = 0; i < kDefaultMaxSockets; ++i) { | 1197 for (int i = 0; i < kDefaultMaxSockets; ++i) { |
| 1169 TestCompletionCallback callback; | 1198 TestCompletionCallback callback; |
| 1170 EXPECT_EQ(OK, handles[i].Init(base::StringPrintf( | 1199 EXPECT_EQ(OK, handles[i].Init(base::StringPrintf( |
| 1171 "Take 2: %d", i), | 1200 "Take 2: %d", i), |
| 1172 params_, | 1201 params_, |
| 1173 kDefaultPriority, | 1202 kDefaultPriority, |
| 1174 callback.callback(), | 1203 callback.callback(), |
| 1175 pool_.get(), | 1204 pool_.get(), |
| 1176 BoundNetLog())); | 1205 BoundNetLog())); |
| 1177 } | 1206 } |
| 1178 | 1207 |
| 1179 EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count()); | 1208 EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count()); |
| 1180 EXPECT_EQ(0, pool_->IdleSocketCount()); | 1209 EXPECT_EQ(0, pool_->IdleSocketCount()); |
| 1210 EXPECT_FALSE(pool_->IsStalled()); |
| 1181 | 1211 |
| 1182 // Now we will hit the socket limit. | 1212 // Now we will hit the socket limit. |
| 1183 EXPECT_EQ(ERR_IO_PENDING, stalled_handle.Init("foo", | 1213 EXPECT_EQ(ERR_IO_PENDING, stalled_handle.Init("foo", |
| 1184 params_, | 1214 params_, |
| 1185 kDefaultPriority, | 1215 kDefaultPriority, |
| 1186 callback.callback(), | 1216 callback.callback(), |
| 1187 pool_.get(), | 1217 pool_.get(), |
| 1188 BoundNetLog())); | 1218 BoundNetLog())); |
| 1219 EXPECT_TRUE(pool_->IsStalled()); |
| 1189 | 1220 |
| 1190 // Dropping out of scope will close all handles and return them to idle. | 1221 // Dropping out of scope will close all handles and return them to idle. |
| 1191 } | 1222 } |
| 1192 | 1223 |
| 1193 // But if we wait for it, the released idle sockets will be closed in | 1224 // But if we wait for it, the released idle sockets will be closed in |
| 1194 // preference of the waiting request. | 1225 // preference of the waiting request. |
| 1195 EXPECT_EQ(OK, callback.WaitForResult()); | 1226 EXPECT_EQ(OK, callback.WaitForResult()); |
| 1196 | 1227 |
| 1197 EXPECT_EQ(kDefaultMaxSockets + 1, client_socket_factory_.allocation_count()); | 1228 EXPECT_EQ(kDefaultMaxSockets + 1, client_socket_factory_.allocation_count()); |
| 1198 EXPECT_EQ(3, pool_->IdleSocketCount()); | 1229 EXPECT_EQ(3, pool_->IdleSocketCount()); |
| (...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1998 // job. Release the socket. Run the loop again to make sure the second | 2029 // job. Release the socket. Run the loop again to make sure the second |
| 1999 // socket is sitting idle and the first one is released (since ReleaseSocket() | 2030 // socket is sitting idle and the first one is released (since ReleaseSocket() |
| 2000 // just posts a DoReleaseSocket() task). | 2031 // just posts a DoReleaseSocket() task). |
| 2001 | 2032 |
| 2002 handle.Reset(); | 2033 handle.Reset(); |
| 2003 EXPECT_EQ(OK, callback2.WaitForResult()); | 2034 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 2004 // Use the socket. | 2035 // Use the socket. |
| 2005 EXPECT_EQ(1, handle2.socket()->Write(NULL, 1, CompletionCallback())); | 2036 EXPECT_EQ(1, handle2.socket()->Write(NULL, 1, CompletionCallback())); |
| 2006 handle2.Reset(); | 2037 handle2.Reset(); |
| 2007 | 2038 |
| 2008 // The idle socket timeout value was set to 10 milliseconds. Wait 20 | 2039 // The idle socket timeout value was set to 10 milliseconds. Wait 100 |
| 2009 // milliseconds so the sockets timeout. | 2040 // milliseconds so the sockets timeout. |
| 2010 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); | 2041 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); |
| 2011 MessageLoop::current()->RunAllPending(); | 2042 MessageLoop::current()->RunAllPending(); |
| 2012 | 2043 |
| 2013 ASSERT_EQ(2, pool_->IdleSocketCount()); | 2044 ASSERT_EQ(2, pool_->IdleSocketCount()); |
| 2014 | 2045 |
| 2015 // Request a new socket. This should cleanup the unused and timed out ones. | 2046 // Request a new socket. This should cleanup the unused and timed out ones. |
| 2016 // A new socket will be created rather than reusing the idle one. | 2047 // A new socket will be created rather than reusing the idle one. |
| 2017 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 2048 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
| 2018 TestCompletionCallback callback3; | 2049 TestCompletionCallback callback3; |
| 2019 rv = handle.Init("a", | 2050 rv = handle.Init("a", |
| 2020 params_, | 2051 params_, |
| (...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3032 CreatePool(kDefaultMaxSockets, kDefaultMaxSockets); | 3063 CreatePool(kDefaultMaxSockets, kDefaultMaxSockets); |
| 3033 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 3064 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3034 | 3065 |
| 3035 ASSERT_FALSE(pool_->HasGroup("a")); | 3066 ASSERT_FALSE(pool_->HasGroup("a")); |
| 3036 | 3067 |
| 3037 pool_->RequestSockets("a", ¶ms_, kDefaultMaxSockets - 1, | 3068 pool_->RequestSockets("a", ¶ms_, kDefaultMaxSockets - 1, |
| 3038 BoundNetLog()); | 3069 BoundNetLog()); |
| 3039 | 3070 |
| 3040 ASSERT_TRUE(pool_->HasGroup("a")); | 3071 ASSERT_TRUE(pool_->HasGroup("a")); |
| 3041 EXPECT_EQ(kDefaultMaxSockets - 1, pool_->NumConnectJobsInGroup("a")); | 3072 EXPECT_EQ(kDefaultMaxSockets - 1, pool_->NumConnectJobsInGroup("a")); |
| 3073 EXPECT_FALSE(pool_->IsStalled()); |
| 3042 | 3074 |
| 3043 ASSERT_FALSE(pool_->HasGroup("b")); | 3075 ASSERT_FALSE(pool_->HasGroup("b")); |
| 3044 | 3076 |
| 3045 pool_->RequestSockets("b", ¶ms_, kDefaultMaxSockets, | 3077 pool_->RequestSockets("b", ¶ms_, kDefaultMaxSockets, |
| 3046 BoundNetLog()); | 3078 BoundNetLog()); |
| 3047 | 3079 |
| 3048 ASSERT_TRUE(pool_->HasGroup("b")); | 3080 ASSERT_TRUE(pool_->HasGroup("b")); |
| 3049 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("b")); | 3081 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("b")); |
| 3082 EXPECT_FALSE(pool_->IsStalled()); |
| 3050 } | 3083 } |
| 3051 | 3084 |
| 3052 TEST_F(ClientSocketPoolBaseTest, RequestSocketsCountIdleSockets) { | 3085 TEST_F(ClientSocketPoolBaseTest, RequestSocketsCountIdleSockets) { |
| 3053 CreatePool(4, 4); | 3086 CreatePool(4, 4); |
| 3054 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 3087 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3055 | 3088 |
| 3056 ClientSocketHandle handle1; | 3089 ClientSocketHandle handle1; |
| 3057 TestCompletionCallback callback1; | 3090 TestCompletionCallback callback1; |
| 3058 EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a", | 3091 EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a", |
| 3059 params_, | 3092 params_, |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3358 EXPECT_EQ(0, pool_->NumActiveSocketsInGroup("a")); | 3391 EXPECT_EQ(0, pool_->NumActiveSocketsInGroup("a")); |
| 3359 ASSERT_EQ(OK, callback.WaitForResult()); | 3392 ASSERT_EQ(OK, callback.WaitForResult()); |
| 3360 | 3393 |
| 3361 // The hung connect job should still be there, but everything else should be | 3394 // The hung connect job should still be there, but everything else should be |
| 3362 // complete. | 3395 // complete. |
| 3363 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); | 3396 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); |
| 3364 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); | 3397 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); |
| 3365 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); | 3398 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); |
| 3366 } | 3399 } |
| 3367 | 3400 |
| 3401 class MockLayeredPool : public LayeredPool { |
| 3402 public: |
| 3403 MockLayeredPool(TestClientSocketPool* pool, |
| 3404 const std::string& group_name) |
| 3405 : pool_(pool), |
| 3406 params_(new TestSocketParams), |
| 3407 group_name_(group_name) { |
| 3408 pool_->AddLayeredPool(this); |
| 3409 } |
| 3410 |
| 3411 ~MockLayeredPool() { |
| 3412 pool_->RemoveLayeredPool(this); |
| 3413 } |
| 3414 |
| 3415 int RequestSocket(TestClientSocketPool* pool) { |
| 3416 return handle_.Init(group_name_, params_, kDefaultPriority, |
| 3417 callback_.callback(), pool, BoundNetLog()); |
| 3418 } |
| 3419 |
| 3420 int RequestSocketWithoutLimits(TestClientSocketPool* pool) { |
| 3421 params_->set_ignore_limits(true); |
| 3422 return handle_.Init(group_name_, params_, kDefaultPriority, |
| 3423 callback_.callback(), pool, BoundNetLog()); |
| 3424 } |
| 3425 |
| 3426 bool ReleaseOneConnection() { |
| 3427 if (!handle_.is_initialized()) { |
| 3428 return false; |
| 3429 } |
| 3430 handle_.socket()->Disconnect(); |
| 3431 handle_.Reset(); |
| 3432 return true; |
| 3433 } |
| 3434 |
| 3435 MOCK_METHOD0(CloseOneIdleConnection, bool()); |
| 3436 |
| 3437 private: |
| 3438 TestClientSocketPool* const pool_; |
| 3439 scoped_refptr<TestSocketParams> params_; |
| 3440 ClientSocketHandle handle_; |
| 3441 TestCompletionCallback callback_; |
| 3442 const std::string group_name_; |
| 3443 }; |
| 3444 |
| 3445 TEST_F(ClientSocketPoolBaseTest, FailToCloseIdleSocketsNotHeldByLayeredPool) { |
| 3446 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 3447 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 3448 |
| 3449 MockLayeredPool mock_layered_pool(pool_.get(), "foo"); |
| 3450 EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection()) |
| 3451 .WillOnce(Return(false)); |
| 3452 EXPECT_EQ(OK, mock_layered_pool.RequestSocket(pool_.get())); |
| 3453 EXPECT_FALSE(pool_->CloseOneIdleConnectionInLayeredPool()); |
| 3454 } |
| 3455 |
| 3456 TEST_F(ClientSocketPoolBaseTest, ForciblyCloseIdleSocketsHeldByLayeredPool) { |
| 3457 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 3458 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 3459 |
| 3460 MockLayeredPool mock_layered_pool(pool_.get(), "foo"); |
| 3461 EXPECT_EQ(OK, mock_layered_pool.RequestSocket(pool_.get())); |
| 3462 EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection()) |
| 3463 .WillOnce(Invoke(&mock_layered_pool, |
| 3464 &MockLayeredPool::ReleaseOneConnection)); |
| 3465 EXPECT_TRUE(pool_->CloseOneIdleConnectionInLayeredPool()); |
| 3466 } |
| 3467 |
| 3468 TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketsHeldByLayeredPoolWhenNeeded) { |
| 3469 CreatePool(1, 1); |
| 3470 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 3471 |
| 3472 MockLayeredPool mock_layered_pool(pool_.get(), "foo"); |
| 3473 EXPECT_EQ(OK, mock_layered_pool.RequestSocket(pool_.get())); |
| 3474 EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection()) |
| 3475 .WillOnce(Invoke(&mock_layered_pool, |
| 3476 &MockLayeredPool::ReleaseOneConnection)); |
| 3477 ClientSocketHandle handle; |
| 3478 TestCompletionCallback callback; |
| 3479 EXPECT_EQ(OK, handle.Init("a", |
| 3480 params_, |
| 3481 kDefaultPriority, |
| 3482 callback.callback(), |
| 3483 pool_.get(), |
| 3484 BoundNetLog())); |
| 3485 } |
| 3486 |
| 3487 TEST_F(ClientSocketPoolBaseTest, |
| 3488 CloseMultipleIdleSocketsHeldByLayeredPoolWhenNeeded) { |
| 3489 CreatePool(1, 1); |
| 3490 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 3491 |
| 3492 MockLayeredPool mock_layered_pool1(pool_.get(), "foo"); |
| 3493 EXPECT_EQ(OK, mock_layered_pool1.RequestSocket(pool_.get())); |
| 3494 EXPECT_CALL(mock_layered_pool1, CloseOneIdleConnection()) |
| 3495 .WillRepeatedly(Invoke(&mock_layered_pool1, |
| 3496 &MockLayeredPool::ReleaseOneConnection)); |
| 3497 MockLayeredPool mock_layered_pool2(pool_.get(), "bar"); |
| 3498 EXPECT_EQ(OK, mock_layered_pool2.RequestSocketWithoutLimits(pool_.get())); |
| 3499 EXPECT_CALL(mock_layered_pool2, CloseOneIdleConnection()) |
| 3500 .WillRepeatedly(Invoke(&mock_layered_pool2, |
| 3501 &MockLayeredPool::ReleaseOneConnection)); |
| 3502 ClientSocketHandle handle; |
| 3503 TestCompletionCallback callback; |
| 3504 EXPECT_EQ(OK, handle.Init("a", |
| 3505 params_, |
| 3506 kDefaultPriority, |
| 3507 callback.callback(), |
| 3508 pool_.get(), |
| 3509 BoundNetLog())); |
| 3510 } |
| 3511 |
| 3368 } // namespace | 3512 } // namespace |
| 3369 | 3513 |
| 3370 } // namespace net | 3514 } // namespace net |
| OLD | NEW |