OLD | NEW |
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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 } | 412 } |
413 | 413 |
414 const TestClientSocketPoolBase* base() const { return &base_; } | 414 const TestClientSocketPoolBase* base() const { return &base_; } |
415 | 415 |
416 int NumConnectJobsInGroup(const std::string& group_name) const { | 416 int NumConnectJobsInGroup(const std::string& group_name) const { |
417 return base_.NumConnectJobsInGroup(group_name); | 417 return base_.NumConnectJobsInGroup(group_name); |
418 } | 418 } |
419 | 419 |
420 void CleanupTimedOutIdleSockets() { base_.CleanupIdleSockets(false); } | 420 void CleanupTimedOutIdleSockets() { base_.CleanupIdleSockets(false); } |
421 | 421 |
422 void EnableBackupJobs() { base_.EnableBackupJobs(); } | 422 void EnableConnectBackupJobs() { base_.EnableConnectBackupJobs(); } |
423 | 423 |
424 private: | 424 private: |
425 ~TestClientSocketPool() {} | 425 ~TestClientSocketPool() {} |
426 | 426 |
427 TestClientSocketPoolBase base_; | 427 TestClientSocketPoolBase base_; |
428 | 428 |
429 DISALLOW_COPY_AND_ASSIGN(TestClientSocketPool); | 429 DISALLOW_COPY_AND_ASSIGN(TestClientSocketPool); |
430 }; | 430 }; |
431 | 431 |
432 } // namespace | 432 } // namespace |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 // preference of the waiting request. | 988 // preference of the waiting request. |
989 EXPECT_EQ(OK, callback.WaitForResult()); | 989 EXPECT_EQ(OK, callback.WaitForResult()); |
990 | 990 |
991 EXPECT_EQ(kDefaultMaxSockets + 1, client_socket_factory_.allocation_count()); | 991 EXPECT_EQ(kDefaultMaxSockets + 1, client_socket_factory_.allocation_count()); |
992 EXPECT_EQ(3, pool_->IdleSocketCount()); | 992 EXPECT_EQ(3, pool_->IdleSocketCount()); |
993 } | 993 } |
994 | 994 |
995 // Regression test for http://crbug.com/40952. | 995 // Regression test for http://crbug.com/40952. |
996 TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketAtSocketLimitDeleteGroup) { | 996 TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketAtSocketLimitDeleteGroup) { |
997 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 997 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
998 pool_->EnableBackupJobs(); | 998 pool_->EnableConnectBackupJobs(); |
999 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); | 999 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
1000 | 1000 |
1001 for (int i = 0; i < kDefaultMaxSockets; ++i) { | 1001 for (int i = 0; i < kDefaultMaxSockets; ++i) { |
1002 ClientSocketHandle handle; | 1002 ClientSocketHandle handle; |
1003 TestCompletionCallback callback; | 1003 TestCompletionCallback callback; |
1004 EXPECT_EQ(OK, handle.Init(base::IntToString(i), params_, kDefaultPriority, | 1004 EXPECT_EQ(OK, handle.Init(base::IntToString(i), params_, kDefaultPriority, |
1005 &callback, pool_, BoundNetLog())); | 1005 &callback, pool_, BoundNetLog())); |
1006 } | 1006 } |
1007 | 1007 |
1008 // Flush all the DoReleaseSocket tasks. | 1008 // Flush all the DoReleaseSocket tasks. |
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1916 &callback, pool_, BoundNetLog())); | 1916 &callback, pool_, BoundNetLog())); |
1917 EXPECT_EQ(OK, callback.WaitForResult()); | 1917 EXPECT_EQ(OK, callback.WaitForResult()); |
1918 EXPECT_EQ(ClientSocketHandle::UNUSED, handle.reuse_type()); | 1918 EXPECT_EQ(ClientSocketHandle::UNUSED, handle.reuse_type()); |
1919 } | 1919 } |
1920 | 1920 |
1921 // Cancel a pending socket request while we're at max sockets, | 1921 // Cancel a pending socket request while we're at max sockets, |
1922 // and verify that the backup socket firing doesn't cause a crash. | 1922 // and verify that the backup socket firing doesn't cause a crash. |
1923 TEST_F(ClientSocketPoolBaseTest, BackupSocketCancelAtMaxSockets) { | 1923 TEST_F(ClientSocketPoolBaseTest, BackupSocketCancelAtMaxSockets) { |
1924 // Max 4 sockets globally, max 4 sockets per group. | 1924 // Max 4 sockets globally, max 4 sockets per group. |
1925 CreatePool(kDefaultMaxSockets, kDefaultMaxSockets); | 1925 CreatePool(kDefaultMaxSockets, kDefaultMaxSockets); |
1926 pool_->EnableBackupJobs(); | 1926 pool_->EnableConnectBackupJobs(); |
1927 | 1927 |
1928 // Create the first socket and set to ERR_IO_PENDING. This creates a | 1928 // Create the first socket and set to ERR_IO_PENDING. This creates a |
1929 // backup job. | 1929 // backup job. |
1930 connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); | 1930 connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
1931 ClientSocketHandle handle; | 1931 ClientSocketHandle handle; |
1932 TestCompletionCallback callback; | 1932 TestCompletionCallback callback; |
1933 EXPECT_EQ(ERR_IO_PENDING, handle.Init("bar", params_, kDefaultPriority, | 1933 EXPECT_EQ(ERR_IO_PENDING, handle.Init("bar", params_, kDefaultPriority, |
1934 &callback, pool_, BoundNetLog())); | 1934 &callback, pool_, BoundNetLog())); |
1935 | 1935 |
1936 // Start (MaxSockets - 1) connected sockets to reach max sockets. | 1936 // Start (MaxSockets - 1) connected sockets to reach max sockets. |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2098 // Finally, signal the waiting Connect. | 2098 // Finally, signal the waiting Connect. |
2099 client_socket_factory_.SignalJobs(); | 2099 client_socket_factory_.SignalJobs(); |
2100 EXPECT_EQ(0, pool_->NumConnectJobsInGroup("a")); | 2100 EXPECT_EQ(0, pool_->NumConnectJobsInGroup("a")); |
2101 | 2101 |
2102 MessageLoop::current()->RunAllPending(); | 2102 MessageLoop::current()->RunAllPending(); |
2103 } | 2103 } |
2104 | 2104 |
2105 } // namespace | 2105 } // namespace |
2106 | 2106 |
2107 } // namespace net | 2107 } // namespace net |
OLD | NEW |