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

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

Issue 2090613002: Remove calls to deprecated MessageLoop methods in net. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 EXPECT_EQ(socket == NULL, result != OK); 638 EXPECT_EQ(socket == NULL, result != OK);
639 have_result_ = true; 639 have_result_ = true;
640 if (waiting_for_result_) 640 if (waiting_for_result_)
641 base::MessageLoop::current()->QuitWhenIdle(); 641 base::MessageLoop::current()->QuitWhenIdle();
642 } 642 }
643 643
644 int WaitForResult() { 644 int WaitForResult() {
645 DCHECK(!waiting_for_result_); 645 DCHECK(!waiting_for_result_);
646 while (!have_result_) { 646 while (!have_result_) {
647 waiting_for_result_ = true; 647 waiting_for_result_ = true;
648 base::MessageLoop::current()->Run(); 648 base::RunLoop().Run();
649 waiting_for_result_ = false; 649 waiting_for_result_ = false;
650 } 650 }
651 have_result_ = false; // auto-reset for next callback 651 have_result_ = false; // auto-reset for next callback
652 return result_; 652 return result_;
653 } 653 }
654 654
655 private: 655 private:
656 bool have_result_; 656 bool have_result_;
657 bool waiting_for_result_; 657 bool waiting_for_result_;
658 int result_; 658 int result_;
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 1015
1016 // Create one asynchronous request. 1016 // Create one asynchronous request.
1017 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); 1017 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
1018 EXPECT_EQ(ERR_IO_PENDING, StartRequest("d", DEFAULT_PRIORITY)); 1018 EXPECT_EQ(ERR_IO_PENDING, StartRequest("d", DEFAULT_PRIORITY));
1019 1019
1020 // We post all of our delayed tasks with a 2ms delay. I.e. they don't 1020 // We post all of our delayed tasks with a 2ms delay. I.e. they don't
1021 // actually become pending until 2ms after they have been created. In order 1021 // actually become pending until 2ms after they have been created. In order
1022 // to flush all tasks, we need to wait so that we know there are no 1022 // to flush all tasks, we need to wait so that we know there are no
1023 // soon-to-be-pending tasks waiting. 1023 // soon-to-be-pending tasks waiting.
1024 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); 1024 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
1025 base::MessageLoop::current()->RunUntilIdle(); 1025 base::RunLoop().RunUntilIdle();
1026 1026
1027 // The next synchronous request should wait for its turn. 1027 // The next synchronous request should wait for its turn.
1028 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); 1028 connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
1029 EXPECT_EQ(ERR_IO_PENDING, StartRequest("e", DEFAULT_PRIORITY)); 1029 EXPECT_EQ(ERR_IO_PENDING, StartRequest("e", DEFAULT_PRIORITY));
1030 1030
1031 ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); 1031 ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE);
1032 1032
1033 EXPECT_EQ(static_cast<int>(requests_size()), 1033 EXPECT_EQ(static_cast<int>(requests_size()),
1034 client_socket_factory_.allocation_count()); 1034 client_socket_factory_.allocation_count());
1035 1035
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 1233
1234 for (int i = 0; i < kDefaultMaxSockets; ++i) { 1234 for (int i = 0; i < kDefaultMaxSockets; ++i) {
1235 ClientSocketHandle handle; 1235 ClientSocketHandle handle;
1236 TestCompletionCallback callback; 1236 TestCompletionCallback callback;
1237 EXPECT_EQ(OK, handle.Init(base::IntToString(i), params_, DEFAULT_PRIORITY, 1237 EXPECT_EQ(OK, handle.Init(base::IntToString(i), params_, DEFAULT_PRIORITY,
1238 ClientSocketPool::RespectLimits::ENABLED, 1238 ClientSocketPool::RespectLimits::ENABLED,
1239 callback.callback(), pool_.get(), BoundNetLog())); 1239 callback.callback(), pool_.get(), BoundNetLog()));
1240 } 1240 }
1241 1241
1242 // Flush all the DoReleaseSocket tasks. 1242 // Flush all the DoReleaseSocket tasks.
1243 base::MessageLoop::current()->RunUntilIdle(); 1243 base::RunLoop().RunUntilIdle();
1244 1244
1245 // Stall a group. Set a pending job so it'll trigger a backup job if we don't 1245 // Stall a group. Set a pending job so it'll trigger a backup job if we don't
1246 // reuse a socket. 1246 // reuse a socket.
1247 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); 1247 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
1248 ClientSocketHandle handle; 1248 ClientSocketHandle handle;
1249 TestCompletionCallback callback; 1249 TestCompletionCallback callback;
1250 1250
1251 // "0" is special here, since it should be the first entry in the sorted map, 1251 // "0" is special here, since it should be the first entry in the sorted map,
1252 // which is the one which we would close an idle socket for. We shouldn't 1252 // which is the one which we would close an idle socket for. We shouldn't
1253 // close an idle socket though, since we should reuse the idle socket. 1253 // close an idle socket though, since we should reuse the idle socket.
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 // high priority socket. 1567 // high priority socket.
1568 EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE)); 1568 EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE));
1569 EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE)); 1569 EXPECT_TRUE(ReleaseOneConnection(ClientSocketPoolTest::KEEP_ALIVE));
1570 1570
1571 // Closing idle sockets should not get us into trouble, but in the bug 1571 // Closing idle sockets should not get us into trouble, but in the bug
1572 // we were hitting a CHECK here. 1572 // we were hitting a CHECK here.
1573 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); 1573 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a"));
1574 pool_->CloseIdleSockets(); 1574 pool_->CloseIdleSockets();
1575 1575
1576 // Run the released socket wakeups. 1576 // Run the released socket wakeups.
1577 base::MessageLoop::current()->RunUntilIdle(); 1577 base::RunLoop().RunUntilIdle();
1578 } 1578 }
1579 1579
1580 TEST_F(ClientSocketPoolBaseTest, BasicAsynchronous) { 1580 TEST_F(ClientSocketPoolBaseTest, BasicAsynchronous) {
1581 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 1581 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
1582 1582
1583 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); 1583 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
1584 ClientSocketHandle handle; 1584 ClientSocketHandle handle;
1585 TestCompletionCallback callback; 1585 TestCompletionCallback callback;
1586 BoundTestNetLog log; 1586 BoundTestNetLog log;
1587 int rv = handle.Init("a", params_, LOWEST, 1587 int rv = handle.Init("a", params_, LOWEST,
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1750 TestSocketRequest req3(&request_order, &completion_count); 1750 TestSocketRequest req3(&request_order, &completion_count);
1751 rv = req3.handle()->Init("a", params_, DEFAULT_PRIORITY, 1751 rv = req3.handle()->Init("a", params_, DEFAULT_PRIORITY,
1752 ClientSocketPool::RespectLimits::ENABLED, 1752 ClientSocketPool::RespectLimits::ENABLED,
1753 req3.callback(), pool_.get(), BoundNetLog()); 1753 req3.callback(), pool_.get(), BoundNetLog());
1754 EXPECT_EQ(ERR_IO_PENDING, rv); 1754 EXPECT_EQ(ERR_IO_PENDING, rv);
1755 1755
1756 // Both Requests 2 and 3 are pending. We release socket 1 which should 1756 // Both Requests 2 and 3 are pending. We release socket 1 which should
1757 // service request 2. Request 3 should still be waiting. 1757 // service request 2. Request 3 should still be waiting.
1758 req1.handle()->Reset(); 1758 req1.handle()->Reset();
1759 // Run the released socket wakeups. 1759 // Run the released socket wakeups.
1760 base::MessageLoop::current()->RunUntilIdle(); 1760 base::RunLoop().RunUntilIdle();
1761 ASSERT_TRUE(req2.handle()->socket()); 1761 ASSERT_TRUE(req2.handle()->socket());
1762 EXPECT_EQ(OK, req2.WaitForResult()); 1762 EXPECT_EQ(OK, req2.WaitForResult());
1763 EXPECT_FALSE(req3.handle()->socket()); 1763 EXPECT_FALSE(req3.handle()->socket());
1764 1764
1765 // Signal job 2, which should service request 3. 1765 // Signal job 2, which should service request 3.
1766 1766
1767 client_socket_factory_.SignalJobs(); 1767 client_socket_factory_.SignalJobs();
1768 EXPECT_EQ(OK, req3.WaitForResult()); 1768 EXPECT_EQ(OK, req3.WaitForResult());
1769 1769
1770 ASSERT_EQ(3U, request_order.size()); 1770 ASSERT_EQ(3U, request_order.size());
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
2147 ASSERT_EQ(OK, callback2.WaitForResult()); 2147 ASSERT_EQ(OK, callback2.WaitForResult());
2148 // Use the socket. 2148 // Use the socket.
2149 EXPECT_EQ(1, handle2.socket()->Write(NULL, 1, CompletionCallback())); 2149 EXPECT_EQ(1, handle2.socket()->Write(NULL, 1, CompletionCallback()));
2150 handle2.Reset(); 2150 handle2.Reset();
2151 2151
2152 // We post all of our delayed tasks with a 2ms delay. I.e. they don't 2152 // We post all of our delayed tasks with a 2ms delay. I.e. they don't
2153 // actually become pending until 2ms after they have been created. In order 2153 // actually become pending until 2ms after they have been created. In order
2154 // to flush all tasks, we need to wait so that we know there are no 2154 // to flush all tasks, we need to wait so that we know there are no
2155 // soon-to-be-pending tasks waiting. 2155 // soon-to-be-pending tasks waiting.
2156 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); 2156 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
2157 base::MessageLoop::current()->RunUntilIdle(); 2157 base::RunLoop().RunUntilIdle();
2158 2158
2159 // Both sockets should now be idle. 2159 // Both sockets should now be idle.
2160 ASSERT_EQ(2, pool_->IdleSocketCount()); 2160 ASSERT_EQ(2, pool_->IdleSocketCount());
2161 2161
2162 // Request a new socket. This should cleanup the unused and timed out ones. 2162 // Request a new socket. This should cleanup the unused and timed out ones.
2163 // A new socket will be created rather than reusing the idle one. 2163 // A new socket will be created rather than reusing the idle one.
2164 BoundTestNetLog log; 2164 BoundTestNetLog log;
2165 TestCompletionCallback callback3; 2165 TestCompletionCallback callback3;
2166 rv = handle.Init("a", params_, LOWEST, 2166 rv = handle.Init("a", params_, LOWEST,
2167 ClientSocketPool::RespectLimits::ENABLED, 2167 ClientSocketPool::RespectLimits::ENABLED,
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
2282 // DoReleaseSocket(), we'll process b's released socket, and since both b and 2282 // DoReleaseSocket(), we'll process b's released socket, and since both b and
2283 // a are stalled, but 'a' is lower lexicographically, we'll process group 'a' 2283 // a are stalled, but 'a' is lower lexicographically, we'll process group 'a'
2284 // first, which has a releasing socket, so it refuses to start up another 2284 // first, which has a releasing socket, so it refuses to start up another
2285 // ConnectJob. So, we used to infinite loop on this. 2285 // ConnectJob. So, we used to infinite loop on this.
2286 handle_b[0].socket()->Disconnect(); 2286 handle_b[0].socket()->Disconnect();
2287 handle_b[0].Reset(); 2287 handle_b[0].Reset();
2288 handle_a[0].socket()->Disconnect(); 2288 handle_a[0].socket()->Disconnect();
2289 handle_a[0].Reset(); 2289 handle_a[0].Reset();
2290 2290
2291 // Used to get stuck here. 2291 // Used to get stuck here.
2292 base::MessageLoop::current()->RunUntilIdle(); 2292 base::RunLoop().RunUntilIdle();
2293 2293
2294 handle_b[1].socket()->Disconnect(); 2294 handle_b[1].socket()->Disconnect();
2295 handle_b[1].Reset(); 2295 handle_b[1].Reset();
2296 handle_a[1].socket()->Disconnect(); 2296 handle_a[1].socket()->Disconnect();
2297 handle_a[1].Reset(); 2297 handle_a[1].Reset();
2298 2298
2299 for (int i = 2; i < 4; ++i) { 2299 for (int i = 2; i < 4; ++i) {
2300 EXPECT_EQ(OK, callback_b[i].WaitForResult()); 2300 EXPECT_EQ(OK, callback_b[i].WaitForResult());
2301 EXPECT_EQ(OK, callback_a[i].WaitForResult()); 2301 EXPECT_EQ(OK, callback_a[i].WaitForResult());
2302 } 2302 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
2436 EXPECT_EQ(ERR_IO_PENDING, 2436 EXPECT_EQ(ERR_IO_PENDING,
2437 handle.Init("a", params_, DEFAULT_PRIORITY, 2437 handle.Init("a", params_, DEFAULT_PRIORITY,
2438 ClientSocketPool::RespectLimits::ENABLED, 2438 ClientSocketPool::RespectLimits::ENABLED,
2439 callback.callback(), pool_.get(), BoundNetLog())); 2439 callback.callback(), pool_.get(), BoundNetLog()));
2440 EXPECT_EQ(OK, callback.WaitForResult()); 2440 EXPECT_EQ(OK, callback.WaitForResult());
2441 EXPECT_EQ(ClientSocketHandle::UNUSED, handle.reuse_type()); 2441 EXPECT_EQ(ClientSocketHandle::UNUSED, handle.reuse_type());
2442 2442
2443 pool_->FlushWithError(ERR_NETWORK_CHANGED); 2443 pool_->FlushWithError(ERR_NETWORK_CHANGED);
2444 2444
2445 handle.Reset(); 2445 handle.Reset();
2446 base::MessageLoop::current()->RunUntilIdle(); 2446 base::RunLoop().RunUntilIdle();
2447 2447
2448 EXPECT_EQ(ERR_IO_PENDING, 2448 EXPECT_EQ(ERR_IO_PENDING,
2449 handle.Init("a", params_, DEFAULT_PRIORITY, 2449 handle.Init("a", params_, DEFAULT_PRIORITY,
2450 ClientSocketPool::RespectLimits::ENABLED, 2450 ClientSocketPool::RespectLimits::ENABLED,
2451 callback.callback(), pool_.get(), BoundNetLog())); 2451 callback.callback(), pool_.get(), BoundNetLog()));
2452 EXPECT_EQ(OK, callback.WaitForResult()); 2452 EXPECT_EQ(OK, callback.WaitForResult());
2453 EXPECT_EQ(ClientSocketHandle::UNUSED, handle.reuse_type()); 2453 EXPECT_EQ(ClientSocketHandle::UNUSED, handle.reuse_type());
2454 } 2454 }
2455 2455
2456 class ConnectWithinCallback : public TestCompletionCallbackBase { 2456 class ConnectWithinCallback : public TestCompletionCallbackBase {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2535 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); 2535 connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
2536 ClientSocketHandle handles[kDefaultMaxSockets]; 2536 ClientSocketHandle handles[kDefaultMaxSockets];
2537 for (int i = 1; i < kDefaultMaxSockets; ++i) { 2537 for (int i = 1; i < kDefaultMaxSockets; ++i) {
2538 TestCompletionCallback callback; 2538 TestCompletionCallback callback;
2539 EXPECT_EQ(OK, 2539 EXPECT_EQ(OK,
2540 handles[i].Init("bar", params_, DEFAULT_PRIORITY, 2540 handles[i].Init("bar", params_, DEFAULT_PRIORITY,
2541 ClientSocketPool::RespectLimits::ENABLED, 2541 ClientSocketPool::RespectLimits::ENABLED,
2542 callback.callback(), pool_.get(), BoundNetLog())); 2542 callback.callback(), pool_.get(), BoundNetLog()));
2543 } 2543 }
2544 2544
2545 base::MessageLoop::current()->RunUntilIdle(); 2545 base::RunLoop().RunUntilIdle();
2546 2546
2547 // Cancel the pending request. 2547 // Cancel the pending request.
2548 handle.Reset(); 2548 handle.Reset();
2549 2549
2550 // Wait for the backup timer to fire (add some slop to ensure it fires) 2550 // Wait for the backup timer to fire (add some slop to ensure it fires)
2551 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( 2551 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(
2552 ClientSocketPool::kMaxConnectRetryIntervalMs / 2 * 3)); 2552 ClientSocketPool::kMaxConnectRetryIntervalMs / 2 * 3));
2553 2553
2554 base::MessageLoop::current()->RunUntilIdle(); 2554 base::RunLoop().RunUntilIdle();
2555 EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count()); 2555 EXPECT_EQ(kDefaultMaxSockets, client_socket_factory_.allocation_count());
2556 } 2556 }
2557 2557
2558 TEST_F(ClientSocketPoolBaseTest, CancelBackupSocketAfterCancelingAllRequests) { 2558 TEST_F(ClientSocketPoolBaseTest, CancelBackupSocketAfterCancelingAllRequests) {
2559 CreatePool(kDefaultMaxSockets, kDefaultMaxSockets); 2559 CreatePool(kDefaultMaxSockets, kDefaultMaxSockets);
2560 pool_->EnableConnectBackupJobs(); 2560 pool_->EnableConnectBackupJobs();
2561 2561
2562 // Create the first socket and set to ERR_IO_PENDING. This starts the backup 2562 // Create the first socket and set to ERR_IO_PENDING. This starts the backup
2563 // timer. 2563 // timer.
2564 connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); 2564 connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob);
2565 ClientSocketHandle handle; 2565 ClientSocketHandle handle;
2566 TestCompletionCallback callback; 2566 TestCompletionCallback callback;
2567 EXPECT_EQ(ERR_IO_PENDING, 2567 EXPECT_EQ(ERR_IO_PENDING,
2568 handle.Init("bar", params_, DEFAULT_PRIORITY, 2568 handle.Init("bar", params_, DEFAULT_PRIORITY,
2569 ClientSocketPool::RespectLimits::ENABLED, 2569 ClientSocketPool::RespectLimits::ENABLED,
2570 callback.callback(), pool_.get(), BoundNetLog())); 2570 callback.callback(), pool_.get(), BoundNetLog()));
2571 ASSERT_TRUE(pool_->HasGroup("bar")); 2571 ASSERT_TRUE(pool_->HasGroup("bar"));
2572 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("bar")); 2572 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("bar"));
2573 EXPECT_EQ(0, pool_->NumUnassignedConnectJobsInGroup("bar")); 2573 EXPECT_EQ(0, pool_->NumUnassignedConnectJobsInGroup("bar"));
2574 2574
2575 // Cancel the socket request. This should cancel the backup timer. Wait for 2575 // Cancel the socket request. This should cancel the backup timer. Wait for
2576 // the backup time to see if it indeed got canceled. 2576 // the backup time to see if it indeed got canceled.
2577 handle.Reset(); 2577 handle.Reset();
2578 // Wait for the backup timer to fire (add some slop to ensure it fires) 2578 // Wait for the backup timer to fire (add some slop to ensure it fires)
2579 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( 2579 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(
2580 ClientSocketPool::kMaxConnectRetryIntervalMs / 2 * 3)); 2580 ClientSocketPool::kMaxConnectRetryIntervalMs / 2 * 3));
2581 base::MessageLoop::current()->RunUntilIdle(); 2581 base::RunLoop().RunUntilIdle();
2582 ASSERT_TRUE(pool_->HasGroup("bar")); 2582 ASSERT_TRUE(pool_->HasGroup("bar"));
2583 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("bar")); 2583 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("bar"));
2584 } 2584 }
2585 2585
2586 TEST_F(ClientSocketPoolBaseTest, CancelBackupSocketAfterFinishingAllRequests) { 2586 TEST_F(ClientSocketPoolBaseTest, CancelBackupSocketAfterFinishingAllRequests) {
2587 CreatePool(kDefaultMaxSockets, kDefaultMaxSockets); 2587 CreatePool(kDefaultMaxSockets, kDefaultMaxSockets);
2588 pool_->EnableConnectBackupJobs(); 2588 pool_->EnableConnectBackupJobs();
2589 2589
2590 // Create the first socket and set to ERR_IO_PENDING. This starts the backup 2590 // Create the first socket and set to ERR_IO_PENDING. This starts the backup
2591 // timer. 2591 // timer.
(...skipping 14 matching lines...) Expand all
2606 ASSERT_TRUE(pool_->HasGroup("bar")); 2606 ASSERT_TRUE(pool_->HasGroup("bar"));
2607 EXPECT_EQ(2, pool_->NumConnectJobsInGroup("bar")); 2607 EXPECT_EQ(2, pool_->NumConnectJobsInGroup("bar"));
2608 2608
2609 // Cancel request 1 and then complete request 2. With the requests finished, 2609 // Cancel request 1 and then complete request 2. With the requests finished,
2610 // the backup timer should be cancelled. 2610 // the backup timer should be cancelled.
2611 handle.Reset(); 2611 handle.Reset();
2612 EXPECT_EQ(OK, callback2.WaitForResult()); 2612 EXPECT_EQ(OK, callback2.WaitForResult());
2613 // Wait for the backup timer to fire (add some slop to ensure it fires) 2613 // Wait for the backup timer to fire (add some slop to ensure it fires)
2614 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( 2614 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(
2615 ClientSocketPool::kMaxConnectRetryIntervalMs / 2 * 3)); 2615 ClientSocketPool::kMaxConnectRetryIntervalMs / 2 * 3));
2616 base::MessageLoop::current()->RunUntilIdle(); 2616 base::RunLoop().RunUntilIdle();
2617 } 2617 }
2618 2618
2619 // Test delayed socket binding for the case where we have two connects, 2619 // Test delayed socket binding for the case where we have two connects,
2620 // and while one is waiting on a connect, the other frees up. 2620 // and while one is waiting on a connect, the other frees up.
2621 // The socket waiting on a connect should switch immediately to the freed 2621 // The socket waiting on a connect should switch immediately to the freed
2622 // up socket. 2622 // up socket.
2623 TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingWaitingForConnect) { 2623 TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingWaitingForConnect) {
2624 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 2624 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
2625 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); 2625 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
2626 2626
(...skipping 17 matching lines...) Expand all
2644 ClientSocketPool::RespectLimits::ENABLED, 2644 ClientSocketPool::RespectLimits::ENABLED,
2645 callback.callback(), pool_.get(), BoundNetLog())); 2645 callback.callback(), pool_.get(), BoundNetLog()));
2646 // No idle sockets, and one connecting job. 2646 // No idle sockets, and one connecting job.
2647 EXPECT_EQ(0, pool_->IdleSocketCount()); 2647 EXPECT_EQ(0, pool_->IdleSocketCount());
2648 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); 2648 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
2649 2649
2650 // Return the first handle to the pool. This will initiate the delayed 2650 // Return the first handle to the pool. This will initiate the delayed
2651 // binding. 2651 // binding.
2652 handle1.Reset(); 2652 handle1.Reset();
2653 2653
2654 base::MessageLoop::current()->RunUntilIdle(); 2654 base::RunLoop().RunUntilIdle();
2655 2655
2656 // Still no idle sockets, still one pending connect job. 2656 // Still no idle sockets, still one pending connect job.
2657 EXPECT_EQ(0, pool_->IdleSocketCount()); 2657 EXPECT_EQ(0, pool_->IdleSocketCount());
2658 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); 2658 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
2659 2659
2660 // The second socket connected, even though it was a Waiting Job. 2660 // The second socket connected, even though it was a Waiting Job.
2661 EXPECT_EQ(OK, callback.WaitForResult()); 2661 EXPECT_EQ(OK, callback.WaitForResult());
2662 2662
2663 // And we can see there is still one job waiting. 2663 // And we can see there is still one job waiting.
2664 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); 2664 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
2665 2665
2666 // Finally, signal the waiting Connect. 2666 // Finally, signal the waiting Connect.
2667 client_socket_factory_.SignalJobs(); 2667 client_socket_factory_.SignalJobs();
2668 EXPECT_EQ(0, pool_->NumConnectJobsInGroup("a")); 2668 EXPECT_EQ(0, pool_->NumConnectJobsInGroup("a"));
2669 2669
2670 base::MessageLoop::current()->RunUntilIdle(); 2670 base::RunLoop().RunUntilIdle();
2671 } 2671 }
2672 2672
2673 // Test delayed socket binding when a group is at capacity and one 2673 // Test delayed socket binding when a group is at capacity and one
2674 // of the group's sockets frees up. 2674 // of the group's sockets frees up.
2675 TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingAtGroupCapacity) { 2675 TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingAtGroupCapacity) {
2676 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 2676 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
2677 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); 2677 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
2678 2678
2679 ClientSocketHandle handle1; 2679 ClientSocketHandle handle1;
2680 TestCompletionCallback callback; 2680 TestCompletionCallback callback;
(...skipping 15 matching lines...) Expand all
2696 ClientSocketPool::RespectLimits::ENABLED, 2696 ClientSocketPool::RespectLimits::ENABLED,
2697 callback.callback(), pool_.get(), BoundNetLog())); 2697 callback.callback(), pool_.get(), BoundNetLog()));
2698 // No idle sockets, and one connecting job. 2698 // No idle sockets, and one connecting job.
2699 EXPECT_EQ(0, pool_->IdleSocketCount()); 2699 EXPECT_EQ(0, pool_->IdleSocketCount());
2700 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); 2700 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
2701 2701
2702 // Return the first handle to the pool. This will initiate the delayed 2702 // Return the first handle to the pool. This will initiate the delayed
2703 // binding. 2703 // binding.
2704 handle1.Reset(); 2704 handle1.Reset();
2705 2705
2706 base::MessageLoop::current()->RunUntilIdle(); 2706 base::RunLoop().RunUntilIdle();
2707 2707
2708 // Still no idle sockets, still one pending connect job. 2708 // Still no idle sockets, still one pending connect job.
2709 EXPECT_EQ(0, pool_->IdleSocketCount()); 2709 EXPECT_EQ(0, pool_->IdleSocketCount());
2710 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); 2710 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
2711 2711
2712 // The second socket connected, even though it was a Waiting Job. 2712 // The second socket connected, even though it was a Waiting Job.
2713 EXPECT_EQ(OK, callback.WaitForResult()); 2713 EXPECT_EQ(OK, callback.WaitForResult());
2714 2714
2715 // And we can see there is still one job waiting. 2715 // And we can see there is still one job waiting.
2716 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); 2716 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
2717 2717
2718 // Finally, signal the waiting Connect. 2718 // Finally, signal the waiting Connect.
2719 client_socket_factory_.SignalJobs(); 2719 client_socket_factory_.SignalJobs();
2720 EXPECT_EQ(0, pool_->NumConnectJobsInGroup("a")); 2720 EXPECT_EQ(0, pool_->NumConnectJobsInGroup("a"));
2721 2721
2722 base::MessageLoop::current()->RunUntilIdle(); 2722 base::RunLoop().RunUntilIdle();
2723 } 2723 }
2724 2724
2725 // Test out the case where we have one socket connected, one 2725 // Test out the case where we have one socket connected, one
2726 // connecting, when the first socket finishes and goes idle. 2726 // connecting, when the first socket finishes and goes idle.
2727 // Although the second connection is pending, the second request 2727 // Although the second connection is pending, the second request
2728 // should complete, by taking the first socket's idle socket. 2728 // should complete, by taking the first socket's idle socket.
2729 TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingAtStall) { 2729 TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingAtStall) {
2730 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 2730 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
2731 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); 2731 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
2732 2732
(...skipping 17 matching lines...) Expand all
2750 ClientSocketPool::RespectLimits::ENABLED, 2750 ClientSocketPool::RespectLimits::ENABLED,
2751 callback.callback(), pool_.get(), BoundNetLog())); 2751 callback.callback(), pool_.get(), BoundNetLog()));
2752 // No idle sockets, and one connecting job. 2752 // No idle sockets, and one connecting job.
2753 EXPECT_EQ(0, pool_->IdleSocketCount()); 2753 EXPECT_EQ(0, pool_->IdleSocketCount());
2754 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); 2754 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
2755 2755
2756 // Return the first handle to the pool. This will initiate the delayed 2756 // Return the first handle to the pool. This will initiate the delayed
2757 // binding. 2757 // binding.
2758 handle1.Reset(); 2758 handle1.Reset();
2759 2759
2760 base::MessageLoop::current()->RunUntilIdle(); 2760 base::RunLoop().RunUntilIdle();
2761 2761
2762 // Still no idle sockets, still one pending connect job. 2762 // Still no idle sockets, still one pending connect job.
2763 EXPECT_EQ(0, pool_->IdleSocketCount()); 2763 EXPECT_EQ(0, pool_->IdleSocketCount());
2764 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); 2764 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
2765 2765
2766 // The second socket connected, even though it was a Waiting Job. 2766 // The second socket connected, even though it was a Waiting Job.
2767 EXPECT_EQ(OK, callback.WaitForResult()); 2767 EXPECT_EQ(OK, callback.WaitForResult());
2768 2768
2769 // And we can see there is still one job waiting. 2769 // And we can see there is still one job waiting.
2770 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); 2770 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
2771 2771
2772 // Finally, signal the waiting Connect. 2772 // Finally, signal the waiting Connect.
2773 client_socket_factory_.SignalJobs(); 2773 client_socket_factory_.SignalJobs();
2774 EXPECT_EQ(0, pool_->NumConnectJobsInGroup("a")); 2774 EXPECT_EQ(0, pool_->NumConnectJobsInGroup("a"));
2775 2775
2776 base::MessageLoop::current()->RunUntilIdle(); 2776 base::RunLoop().RunUntilIdle();
2777 } 2777 }
2778 2778
2779 // Cover the case where on an available socket slot, we have one pending 2779 // Cover the case where on an available socket slot, we have one pending
2780 // request that completes synchronously, thereby making the Group empty. 2780 // request that completes synchronously, thereby making the Group empty.
2781 TEST_F(ClientSocketPoolBaseTest, SynchronouslyProcessOnePendingRequest) { 2781 TEST_F(ClientSocketPoolBaseTest, SynchronouslyProcessOnePendingRequest) {
2782 const int kUnlimitedSockets = 100; 2782 const int kUnlimitedSockets = 100;
2783 const int kOneSocketPerGroup = 1; 2783 const int kOneSocketPerGroup = 1;
2784 CreatePool(kUnlimitedSockets, kOneSocketPerGroup); 2784 CreatePool(kUnlimitedSockets, kOneSocketPerGroup);
2785 2785
2786 // Make the first request asynchronous fail. 2786 // Make the first request asynchronous fail.
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
3355 EXPECT_EQ(1, pool_->NumUnassignedConnectJobsInGroup("a")); 3355 EXPECT_EQ(1, pool_->NumUnassignedConnectJobsInGroup("a"));
3356 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); 3356 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a"));
3357 3357
3358 // Verify the backup timer doesn't create a backup job, by making 3358 // Verify the backup timer doesn't create a backup job, by making
3359 // the backup job a pending job instead of a waiting job, so it 3359 // the backup job a pending job instead of a waiting job, so it
3360 // *would* complete if it were created. 3360 // *would* complete if it were created.
3361 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); 3361 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
3362 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 3362 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
3363 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), 3363 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
3364 base::TimeDelta::FromSeconds(1)); 3364 base::TimeDelta::FromSeconds(1));
3365 base::MessageLoop::current()->Run(); 3365 base::RunLoop().Run();
3366 EXPECT_FALSE(pool_->HasGroup("a")); 3366 EXPECT_FALSE(pool_->HasGroup("a"));
3367 } 3367 }
3368 3368
3369 TEST_F(ClientSocketPoolBaseTest, PreconnectWithBackupJob) { 3369 TEST_F(ClientSocketPoolBaseTest, PreconnectWithBackupJob) {
3370 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 3370 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
3371 pool_->EnableConnectBackupJobs(); 3371 pool_->EnableConnectBackupJobs();
3372 3372
3373 // Make the ConnectJob hang forever. 3373 // Make the ConnectJob hang forever.
3374 connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); 3374 connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob);
3375 pool_->RequestSockets("a", &params_, 1, BoundNetLog()); 3375 pool_->RequestSockets("a", &params_, 1, BoundNetLog());
3376 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); 3376 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
3377 EXPECT_EQ(1, pool_->NumUnassignedConnectJobsInGroup("a")); 3377 EXPECT_EQ(1, pool_->NumUnassignedConnectJobsInGroup("a"));
3378 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); 3378 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a"));
3379 base::MessageLoop::current()->RunUntilIdle(); 3379 base::RunLoop().RunUntilIdle();
3380 3380
3381 // Make the backup job be a pending job, so it completes normally. 3381 // Make the backup job be a pending job, so it completes normally.
3382 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); 3382 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
3383 ClientSocketHandle handle; 3383 ClientSocketHandle handle;
3384 TestCompletionCallback callback; 3384 TestCompletionCallback callback;
3385 EXPECT_EQ(ERR_IO_PENDING, 3385 EXPECT_EQ(ERR_IO_PENDING,
3386 handle.Init("a", params_, DEFAULT_PRIORITY, 3386 handle.Init("a", params_, DEFAULT_PRIORITY,
3387 ClientSocketPool::RespectLimits::ENABLED, 3387 ClientSocketPool::RespectLimits::ENABLED,
3388 callback.callback(), pool_.get(), BoundNetLog())); 3388 callback.callback(), pool_.get(), BoundNetLog()));
3389 // Timer has started, but the backup connect job shouldn't be created yet. 3389 // Timer has started, but the backup connect job shouldn't be created yet.
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
3761 request(1)->handle()->Reset(); 3761 request(1)->handle()->Reset();
3762 ASSERT_EQ(1, pool_->NumConnectJobsInGroup("a")); 3762 ASSERT_EQ(1, pool_->NumConnectJobsInGroup("a"));
3763 3763
3764 EXPECT_EQ(OK, request(2)->WaitForResult()); 3764 EXPECT_EQ(OK, request(2)->WaitForResult());
3765 EXPECT_FALSE(request(1)->have_result()); 3765 EXPECT_FALSE(request(1)->have_result());
3766 } 3766 }
3767 3767
3768 } // namespace 3768 } // namespace
3769 3769
3770 } // namespace net 3770 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_resolver_v8_tracing_wrapper_unittest.cc ('k') | net/socket/ssl_server_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698