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

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

Issue 165218: Merge 21988 - Fix crash in client_socket_pool_base.cc.... (Closed) Base URL: svn://chrome-svn/chrome/branches/195/src/
Patch Set: Created 11 years, 4 months 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
« no previous file with comments | « net/socket/client_socket_pool_base.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Modified: svn:mergeinfo
Merged /trunk/src/net/socket/client_socket_pool_base_unittest.cc:r21988
OLDNEW
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 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 EXPECT_FALSE(req2.handle.socket()); 1044 EXPECT_FALSE(req2.handle.socket());
1045 client_socket_factory_.SignalJobs(); 1045 client_socket_factory_.SignalJobs();
1046 EXPECT_EQ(OK, req2.WaitForResult()); 1046 EXPECT_EQ(OK, req2.WaitForResult());
1047 1047
1048 ASSERT_EQ(2U, request_order_.size()); 1048 ASSERT_EQ(2U, request_order_.size());
1049 EXPECT_EQ(&req1, request_order_[0]); 1049 EXPECT_EQ(&req1, request_order_[0]);
1050 EXPECT_EQ(&req2, request_order_[1]); 1050 EXPECT_EQ(&req2, request_order_[1]);
1051 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); 1051 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a"));
1052 } 1052 }
1053 1053
1054 // Regression test for http://crbug.com/17985.
1055 TEST_F(ClientSocketPoolBaseTest, GroupWithPendingRequestsIsNotEmpty) {
1056 const int kMaxSockets = 3;
1057 const int kMaxSocketsPerGroup = 2;
1058 CreatePool(kMaxSockets, kMaxSocketsPerGroup);
1059
1060 const int kHighPriority = kDefaultPriority + 100;
1061
1062 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority));
1063 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority));
1064
1065 // This is going to be a pending request in an otherwise empty group.
1066 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority));
1067
1068 // Reach the maximum socket limit.
1069 EXPECT_EQ(OK, StartRequest("b", kDefaultPriority));
1070
1071 // Create a stalled group with high priorities.
1072 EXPECT_EQ(ERR_IO_PENDING, StartRequest("c", kHighPriority));
1073 EXPECT_EQ(ERR_IO_PENDING, StartRequest("c", kHighPriority));
1074 EXPECT_TRUE(pool_->base()->may_have_stalled_group());
1075
1076 // Release the first two sockets from "a", which will make room
1077 // for requests from "c". After that "a" will have no active sockets
1078 // and one pending request.
1079 EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE));
1080 EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE));
1081
1082 // Closing idle sockets should not get us into trouble, but in the bug
1083 // we were hitting a CHECK here.
1084 EXPECT_EQ(2, pool_->IdleSocketCountInGroup("a"));
1085 pool_->CloseIdleSockets();
1086 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a"));
1087 }
1088
1054 class ClientSocketPoolBaseTest_LateBinding : public ClientSocketPoolBaseTest { 1089 class ClientSocketPoolBaseTest_LateBinding : public ClientSocketPoolBaseTest {
1055 protected: 1090 protected:
1056 virtual void SetUp() { 1091 virtual void SetUp() {
1057 ClientSocketPoolBaseTest::SetUp(); 1092 ClientSocketPoolBaseTest::SetUp();
1058 ClientSocketPoolBase::EnableLateBindingOfSockets(true); 1093 ClientSocketPoolBase::EnableLateBindingOfSockets(true);
1059 } 1094 }
1060 }; 1095 };
1061 1096
1062 TEST_F(ClientSocketPoolBaseTest_LateBinding, BasicSynchronous) { 1097 TEST_F(ClientSocketPoolBaseTest_LateBinding, BasicSynchronous) {
1063 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 1098 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
1440 1475
1441 MessageLoop::current()->RunAllPending(); 1476 MessageLoop::current()->RunAllPending();
1442 1477
1443 TestSocketRequest req2(pool_.get(), &request_order_); 1478 TestSocketRequest req2(pool_.get(), &request_order_);
1444 rv = req2.handle.Init("a", ignored_request_info_, 5, &req2); 1479 rv = req2.handle.Init("a", ignored_request_info_, 5, &req2);
1445 EXPECT_EQ(ERR_IO_PENDING, rv); 1480 EXPECT_EQ(ERR_IO_PENDING, rv);
1446 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req1.handle.GetLoadState()); 1481 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req1.handle.GetLoadState());
1447 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req2.handle.GetLoadState()); 1482 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req2.handle.GetLoadState());
1448 } 1483 }
1449 1484
1485 // Regression test for http://crbug.com/17985.
1486 TEST_F(ClientSocketPoolBaseTest_LateBinding,
1487 GroupWithPendingRequestsIsNotEmpty) {
1488 const int kMaxSockets = 3;
1489 const int kMaxSocketsPerGroup = 2;
1490 CreatePool(kMaxSockets, kMaxSocketsPerGroup);
1491
1492 const int kHighPriority = kDefaultPriority + 100;
1493
1494 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority));
1495 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority));
1496
1497 // This is going to be a pending request in an otherwise empty group.
1498 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority));
1499
1500 // Reach the maximum socket limit.
1501 EXPECT_EQ(OK, StartRequest("b", kDefaultPriority));
1502
1503 // Create a stalled group with high priorities.
1504 EXPECT_EQ(ERR_IO_PENDING, StartRequest("c", kHighPriority));
1505 EXPECT_EQ(ERR_IO_PENDING, StartRequest("c", kHighPriority));
1506 EXPECT_TRUE(pool_->base()->may_have_stalled_group());
1507
1508 // Release the first two sockets from "a", which will make room
1509 // for requests from "c". After that "a" will have no active sockets
1510 // and one pending request.
1511 EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE));
1512 EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE));
1513
1514 // Closing idle sockets should not get us into trouble, but in the bug
1515 // we were hitting a CHECK here.
1516 EXPECT_EQ(2, pool_->IdleSocketCountInGroup("a"));
1517 pool_->CloseIdleSockets();
1518 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a"));
1519 }
1520
1450 } // namespace 1521 } // namespace
1451 1522
1452 } // namespace net 1523 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/client_socket_pool_base.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698