| 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 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 EXPECT_FALSE(req2.handle()->socket()); | 967 EXPECT_FALSE(req2.handle()->socket()); |
| 968 client_socket_factory_.SignalJobs(); | 968 client_socket_factory_.SignalJobs(); |
| 969 EXPECT_EQ(OK, req2.WaitForResult()); | 969 EXPECT_EQ(OK, req2.WaitForResult()); |
| 970 | 970 |
| 971 ASSERT_EQ(2U, request_order_.size()); | 971 ASSERT_EQ(2U, request_order_.size()); |
| 972 EXPECT_EQ(&req1, request_order_[0]); | 972 EXPECT_EQ(&req1, request_order_[0]); |
| 973 EXPECT_EQ(&req2, request_order_[1]); | 973 EXPECT_EQ(&req2, request_order_[1]); |
| 974 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); | 974 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); |
| 975 } | 975 } |
| 976 | 976 |
| 977 // Regression test for http://crbug.com/17985. |
| 978 TEST_F(ClientSocketPoolBaseTest, GroupWithPendingRequestsIsNotEmpty) { |
| 979 const int kMaxSockets = 3; |
| 980 const int kMaxSocketsPerGroup = 2; |
| 981 CreatePool(kMaxSockets, kMaxSocketsPerGroup); |
| 982 |
| 983 const int kHighPriority = kDefaultPriority + 100; |
| 984 |
| 985 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); |
| 986 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); |
| 987 |
| 988 // This is going to be a pending request in an otherwise empty group. |
| 989 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 990 |
| 991 // Reach the maximum socket limit. |
| 992 EXPECT_EQ(OK, StartRequest("b", kDefaultPriority)); |
| 993 |
| 994 // Create a stalled group with high priorities. |
| 995 EXPECT_EQ(ERR_IO_PENDING, StartRequest("c", kHighPriority)); |
| 996 EXPECT_EQ(ERR_IO_PENDING, StartRequest("c", kHighPriority)); |
| 997 EXPECT_TRUE(pool_->base()->may_have_stalled_group()); |
| 998 |
| 999 // Release the first two sockets from "a", which will make room |
| 1000 // for requests from "c". After that "a" will have no active sockets |
| 1001 // and one pending request. |
| 1002 EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE)); |
| 1003 EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE)); |
| 1004 |
| 1005 // Closing idle sockets should not get us into trouble, but in the bug |
| 1006 // we were hitting a CHECK here. |
| 1007 EXPECT_EQ(2, pool_->IdleSocketCountInGroup("a")); |
| 1008 pool_->CloseIdleSockets(); |
| 1009 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); |
| 1010 } |
| 1011 |
| 977 class ClientSocketPoolBaseTest_LateBinding : public ClientSocketPoolBaseTest { | 1012 class ClientSocketPoolBaseTest_LateBinding : public ClientSocketPoolBaseTest { |
| 978 protected: | 1013 protected: |
| 979 virtual void SetUp() { | 1014 virtual void SetUp() { |
| 980 ClientSocketPoolBaseTest::SetUp(); | 1015 ClientSocketPoolBaseTest::SetUp(); |
| 981 ClientSocketPoolBase::EnableLateBindingOfSockets(true); | 1016 ClientSocketPoolBase::EnableLateBindingOfSockets(true); |
| 982 } | 1017 } |
| 983 }; | 1018 }; |
| 984 | 1019 |
| 985 TEST_F(ClientSocketPoolBaseTest_LateBinding, BasicSynchronous) { | 1020 TEST_F(ClientSocketPoolBaseTest_LateBinding, BasicSynchronous) { |
| 986 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1021 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1369 | 1404 |
| 1370 MessageLoop::current()->RunAllPending(); | 1405 MessageLoop::current()->RunAllPending(); |
| 1371 | 1406 |
| 1372 TestSocketRequest req2(pool_.get(), &request_order_, &completion_count_); | 1407 TestSocketRequest req2(pool_.get(), &request_order_, &completion_count_); |
| 1373 rv = req2.handle()->Init("a", ignored_request_info_, kDefaultPriority, &req2); | 1408 rv = req2.handle()->Init("a", ignored_request_info_, kDefaultPriority, &req2); |
| 1374 EXPECT_EQ(ERR_IO_PENDING, rv); | 1409 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1375 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req1.handle()->GetLoadState()); | 1410 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req1.handle()->GetLoadState()); |
| 1376 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req2.handle()->GetLoadState()); | 1411 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req2.handle()->GetLoadState()); |
| 1377 } | 1412 } |
| 1378 | 1413 |
| 1414 // Regression test for http://crbug.com/17985. |
| 1415 TEST_F(ClientSocketPoolBaseTest_LateBinding, |
| 1416 GroupWithPendingRequestsIsNotEmpty) { |
| 1417 const int kMaxSockets = 3; |
| 1418 const int kMaxSocketsPerGroup = 2; |
| 1419 CreatePool(kMaxSockets, kMaxSocketsPerGroup); |
| 1420 |
| 1421 const int kHighPriority = kDefaultPriority + 100; |
| 1422 |
| 1423 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); |
| 1424 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); |
| 1425 |
| 1426 // This is going to be a pending request in an otherwise empty group. |
| 1427 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 1428 |
| 1429 // Reach the maximum socket limit. |
| 1430 EXPECT_EQ(OK, StartRequest("b", kDefaultPriority)); |
| 1431 |
| 1432 // Create a stalled group with high priorities. |
| 1433 EXPECT_EQ(ERR_IO_PENDING, StartRequest("c", kHighPriority)); |
| 1434 EXPECT_EQ(ERR_IO_PENDING, StartRequest("c", kHighPriority)); |
| 1435 EXPECT_TRUE(pool_->base()->may_have_stalled_group()); |
| 1436 |
| 1437 // Release the first two sockets from "a", which will make room |
| 1438 // for requests from "c". After that "a" will have no active sockets |
| 1439 // and one pending request. |
| 1440 EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE)); |
| 1441 EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE)); |
| 1442 |
| 1443 // Closing idle sockets should not get us into trouble, but in the bug |
| 1444 // we were hitting a CHECK here. |
| 1445 EXPECT_EQ(2, pool_->IdleSocketCountInGroup("a")); |
| 1446 pool_->CloseIdleSockets(); |
| 1447 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); |
| 1448 } |
| 1449 |
| 1379 } // namespace | 1450 } // namespace |
| 1380 | 1451 |
| 1381 } // namespace net | 1452 } // namespace net |
| OLD | NEW |