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

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

Issue 2050005: Reland 46757. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Reduce large iteration check. Created 10 years, 7 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
« no previous file with comments | « net/socket/client_socket_pool_base.cc ('k') | net/socket/tcp_client_socket_pool_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/callback.h" 7 #include "base/callback.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/platform_thread.h" 10 #include "base/platform_thread.h"
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 823
824 EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE)); 824 EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE));
825 EXPECT_EQ(kDefaultMaxSockets + 1, client_socket_factory_.allocation_count()); 825 EXPECT_EQ(kDefaultMaxSockets + 1, client_socket_factory_.allocation_count());
826 EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE)); 826 EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE));
827 EXPECT_EQ(kDefaultMaxSockets + 2, client_socket_factory_.allocation_count()); 827 EXPECT_EQ(kDefaultMaxSockets + 2, client_socket_factory_.allocation_count());
828 EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE)); 828 EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE));
829 EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE)); 829 EXPECT_TRUE(ReleaseOneConnection(KEEP_ALIVE));
830 EXPECT_EQ(kDefaultMaxSockets + 2, client_socket_factory_.allocation_count()); 830 EXPECT_EQ(kDefaultMaxSockets + 2, client_socket_factory_.allocation_count());
831 } 831 }
832 832
833 TEST_F(ClientSocketPoolBaseTest, StallAndThenCancelAndTriggerAvailableSocket) {
834 CreatePool(kDefaultMaxSockets, kDefaultMaxSockets);
835 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
836
837 ClientSocketHandle handle;
838 TestCompletionCallback callback;
839 EXPECT_EQ(ERR_IO_PENDING,
840 InitHandle(&handle, "a", kDefaultPriority, &callback, pool_,
841 BoundNetLog()));
842
843 ClientSocketHandle handles[4];
844 for (size_t i = 0; i < arraysize(handles); ++i) {
845 TestCompletionCallback callback;
846 EXPECT_EQ(ERR_IO_PENDING,
847 InitHandle(&handles[i], "b", kDefaultPriority, &callback, pool_,
848 BoundNetLog()));
849 }
850
851 // One will be stalled, cancel all the handles now.
852 // This should hit the OnAvailableSocketSlot() code where we previously had
853 // stalled groups, but no longer have any.
854 for (size_t i = 0; i < arraysize(handles); ++i)
855 handles[i].Reset();
856 }
857
833 TEST_F(ClientSocketPoolBaseTest, PendingRequests) { 858 TEST_F(ClientSocketPoolBaseTest, PendingRequests) {
834 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 859 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
835 860
836 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); 861 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority));
837 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); 862 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority));
838 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST)); 863 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST));
839 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", MEDIUM)); 864 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", MEDIUM));
840 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", HIGHEST)); 865 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", HIGHEST));
841 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOW)); 866 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOW));
842 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST)); 867 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST));
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 req.handle()->Reset(); 1473 req.handle()->Reset();
1449 req2.handle()->socket()->Disconnect(); 1474 req2.handle()->socket()->Disconnect();
1450 req2.handle()->Reset(); 1475 req2.handle()->Reset();
1451 1476
1452 EXPECT_EQ(OK, req3.WaitForResult()); 1477 EXPECT_EQ(OK, req3.WaitForResult());
1453 EXPECT_FALSE(req3.handle()->is_reused()); 1478 EXPECT_FALSE(req3.handle()->is_reused());
1454 EXPECT_EQ(OK, req4.WaitForResult()); 1479 EXPECT_EQ(OK, req4.WaitForResult());
1455 EXPECT_FALSE(req4.handle()->is_reused()); 1480 EXPECT_FALSE(req4.handle()->is_reused());
1456 } 1481 }
1457 1482
1483 // Regression test for http://crbug.com/42267.
1484 // When DoReleaseSocket() is processed for one socket, it is blocked because the
1485 // other stalled groups all have releasing sockets, so no progress can be made.
1486 TEST_F(ClientSocketPoolBaseTest, SocketLimitReleasingSockets) {
1487 CreatePoolWithIdleTimeouts(
1488 4 /* socket limit */, 4 /* socket limit per group */,
1489 base::TimeDelta(), // Time out unused sockets immediately.
1490 base::TimeDelta::FromDays(1)); // Don't time out used sockets.
1491
1492 connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
1493
1494 // Max out the socket limit with 2 per group.
1495
1496 scoped_ptr<TestSocketRequest> req_a[4];
1497 scoped_ptr<TestSocketRequest> req_b[4];
1498
1499 for (int i = 0; i < 2; ++i) {
1500 req_a[i].reset(new TestSocketRequest(&request_order_, &completion_count_));
1501 req_b[i].reset(new TestSocketRequest(&request_order_, &completion_count_));
1502 EXPECT_EQ(OK,
1503 InitHandle(req_a[i]->handle(), "a", LOWEST, req_a[i].get(), pool_,
1504 BoundNetLog()));
1505 EXPECT_EQ(OK,
1506 InitHandle(req_b[i]->handle(), "b", LOWEST, req_b[i].get(), pool_,
1507 BoundNetLog()));
1508 }
1509
1510 // Make 4 pending requests, 2 per group.
1511
1512 for (int i = 2; i < 4; ++i) {
1513 req_a[i].reset(new TestSocketRequest(&request_order_, &completion_count_));
1514 req_b[i].reset(new TestSocketRequest(&request_order_, &completion_count_));
1515 EXPECT_EQ(ERR_IO_PENDING,
1516 InitHandle(req_a[i]->handle(), "a", LOWEST, req_a[i].get(), pool_,
1517 BoundNetLog()));
1518 EXPECT_EQ(ERR_IO_PENDING,
1519 InitHandle(req_b[i]->handle(), "b", LOWEST, req_b[i].get(), pool_,
1520 BoundNetLog()));
1521 }
1522
1523 // Release b's socket first. The order is important, because in
1524 // DoReleaseSocket(), we'll process b's released socket, and since both b and
1525 // a are stalled, but 'a' is lower lexicographically, we'll process group 'a'
1526 // first, which has a releasing socket, so it refuses to start up another
1527 // ConnectJob. So, we used to infinite loop on this.
1528 req_b[0]->handle()->socket()->Disconnect();
1529 req_b[0]->handle()->Reset();
1530 req_a[0]->handle()->socket()->Disconnect();
1531 req_a[0]->handle()->Reset();
1532
1533 // Used to get stuck here.
1534 MessageLoop::current()->RunAllPending();
1535
1536 req_b[1]->handle()->socket()->Disconnect();
1537 req_b[1]->handle()->Reset();
1538 req_a[1]->handle()->socket()->Disconnect();
1539 req_a[1]->handle()->Reset();
1540
1541 for (int i = 2; i < 4; ++i) {
1542 EXPECT_EQ(OK, req_b[i]->WaitForResult());
1543 EXPECT_EQ(OK, req_a[i]->WaitForResult());
1544 }
1545 }
1546
1458 TEST_F(ClientSocketPoolBaseTest, 1547 TEST_F(ClientSocketPoolBaseTest,
1459 ReleasingDisconnectedSocketsMaintainsPriorityOrder) { 1548 ReleasingDisconnectedSocketsMaintainsPriorityOrder) {
1460 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 1549 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
1461 1550
1462 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); 1551 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
1463 1552
1464 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); 1553 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority));
1465 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); 1554 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority));
1466 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); 1555 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority));
1467 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); 1556 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1534 TestReleasingSocketRequest request(pool_.get()); 1623 TestReleasingSocketRequest request(pool_.get());
1535 EXPECT_EQ(ERR_IO_PENDING, InitHandle(request.handle(), "a", kDefaultPriority, 1624 EXPECT_EQ(ERR_IO_PENDING, InitHandle(request.handle(), "a", kDefaultPriority,
1536 &request, pool_, BoundNetLog())); 1625 &request, pool_, BoundNetLog()));
1537 1626
1538 EXPECT_EQ(OK, request.WaitForResult()); 1627 EXPECT_EQ(OK, request.WaitForResult());
1539 } 1628 }
1540 1629
1541 } // namespace 1630 } // namespace
1542 1631
1543 } // namespace net 1632 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/client_socket_pool_base.cc ('k') | net/socket/tcp_client_socket_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698