| Index: net/socket/client_socket_pool_base_unittest.cc
|
| diff --git a/net/socket/client_socket_pool_base_unittest.cc b/net/socket/client_socket_pool_base_unittest.cc
|
| index 985a4c59988a7fb4793d3ac2903346f98d639279..dfadeaf8095e0268d7f91ae934d2780ac5cd1e1f 100644
|
| --- a/net/socket/client_socket_pool_base_unittest.cc
|
| +++ b/net/socket/client_socket_pool_base_unittest.cc
|
| @@ -492,6 +492,10 @@ class TestClientSocketPool : public ClientSocketPool {
|
|
|
| void EnableConnectBackupJobs() { base_.EnableConnectBackupJobs(); }
|
|
|
| + void UseCleanupTimer(bool enabled) {
|
| + base_.SetCleanupTimerEnabled(enabled);
|
| + }
|
| +
|
| private:
|
| TestClientSocketPoolBase base_;
|
|
|
| @@ -1946,6 +1950,83 @@ TEST_F(ClientSocketPoolBaseTest, AdditionalErrorStateAsynchronous) {
|
| EXPECT_FALSE(handle.ssl_error_response_info().headers.get() == NULL);
|
| }
|
|
|
| +TEST_F(ClientSocketPoolBaseTest, DisableCleanupTimer) {
|
| + CreatePoolWithIdleTimeouts(
|
| + kDefaultMaxSockets, kDefaultMaxSocketsPerGroup,
|
| + base::TimeDelta::FromMilliseconds(10), // Time out unused sockets
|
| + base::TimeDelta::FromMilliseconds(10)); // Time out used sockets
|
| +
|
| + // Disable cleanup timer.
|
| + pool_->UseCleanupTimer(false);
|
| +
|
| + connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
|
| +
|
| + // Startup two mock pending connect jobs, which will sit in the MessageLoop.
|
| +
|
| + ClientSocketHandle handle;
|
| + TestOldCompletionCallback callback;
|
| + int rv = handle.Init("a",
|
| + params_,
|
| + LOWEST,
|
| + &callback,
|
| + pool_.get(),
|
| + BoundNetLog());
|
| + EXPECT_EQ(ERR_IO_PENDING, rv);
|
| + EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle));
|
| +
|
| + ClientSocketHandle handle2;
|
| + TestOldCompletionCallback callback2;
|
| + rv = handle2.Init("a",
|
| + params_,
|
| + LOWEST,
|
| + &callback2,
|
| + pool_.get(),
|
| + BoundNetLog());
|
| + EXPECT_EQ(ERR_IO_PENDING, rv);
|
| + EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle2));
|
| +
|
| + // Cancel one of the requests. Wait for the other, which will get the first
|
| + // job. Release the socket. Run the loop again to make sure the second
|
| + // socket is sitting idle and the first one is released (since ReleaseSocket()
|
| + // just posts a DoReleaseSocket() task).
|
| +
|
| + handle.Reset();
|
| + EXPECT_EQ(OK, callback2.WaitForResult());
|
| + // Use the socket.
|
| + EXPECT_EQ(1, handle2.socket()->Write(NULL, 1, NULL));
|
| + handle2.Reset();
|
| +
|
| + // We post all of our delayed tasks with a 2ms delay. I.e. they don't
|
| + // actually become pending until 2ms after they have been created. In order
|
| + // to flush all tasks, we need to wait so that we know there are no
|
| + // soon-to-be-pending tasks waiting.
|
| + base::PlatformThread::Sleep(20);
|
| + MessageLoop::current()->RunAllPending();
|
| +
|
| + ASSERT_EQ(2, pool_->IdleSocketCount());
|
| +
|
| + // Request a new socket. This should cleanup the unused and timed out ones.
|
| + CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
|
| + rv = handle.Init("a",
|
| + params_,
|
| + LOWEST,
|
| + &callback,
|
| + pool_.get(),
|
| + log.bound());
|
| + EXPECT_EQ(OK, rv);
|
| + EXPECT_TRUE(handle.is_reused());
|
| +
|
| + // Make sure the idle socket is closed
|
| + ASSERT_TRUE(pool_->HasGroup("a"));
|
| + EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a"));
|
| + EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a"));
|
| +
|
| + net::CapturingNetLog::EntryList entries;
|
| + log.GetEntries(&entries);
|
| + EXPECT_TRUE(LogContainsEntryWithType(
|
| + entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET));
|
| +}
|
| +
|
| TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSockets) {
|
| CreatePoolWithIdleTimeouts(
|
| kDefaultMaxSockets, kDefaultMaxSocketsPerGroup,
|
|
|