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

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

Issue 1992010: Revert 46757 - Fix IO thread hang on releasing a socket.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 | Annotate | Revision Log
« 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 1437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 req.handle()->Reset(); 1448 req.handle()->Reset();
1449 req2.handle()->socket()->Disconnect(); 1449 req2.handle()->socket()->Disconnect();
1450 req2.handle()->Reset(); 1450 req2.handle()->Reset();
1451 1451
1452 EXPECT_EQ(OK, req3.WaitForResult()); 1452 EXPECT_EQ(OK, req3.WaitForResult());
1453 EXPECT_FALSE(req3.handle()->is_reused()); 1453 EXPECT_FALSE(req3.handle()->is_reused());
1454 EXPECT_EQ(OK, req4.WaitForResult()); 1454 EXPECT_EQ(OK, req4.WaitForResult());
1455 EXPECT_FALSE(req4.handle()->is_reused()); 1455 EXPECT_FALSE(req4.handle()->is_reused());
1456 } 1456 }
1457 1457
1458 // Regression test for http://crbug.com/42267.
1459 // When DoReleaseSocket() is processed for one socket, it is blocked because the
1460 // other stalled groups all have releasing sockets, so no progress can be made.
1461 TEST_F(ClientSocketPoolBaseTest, SocketLimitReleasingSockets) {
1462 CreatePoolWithIdleTimeouts(
1463 4 /* socket limit */, 4 /* socket limit per group */,
1464 base::TimeDelta(), // Time out unused sockets immediately.
1465 base::TimeDelta::FromDays(1)); // Don't time out used sockets.
1466
1467 connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
1468
1469 // Max out the socket limit with 2 per group.
1470
1471 scoped_ptr<TestSocketRequest> req_a[4];
1472 scoped_ptr<TestSocketRequest> req_b[4];
1473
1474 for (int i = 0; i < 2; ++i) {
1475 req_a[i].reset(new TestSocketRequest(&request_order_, &completion_count_));
1476 req_b[i].reset(new TestSocketRequest(&request_order_, &completion_count_));
1477 EXPECT_EQ(OK,
1478 InitHandle(req_a[i]->handle(), "a", LOWEST, req_a[i].get(), pool_,
1479 BoundNetLog()));
1480 EXPECT_EQ(OK,
1481 InitHandle(req_b[i]->handle(), "b", LOWEST, req_b[i].get(), pool_,
1482 BoundNetLog()));
1483 }
1484
1485 // Make 4 pending requests, 2 per group.
1486
1487 for (int i = 2; i < 4; ++i) {
1488 req_a[i].reset(new TestSocketRequest(&request_order_, &completion_count_));
1489 req_b[i].reset(new TestSocketRequest(&request_order_, &completion_count_));
1490 EXPECT_EQ(ERR_IO_PENDING,
1491 InitHandle(req_a[i]->handle(), "a", LOWEST, req_a[i].get(), pool_,
1492 BoundNetLog()));
1493 EXPECT_EQ(ERR_IO_PENDING,
1494 InitHandle(req_b[i]->handle(), "b", LOWEST, req_b[i].get(), pool_,
1495 BoundNetLog()));
1496 }
1497
1498 // Release b's socket first. The order is important, because in
1499 // DoReleaseSocket(), we'll process b's released socket, and since both b and
1500 // a are stalled, but 'a' is lower lexicographically, we'll process group 'a'
1501 // first, which has a releasing socket, so it refuses to start up another
1502 // ConnectJob. So, we used to infinite loop on this.
1503 req_b[0]->handle()->socket()->Disconnect();
1504 req_b[0]->handle()->Reset();
1505 req_a[0]->handle()->socket()->Disconnect();
1506 req_a[0]->handle()->Reset();
1507
1508 // Used to get stuck here.
1509 MessageLoop::current()->RunAllPending();
1510
1511 req_b[1]->handle()->socket()->Disconnect();
1512 req_b[1]->handle()->Reset();
1513 req_a[1]->handle()->socket()->Disconnect();
1514 req_a[1]->handle()->Reset();
1515
1516 for (int i = 2; i < 4; ++i) {
1517 EXPECT_EQ(OK, req_b[i]->WaitForResult());
1518 EXPECT_EQ(OK, req_a[i]->WaitForResult());
1519 }
1520 }
1521
1522 TEST_F(ClientSocketPoolBaseTest, 1458 TEST_F(ClientSocketPoolBaseTest,
1523 ReleasingDisconnectedSocketsMaintainsPriorityOrder) { 1459 ReleasingDisconnectedSocketsMaintainsPriorityOrder) {
1524 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 1460 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
1525 1461
1526 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); 1462 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
1527 1463
1528 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); 1464 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority));
1529 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); 1465 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority));
1530 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); 1466 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority));
1531 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); 1467 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1598 TestReleasingSocketRequest request(pool_.get()); 1534 TestReleasingSocketRequest request(pool_.get());
1599 EXPECT_EQ(ERR_IO_PENDING, InitHandle(request.handle(), "a", kDefaultPriority, 1535 EXPECT_EQ(ERR_IO_PENDING, InitHandle(request.handle(), "a", kDefaultPriority,
1600 &request, pool_, BoundNetLog())); 1536 &request, pool_, BoundNetLog()));
1601 1537
1602 EXPECT_EQ(OK, request.WaitForResult()); 1538 EXPECT_EQ(OK, request.WaitForResult());
1603 } 1539 }
1604 1540
1605 } // namespace 1541 } // namespace
1606 1542
1607 } // namespace net 1543 } // 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