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