| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/scoped_vector.h" | 9 #include "base/scoped_vector.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 EXPECT_FALSE(req2.handle.socket()); | 818 EXPECT_FALSE(req2.handle.socket()); |
| 819 client_socket_factory_.SignalJobs(); | 819 client_socket_factory_.SignalJobs(); |
| 820 EXPECT_EQ(OK, req2.WaitForResult()); | 820 EXPECT_EQ(OK, req2.WaitForResult()); |
| 821 | 821 |
| 822 ASSERT_EQ(2U, request_order_.size()); | 822 ASSERT_EQ(2U, request_order_.size()); |
| 823 EXPECT_EQ(&req1, request_order_[0]); | 823 EXPECT_EQ(&req1, request_order_[0]); |
| 824 EXPECT_EQ(&req2, request_order_[1]); | 824 EXPECT_EQ(&req2, request_order_[1]); |
| 825 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); | 825 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); |
| 826 } | 826 } |
| 827 | 827 |
| 828 // Regression test for http://crbug.com/17985. |
| 829 TEST_F(ClientSocketPoolBaseTest, GroupWithPendingRequestsIsNotEmpty) { |
| 830 const int kMaxSockets = 3; |
| 831 const int kMaxSocketsPerGroup = 2; |
| 832 CreatePool(kMaxSockets, kMaxSocketsPerGroup); |
| 833 |
| 834 const int kHighPriority = kDefaultPriority + 100; |
| 835 |
| 836 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); |
| 837 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); |
| 838 |
| 839 // This is going to be a pending request in an otherwise empty group. |
| 840 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 841 |
| 842 // Reach the maximum socket limit. |
| 843 EXPECT_EQ(OK, StartRequest("b", kDefaultPriority)); |
| 844 |
| 845 // Create a stalled group with high priorities. |
| 846 EXPECT_EQ(ERR_IO_PENDING, StartRequest("c", kHighPriority)); |
| 847 EXPECT_EQ(ERR_IO_PENDING, StartRequest("c", kHighPriority)); |
| 848 EXPECT_TRUE(pool_->base()->may_have_stalled_group()); |
| 849 |
| 850 // Release the first two sockets from "a", which will make room |
| 851 // for requests from "c". After that "a" will have no active sockets |
| 852 // and one pending request. |
| 853 EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE)); |
| 854 EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE)); |
| 855 |
| 856 // Closing idle sockets should not get us into trouble, but in the bug |
| 857 // we were hitting a CHECK here. |
| 858 EXPECT_EQ(2, pool_->IdleSocketCountInGroup("a")); |
| 859 pool_->CloseIdleSockets(); |
| 860 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); |
| 861 } |
| 862 |
| 828 class ClientSocketPoolBaseTest_LateBinding : public ClientSocketPoolBaseTest { | 863 class ClientSocketPoolBaseTest_LateBinding : public ClientSocketPoolBaseTest { |
| 829 protected: | 864 protected: |
| 830 virtual void SetUp() { | 865 virtual void SetUp() { |
| 831 ClientSocketPoolBaseTest::SetUp(); | 866 ClientSocketPoolBaseTest::SetUp(); |
| 832 ClientSocketPoolBase::EnableLateBindingOfSockets(true); | 867 ClientSocketPoolBase::EnableLateBindingOfSockets(true); |
| 833 } | 868 } |
| 834 }; | 869 }; |
| 835 | 870 |
| 836 TEST_F(ClientSocketPoolBaseTest_LateBinding, BasicSynchronous) { | 871 TEST_F(ClientSocketPoolBaseTest_LateBinding, BasicSynchronous) { |
| 837 CreatePool(kDefaultMaxSocketsPerGroup); | 872 CreatePool(kDefaultMaxSocketsPerGroup); |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1216 | 1251 |
| 1217 MessageLoop::current()->RunAllPending(); | 1252 MessageLoop::current()->RunAllPending(); |
| 1218 | 1253 |
| 1219 TestSocketRequest req2(pool_.get(), &request_order_); | 1254 TestSocketRequest req2(pool_.get(), &request_order_); |
| 1220 rv = req2.handle.Init("a", ignored_request_info_, 5, &req2); | 1255 rv = req2.handle.Init("a", ignored_request_info_, 5, &req2); |
| 1221 EXPECT_EQ(ERR_IO_PENDING, rv); | 1256 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1222 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req1.handle.GetLoadState()); | 1257 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req1.handle.GetLoadState()); |
| 1223 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req2.handle.GetLoadState()); | 1258 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req2.handle.GetLoadState()); |
| 1224 } | 1259 } |
| 1225 | 1260 |
| 1261 // Regression test for http://crbug.com/17985. |
| 1262 TEST_F(ClientSocketPoolBaseTest_LateBinding, |
| 1263 GroupWithPendingRequestsIsNotEmpty) { |
| 1264 const int kMaxSockets = 3; |
| 1265 const int kMaxSocketsPerGroup = 2; |
| 1266 CreatePool(kMaxSockets, kMaxSocketsPerGroup); |
| 1267 |
| 1268 const int kHighPriority = kDefaultPriority + 100; |
| 1269 |
| 1270 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); |
| 1271 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); |
| 1272 |
| 1273 // This is going to be a pending request in an otherwise empty group. |
| 1274 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 1275 |
| 1276 // Reach the maximum socket limit. |
| 1277 EXPECT_EQ(OK, StartRequest("b", kDefaultPriority)); |
| 1278 |
| 1279 // Create a stalled group with high priorities. |
| 1280 EXPECT_EQ(ERR_IO_PENDING, StartRequest("c", kHighPriority)); |
| 1281 EXPECT_EQ(ERR_IO_PENDING, StartRequest("c", kHighPriority)); |
| 1282 EXPECT_TRUE(pool_->base()->may_have_stalled_group()); |
| 1283 |
| 1284 // Release the first two sockets from "a", which will make room |
| 1285 // for requests from "c". After that "a" will have no active sockets |
| 1286 // and one pending request. |
| 1287 EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE)); |
| 1288 EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE)); |
| 1289 |
| 1290 // Closing idle sockets should not get us into trouble, but in the bug |
| 1291 // we were hitting a CHECK here. |
| 1292 EXPECT_EQ(2, pool_->IdleSocketCountInGroup("a")); |
| 1293 pool_->CloseIdleSockets(); |
| 1294 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); |
| 1295 } |
| 1296 |
| 1226 } // namespace | 1297 } // namespace |
| 1227 | 1298 |
| 1228 } // namespace net | 1299 } // namespace net |
| OLD | NEW |