| 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 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 return handle->Init<TestSocketParams, TestClientSocketPool>( | 464 return handle->Init<TestSocketParams, TestClientSocketPool>( |
| 465 group_name, NULL, priority, callback, pool, net_log); | 465 group_name, NULL, priority, callback, pool, net_log); |
| 466 } | 466 } |
| 467 | 467 |
| 468 // Even though a timeout is specified, it doesn't time out on a synchronous | 468 // Even though a timeout is specified, it doesn't time out on a synchronous |
| 469 // completion. | 469 // completion. |
| 470 TEST_F(ClientSocketPoolBaseTest, ConnectJob_NoTimeoutOnSynchronousCompletion) { | 470 TEST_F(ClientSocketPoolBaseTest, ConnectJob_NoTimeoutOnSynchronousCompletion) { |
| 471 TestConnectJobDelegate delegate; | 471 TestConnectJobDelegate delegate; |
| 472 ClientSocketHandle ignored; | 472 ClientSocketHandle ignored; |
| 473 TestClientSocketPoolBase::Request request( | 473 TestClientSocketPoolBase::Request request( |
| 474 &ignored, NULL, kDefaultPriority, NULL, NULL); | 474 &ignored, NULL, kDefaultPriority, NULL, BoundNetLog()); |
| 475 scoped_ptr<TestConnectJob> job( | 475 scoped_ptr<TestConnectJob> job( |
| 476 new TestConnectJob(TestConnectJob::kMockJob, | 476 new TestConnectJob(TestConnectJob::kMockJob, |
| 477 "a", | 477 "a", |
| 478 request, | 478 request, |
| 479 base::TimeDelta::FromMicroseconds(1), | 479 base::TimeDelta::FromMicroseconds(1), |
| 480 &delegate, | 480 &delegate, |
| 481 &client_socket_factory_, | 481 &client_socket_factory_, |
| 482 NULL)); | 482 BoundNetLog())); |
| 483 EXPECT_EQ(OK, job->Connect()); | 483 EXPECT_EQ(OK, job->Connect()); |
| 484 } | 484 } |
| 485 | 485 |
| 486 TEST_F(ClientSocketPoolBaseTest, ConnectJob_TimedOut) { | 486 TEST_F(ClientSocketPoolBaseTest, ConnectJob_TimedOut) { |
| 487 TestConnectJobDelegate delegate; | 487 TestConnectJobDelegate delegate; |
| 488 ClientSocketHandle ignored; | 488 ClientSocketHandle ignored; |
| 489 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 489 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
| 490 | 490 |
| 491 TestClientSocketPoolBase::Request request( | 491 TestClientSocketPoolBase::Request request( |
| 492 &ignored, NULL, kDefaultPriority, NULL, NULL); | 492 &ignored, NULL, kDefaultPriority, NULL, BoundNetLog()); |
| 493 // Deleted by TestConnectJobDelegate. | 493 // Deleted by TestConnectJobDelegate. |
| 494 TestConnectJob* job = | 494 TestConnectJob* job = |
| 495 new TestConnectJob(TestConnectJob::kMockPendingJob, | 495 new TestConnectJob(TestConnectJob::kMockPendingJob, |
| 496 "a", | 496 "a", |
| 497 request, | 497 request, |
| 498 base::TimeDelta::FromMicroseconds(1), | 498 base::TimeDelta::FromMicroseconds(1), |
| 499 &delegate, | 499 &delegate, |
| 500 &client_socket_factory_, | 500 &client_socket_factory_, |
| 501 log.bound()); | 501 log.bound()); |
| 502 ASSERT_EQ(ERR_IO_PENDING, job->Connect()); | 502 ASSERT_EQ(ERR_IO_PENDING, job->Connect()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 | 549 |
| 550 connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); | 550 connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); |
| 551 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 551 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
| 552 | 552 |
| 553 TestSocketRequest req(&request_order_, &completion_count_); | 553 TestSocketRequest req(&request_order_, &completion_count_); |
| 554 EXPECT_EQ(ERR_CONNECTION_FAILED, | 554 EXPECT_EQ(ERR_CONNECTION_FAILED, |
| 555 InitHandle(req.handle(), "a", kDefaultPriority, &req, pool_, | 555 InitHandle(req.handle(), "a", kDefaultPriority, &req, pool_, |
| 556 log.bound())); | 556 log.bound())); |
| 557 | 557 |
| 558 EXPECT_EQ(6u, log.entries().size()); | 558 EXPECT_EQ(6u, log.entries().size()); |
| 559 EXPECT_TRUE(LogContainsBeginEvent(log.entries(), 0, NetLog::TYPE_SOCKET_POOL))
; | 559 EXPECT_TRUE(LogContainsBeginEvent( |
| 560 log.entries(), 0, NetLog::TYPE_SOCKET_POOL)); |
| 560 EXPECT_TRUE(LogContainsBeginEvent( | 561 EXPECT_TRUE(LogContainsBeginEvent( |
| 561 log.entries(), 2, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); | 562 log.entries(), 2, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); |
| 562 EXPECT_TRUE(LogContainsEndEvent( | 563 EXPECT_TRUE(LogContainsEndEvent( |
| 563 log.entries(), 3, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); | 564 log.entries(), 3, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); |
| 564 EXPECT_TRUE(LogContainsEndEvent(log.entries(), 5, NetLog::TYPE_SOCKET_POOL)); | 565 EXPECT_TRUE(LogContainsEndEvent(log.entries(), 5, NetLog::TYPE_SOCKET_POOL)); |
| 565 } | 566 } |
| 566 | 567 |
| 567 TEST_F(ClientSocketPoolBaseTest, TotalLimit) { | 568 TEST_F(ClientSocketPoolBaseTest, TotalLimit) { |
| 568 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 569 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 569 | 570 |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 | 882 |
| 882 // This test will start up a RequestSocket() and then immediately Cancel() it. | 883 // This test will start up a RequestSocket() and then immediately Cancel() it. |
| 883 // The pending connect job will be cancelled and should not call back into | 884 // The pending connect job will be cancelled and should not call back into |
| 884 // ClientSocketPoolBase. | 885 // ClientSocketPoolBase. |
| 885 TEST_F(ClientSocketPoolBaseTest, CancelRequestClearGroup) { | 886 TEST_F(ClientSocketPoolBaseTest, CancelRequestClearGroup) { |
| 886 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 887 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 887 | 888 |
| 888 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 889 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 889 TestSocketRequest req(&request_order_, &completion_count_); | 890 TestSocketRequest req(&request_order_, &completion_count_); |
| 890 EXPECT_EQ(ERR_IO_PENDING, | 891 EXPECT_EQ(ERR_IO_PENDING, |
| 891 InitHandle(req.handle(), "a", kDefaultPriority, &req, pool_, NULL)); | 892 InitHandle(req.handle(), "a", kDefaultPriority, &req, pool_, |
| 893 BoundNetLog())); |
| 892 req.handle()->Reset(); | 894 req.handle()->Reset(); |
| 893 } | 895 } |
| 894 | 896 |
| 895 TEST_F(ClientSocketPoolBaseTest, ConnectCancelConnect) { | 897 TEST_F(ClientSocketPoolBaseTest, ConnectCancelConnect) { |
| 896 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 898 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 897 | 899 |
| 898 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 900 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 899 ClientSocketHandle handle; | 901 ClientSocketHandle handle; |
| 900 TestCompletionCallback callback; | 902 TestCompletionCallback callback; |
| 901 TestSocketRequest req(&request_order_, &completion_count_); | 903 TestSocketRequest req(&request_order_, &completion_count_); |
| 902 | 904 |
| 903 EXPECT_EQ(ERR_IO_PENDING, | 905 EXPECT_EQ(ERR_IO_PENDING, |
| 904 InitHandle(&handle, "a", kDefaultPriority, &callback, pool_, NULL)); | 906 InitHandle(&handle, "a", kDefaultPriority, &callback, pool_, |
| 907 BoundNetLog())); |
| 905 | 908 |
| 906 handle.Reset(); | 909 handle.Reset(); |
| 907 | 910 |
| 908 TestCompletionCallback callback2; | 911 TestCompletionCallback callback2; |
| 909 EXPECT_EQ(ERR_IO_PENDING, InitHandle(&handle, "a", kDefaultPriority, | 912 EXPECT_EQ(ERR_IO_PENDING, InitHandle(&handle, "a", kDefaultPriority, |
| 910 &callback2, pool_, NULL)); | 913 &callback2, pool_, BoundNetLog())); |
| 911 | 914 |
| 912 EXPECT_EQ(OK, callback2.WaitForResult()); | 915 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 913 EXPECT_FALSE(callback.have_result()); | 916 EXPECT_FALSE(callback.have_result()); |
| 914 | 917 |
| 915 handle.Reset(); | 918 handle.Reset(); |
| 916 } | 919 } |
| 917 | 920 |
| 918 TEST_F(ClientSocketPoolBaseTest, CancelRequest) { | 921 TEST_F(ClientSocketPoolBaseTest, CancelRequest) { |
| 919 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 922 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 920 | 923 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 handle_->socket()->Disconnect(); | 977 handle_->socket()->Disconnect(); |
| 975 handle_->Reset(); | 978 handle_->Reset(); |
| 976 { | 979 { |
| 977 MessageLoop::ScopedNestableTaskAllower nestable( | 980 MessageLoop::ScopedNestableTaskAllower nestable( |
| 978 MessageLoop::current()); | 981 MessageLoop::current()); |
| 979 MessageLoop::current()->RunAllPending(); | 982 MessageLoop::current()->RunAllPending(); |
| 980 } | 983 } |
| 981 within_callback_ = true; | 984 within_callback_ = true; |
| 982 TestCompletionCallback next_job_callback; | 985 TestCompletionCallback next_job_callback; |
| 983 int rv = InitHandle(handle_, "a", kDefaultPriority, &next_job_callback, | 986 int rv = InitHandle(handle_, "a", kDefaultPriority, &next_job_callback, |
| 984 pool_, NULL); | 987 pool_, BoundNetLog()); |
| 985 switch (next_job_type_) { | 988 switch (next_job_type_) { |
| 986 case TestConnectJob::kMockJob: | 989 case TestConnectJob::kMockJob: |
| 987 EXPECT_EQ(OK, rv); | 990 EXPECT_EQ(OK, rv); |
| 988 break; | 991 break; |
| 989 case TestConnectJob::kMockPendingJob: | 992 case TestConnectJob::kMockPendingJob: |
| 990 EXPECT_EQ(ERR_IO_PENDING, rv); | 993 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 991 | 994 |
| 992 // For pending jobs, wait for new socket to be created. This makes | 995 // For pending jobs, wait for new socket to be created. This makes |
| 993 // sure there are no more pending operations nor any unclosed sockets | 996 // sure there are no more pending operations nor any unclosed sockets |
| 994 // when the test finishes. | 997 // when the test finishes. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1023 }; | 1026 }; |
| 1024 | 1027 |
| 1025 TEST_F(ClientSocketPoolBaseTest, RequestPendingJobTwice) { | 1028 TEST_F(ClientSocketPoolBaseTest, RequestPendingJobTwice) { |
| 1026 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1029 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1027 | 1030 |
| 1028 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 1031 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 1029 ClientSocketHandle handle; | 1032 ClientSocketHandle handle; |
| 1030 RequestSocketCallback callback( | 1033 RequestSocketCallback callback( |
| 1031 &handle, pool_.get(), connect_job_factory_, | 1034 &handle, pool_.get(), connect_job_factory_, |
| 1032 TestConnectJob::kMockPendingJob); | 1035 TestConnectJob::kMockPendingJob); |
| 1033 int rv = InitHandle(&handle, "a", kDefaultPriority, &callback, pool_, NULL); | 1036 int rv = InitHandle(&handle, "a", kDefaultPriority, &callback, pool_, |
| 1037 BoundNetLog()); |
| 1034 ASSERT_EQ(ERR_IO_PENDING, rv); | 1038 ASSERT_EQ(ERR_IO_PENDING, rv); |
| 1035 | 1039 |
| 1036 EXPECT_EQ(OK, callback.WaitForResult()); | 1040 EXPECT_EQ(OK, callback.WaitForResult()); |
| 1037 } | 1041 } |
| 1038 | 1042 |
| 1039 TEST_F(ClientSocketPoolBaseTest, RequestPendingJobThenSynchronous) { | 1043 TEST_F(ClientSocketPoolBaseTest, RequestPendingJobThenSynchronous) { |
| 1040 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1044 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1041 | 1045 |
| 1042 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 1046 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 1043 ClientSocketHandle handle; | 1047 ClientSocketHandle handle; |
| 1044 RequestSocketCallback callback( | 1048 RequestSocketCallback callback( |
| 1045 &handle, pool_.get(), connect_job_factory_, TestConnectJob::kMockJob); | 1049 &handle, pool_.get(), connect_job_factory_, TestConnectJob::kMockJob); |
| 1046 int rv = InitHandle(&handle, "a", kDefaultPriority, &callback, pool_, NULL); | 1050 int rv = InitHandle(&handle, "a", kDefaultPriority, &callback, pool_, |
| 1051 BoundNetLog()); |
| 1047 ASSERT_EQ(ERR_IO_PENDING, rv); | 1052 ASSERT_EQ(ERR_IO_PENDING, rv); |
| 1048 | 1053 |
| 1049 EXPECT_EQ(OK, callback.WaitForResult()); | 1054 EXPECT_EQ(OK, callback.WaitForResult()); |
| 1050 } | 1055 } |
| 1051 | 1056 |
| 1052 // Make sure that pending requests get serviced after active requests get | 1057 // Make sure that pending requests get serviced after active requests get |
| 1053 // cancelled. | 1058 // cancelled. |
| 1054 TEST_F(ClientSocketPoolBaseTest, CancelActiveRequestWithPendingRequests) { | 1059 TEST_F(ClientSocketPoolBaseTest, CancelActiveRequestWithPendingRequests) { |
| 1055 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1060 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1056 | 1061 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1097 for (size_t i = 0; i < kNumberOfRequests; ++i) | 1102 for (size_t i = 0; i < kNumberOfRequests; ++i) |
| 1098 EXPECT_EQ(ERR_CONNECTION_FAILED, requests_[i]->WaitForResult()); | 1103 EXPECT_EQ(ERR_CONNECTION_FAILED, requests_[i]->WaitForResult()); |
| 1099 } | 1104 } |
| 1100 | 1105 |
| 1101 TEST_F(ClientSocketPoolBaseTest, CancelActiveRequestThenRequestSocket) { | 1106 TEST_F(ClientSocketPoolBaseTest, CancelActiveRequestThenRequestSocket) { |
| 1102 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1107 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1103 | 1108 |
| 1104 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 1109 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 1105 | 1110 |
| 1106 TestSocketRequest req(&request_order_, &completion_count_); | 1111 TestSocketRequest req(&request_order_, &completion_count_); |
| 1107 int rv = InitHandle(req.handle(), "a", kDefaultPriority, &req, pool_, NULL); | 1112 int rv = InitHandle(req.handle(), "a", kDefaultPriority, &req, pool_, |
| 1113 BoundNetLog()); |
| 1108 EXPECT_EQ(ERR_IO_PENDING, rv); | 1114 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1109 | 1115 |
| 1110 // Cancel the active request. | 1116 // Cancel the active request. |
| 1111 req.handle()->Reset(); | 1117 req.handle()->Reset(); |
| 1112 | 1118 |
| 1113 rv = InitHandle(req.handle(), "a", kDefaultPriority, &req, pool_, NULL); | 1119 rv = InitHandle(req.handle(), "a", kDefaultPriority, &req, pool_, |
| 1120 BoundNetLog()); |
| 1114 EXPECT_EQ(ERR_IO_PENDING, rv); | 1121 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1115 EXPECT_EQ(OK, req.WaitForResult()); | 1122 EXPECT_EQ(OK, req.WaitForResult()); |
| 1116 | 1123 |
| 1117 EXPECT_FALSE(req.handle()->is_reused()); | 1124 EXPECT_FALSE(req.handle()->is_reused()); |
| 1118 EXPECT_EQ(1U, completion_count_); | 1125 EXPECT_EQ(1U, completion_count_); |
| 1119 EXPECT_EQ(2, client_socket_factory_.allocation_count()); | 1126 EXPECT_EQ(2, client_socket_factory_.allocation_count()); |
| 1120 } | 1127 } |
| 1121 | 1128 |
| 1122 // Regression test for http://crbug.com/17985. | 1129 // Regression test for http://crbug.com/17985. |
| 1123 TEST_F(ClientSocketPoolBaseTest, GroupWithPendingRequestsIsNotEmpty) { | 1130 TEST_F(ClientSocketPoolBaseTest, GroupWithPendingRequestsIsNotEmpty) { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1256 | 1263 |
| 1257 // When requests and ConnectJobs are not coupled, the request will get serviced | 1264 // When requests and ConnectJobs are not coupled, the request will get serviced |
| 1258 // by whatever comes first. | 1265 // by whatever comes first. |
| 1259 TEST_F(ClientSocketPoolBaseTest, ReleaseSockets) { | 1266 TEST_F(ClientSocketPoolBaseTest, ReleaseSockets) { |
| 1260 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1267 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1261 | 1268 |
| 1262 // Start job 1 (async OK) | 1269 // Start job 1 (async OK) |
| 1263 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 1270 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 1264 | 1271 |
| 1265 TestSocketRequest req1(&request_order_, &completion_count_); | 1272 TestSocketRequest req1(&request_order_, &completion_count_); |
| 1266 int rv = InitHandle(req1.handle(), "a", kDefaultPriority, &req1, pool_, NULL); | 1273 int rv = InitHandle(req1.handle(), "a", kDefaultPriority, &req1, pool_, |
| 1274 BoundNetLog()); |
| 1267 EXPECT_EQ(ERR_IO_PENDING, rv); | 1275 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1268 EXPECT_EQ(OK, req1.WaitForResult()); | 1276 EXPECT_EQ(OK, req1.WaitForResult()); |
| 1269 | 1277 |
| 1270 // Job 1 finished OK. Start job 2 (also async OK). Request 3 is pending | 1278 // Job 1 finished OK. Start job 2 (also async OK). Request 3 is pending |
| 1271 // without a job. | 1279 // without a job. |
| 1272 connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); | 1280 connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
| 1273 | 1281 |
| 1274 TestSocketRequest req2(&request_order_, &completion_count_); | 1282 TestSocketRequest req2(&request_order_, &completion_count_); |
| 1275 rv = InitHandle(req2.handle(), "a", kDefaultPriority, &req2, pool_, NULL); | 1283 rv = InitHandle(req2.handle(), "a", kDefaultPriority, &req2, pool_, |
| 1284 BoundNetLog()); |
| 1276 EXPECT_EQ(ERR_IO_PENDING, rv); | 1285 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1277 TestSocketRequest req3(&request_order_, &completion_count_); | 1286 TestSocketRequest req3(&request_order_, &completion_count_); |
| 1278 rv = InitHandle(req3.handle(), "a", kDefaultPriority, &req3, pool_, NULL); | 1287 rv = InitHandle(req3.handle(), "a", kDefaultPriority, &req3, pool_, |
| 1288 BoundNetLog()); |
| 1279 EXPECT_EQ(ERR_IO_PENDING, rv); | 1289 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1280 | 1290 |
| 1281 // Both Requests 2 and 3 are pending. We release socket 1 which should | 1291 // Both Requests 2 and 3 are pending. We release socket 1 which should |
| 1282 // service request 2. Request 3 should still be waiting. | 1292 // service request 2. Request 3 should still be waiting. |
| 1283 req1.handle()->Reset(); | 1293 req1.handle()->Reset(); |
| 1284 MessageLoop::current()->RunAllPending(); // Run the DoReleaseSocket() | 1294 MessageLoop::current()->RunAllPending(); // Run the DoReleaseSocket() |
| 1285 ASSERT_TRUE(req2.handle()->socket()); | 1295 ASSERT_TRUE(req2.handle()->socket()); |
| 1286 EXPECT_EQ(OK, req2.WaitForResult()); | 1296 EXPECT_EQ(OK, req2.WaitForResult()); |
| 1287 EXPECT_FALSE(req3.handle()->socket()); | 1297 EXPECT_FALSE(req3.handle()->socket()); |
| 1288 | 1298 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1299 } | 1309 } |
| 1300 | 1310 |
| 1301 // The requests are not coupled to the jobs. So, the requests should finish in | 1311 // The requests are not coupled to the jobs. So, the requests should finish in |
| 1302 // their priority / insertion order. | 1312 // their priority / insertion order. |
| 1303 TEST_F(ClientSocketPoolBaseTest, PendingJobCompletionOrder) { | 1313 TEST_F(ClientSocketPoolBaseTest, PendingJobCompletionOrder) { |
| 1304 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1314 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1305 // First two jobs are async. | 1315 // First two jobs are async. |
| 1306 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); | 1316 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); |
| 1307 | 1317 |
| 1308 TestSocketRequest req1(&request_order_, &completion_count_); | 1318 TestSocketRequest req1(&request_order_, &completion_count_); |
| 1309 int rv = InitHandle(req1.handle(), "a", kDefaultPriority, &req1, pool_, NULL); | 1319 int rv = InitHandle(req1.handle(), "a", kDefaultPriority, &req1, pool_, |
| 1320 BoundNetLog()); |
| 1310 EXPECT_EQ(ERR_IO_PENDING, rv); | 1321 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1311 | 1322 |
| 1312 TestSocketRequest req2(&request_order_, &completion_count_); | 1323 TestSocketRequest req2(&request_order_, &completion_count_); |
| 1313 rv = InitHandle(req2.handle(), "a", kDefaultPriority, &req2, pool_, NULL); | 1324 rv = InitHandle(req2.handle(), "a", kDefaultPriority, &req2, pool_, |
| 1325 BoundNetLog()); |
| 1314 EXPECT_EQ(ERR_IO_PENDING, rv); | 1326 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1315 | 1327 |
| 1316 // The pending job is sync. | 1328 // The pending job is sync. |
| 1317 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); | 1329 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 1318 | 1330 |
| 1319 TestSocketRequest req3(&request_order_, &completion_count_); | 1331 TestSocketRequest req3(&request_order_, &completion_count_); |
| 1320 rv = InitHandle(req3.handle(), "a", kDefaultPriority, &req3, pool_, NULL); | 1332 rv = InitHandle(req3.handle(), "a", kDefaultPriority, &req3, pool_, |
| 1333 BoundNetLog()); |
| 1321 EXPECT_EQ(ERR_IO_PENDING, rv); | 1334 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1322 | 1335 |
| 1323 EXPECT_EQ(ERR_CONNECTION_FAILED, req1.WaitForResult()); | 1336 EXPECT_EQ(ERR_CONNECTION_FAILED, req1.WaitForResult()); |
| 1324 EXPECT_EQ(OK, req2.WaitForResult()); | 1337 EXPECT_EQ(OK, req2.WaitForResult()); |
| 1325 EXPECT_EQ(ERR_CONNECTION_FAILED, req3.WaitForResult()); | 1338 EXPECT_EQ(ERR_CONNECTION_FAILED, req3.WaitForResult()); |
| 1326 | 1339 |
| 1327 ASSERT_EQ(3U, request_order_.size()); | 1340 ASSERT_EQ(3U, request_order_.size()); |
| 1328 EXPECT_EQ(&req1, request_order_[0]); | 1341 EXPECT_EQ(&req1, request_order_[0]); |
| 1329 EXPECT_EQ(&req2, request_order_[1]); | 1342 EXPECT_EQ(&req2, request_order_[1]); |
| 1330 EXPECT_EQ(&req3, request_order_[2]); | 1343 EXPECT_EQ(&req3, request_order_[2]); |
| 1331 } | 1344 } |
| 1332 | 1345 |
| 1333 TEST_F(ClientSocketPoolBaseTest, DISABLED_LoadState) { | 1346 TEST_F(ClientSocketPoolBaseTest, DISABLED_LoadState) { |
| 1334 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1347 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1335 connect_job_factory_->set_job_type( | 1348 connect_job_factory_->set_job_type( |
| 1336 TestConnectJob::kMockAdvancingLoadStateJob); | 1349 TestConnectJob::kMockAdvancingLoadStateJob); |
| 1337 | 1350 |
| 1338 TestSocketRequest req1(&request_order_, &completion_count_); | 1351 TestSocketRequest req1(&request_order_, &completion_count_); |
| 1339 int rv = InitHandle(req1.handle(), "a", kDefaultPriority, &req1, pool_, NULL); | 1352 int rv = InitHandle(req1.handle(), "a", kDefaultPriority, &req1, pool_, |
| 1353 BoundNetLog()); |
| 1340 EXPECT_EQ(ERR_IO_PENDING, rv); | 1354 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1341 EXPECT_EQ(LOAD_STATE_IDLE, req1.handle()->GetLoadState()); | 1355 EXPECT_EQ(LOAD_STATE_IDLE, req1.handle()->GetLoadState()); |
| 1342 | 1356 |
| 1343 MessageLoop::current()->RunAllPending(); | 1357 MessageLoop::current()->RunAllPending(); |
| 1344 | 1358 |
| 1345 TestSocketRequest req2(&request_order_, &completion_count_); | 1359 TestSocketRequest req2(&request_order_, &completion_count_); |
| 1346 rv = InitHandle(req2.handle(), "a", kDefaultPriority, &req2, pool_, NULL); | 1360 rv = InitHandle(req2.handle(), "a", kDefaultPriority, &req2, pool_, |
| 1361 BoundNetLog()); |
| 1347 EXPECT_EQ(ERR_IO_PENDING, rv); | 1362 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1348 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req1.handle()->GetLoadState()); | 1363 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req1.handle()->GetLoadState()); |
| 1349 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req2.handle()->GetLoadState()); | 1364 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req2.handle()->GetLoadState()); |
| 1350 } | 1365 } |
| 1351 | 1366 |
| 1352 TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSockets) { | 1367 TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSockets) { |
| 1353 CreatePoolWithIdleTimeouts( | 1368 CreatePoolWithIdleTimeouts( |
| 1354 kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, | 1369 kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, |
| 1355 base::TimeDelta(), // Time out unused sockets immediately. | 1370 base::TimeDelta(), // Time out unused sockets immediately. |
| 1356 base::TimeDelta::FromDays(1)); // Don't time out used sockets. | 1371 base::TimeDelta::FromDays(1)); // Don't time out used sockets. |
| 1357 | 1372 |
| 1358 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 1373 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 1359 | 1374 |
| 1360 // Startup two mock pending connect jobs, which will sit in the MessageLoop. | 1375 // Startup two mock pending connect jobs, which will sit in the MessageLoop. |
| 1361 | 1376 |
| 1362 TestSocketRequest req(&request_order_, &completion_count_); | 1377 TestSocketRequest req(&request_order_, &completion_count_); |
| 1363 int rv = InitHandle(req.handle(), "a", LOWEST, &req, pool_, NULL); | 1378 int rv = InitHandle(req.handle(), "a", LOWEST, &req, pool_, BoundNetLog()); |
| 1364 EXPECT_EQ(ERR_IO_PENDING, rv); | 1379 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1365 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle())); | 1380 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle())); |
| 1366 | 1381 |
| 1367 TestSocketRequest req2(&request_order_, &completion_count_); | 1382 TestSocketRequest req2(&request_order_, &completion_count_); |
| 1368 rv = InitHandle(req2.handle(), "a", LOWEST, &req2, pool_, NULL); | 1383 rv = InitHandle(req2.handle(), "a", LOWEST, &req2, pool_, BoundNetLog()); |
| 1369 EXPECT_EQ(ERR_IO_PENDING, rv); | 1384 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1370 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req2.handle())); | 1385 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req2.handle())); |
| 1371 | 1386 |
| 1372 // Cancel one of the requests. Wait for the other, which will get the first | 1387 // Cancel one of the requests. Wait for the other, which will get the first |
| 1373 // job. Release the socket. Run the loop again to make sure the second | 1388 // job. Release the socket. Run the loop again to make sure the second |
| 1374 // socket is sitting idle and the first one is released (since ReleaseSocket() | 1389 // socket is sitting idle and the first one is released (since ReleaseSocket() |
| 1375 // just posts a DoReleaseSocket() task). | 1390 // just posts a DoReleaseSocket() task). |
| 1376 | 1391 |
| 1377 req.handle()->Reset(); | 1392 req.handle()->Reset(); |
| 1378 EXPECT_EQ(OK, req2.WaitForResult()); | 1393 EXPECT_EQ(OK, req2.WaitForResult()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1405 CreatePoolWithIdleTimeouts( | 1420 CreatePoolWithIdleTimeouts( |
| 1406 kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, | 1421 kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, |
| 1407 base::TimeDelta(), // Time out unused sockets immediately. | 1422 base::TimeDelta(), // Time out unused sockets immediately. |
| 1408 base::TimeDelta::FromDays(1)); // Don't time out used sockets. | 1423 base::TimeDelta::FromDays(1)); // Don't time out used sockets. |
| 1409 | 1424 |
| 1410 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); | 1425 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 1411 | 1426 |
| 1412 // Startup 4 connect jobs. Two of them will be pending. | 1427 // Startup 4 connect jobs. Two of them will be pending. |
| 1413 | 1428 |
| 1414 TestSocketRequest req(&request_order_, &completion_count_); | 1429 TestSocketRequest req(&request_order_, &completion_count_); |
| 1415 int rv = InitHandle(req.handle(), "a", LOWEST, &req, pool_, NULL); | 1430 int rv = InitHandle(req.handle(), "a", LOWEST, &req, pool_, BoundNetLog()); |
| 1416 EXPECT_EQ(OK, rv); | 1431 EXPECT_EQ(OK, rv); |
| 1417 | 1432 |
| 1418 TestSocketRequest req2(&request_order_, &completion_count_); | 1433 TestSocketRequest req2(&request_order_, &completion_count_); |
| 1419 rv = InitHandle(req2.handle(), "a", LOWEST, &req2, pool_, NULL); | 1434 rv = InitHandle(req2.handle(), "a", LOWEST, &req2, pool_, BoundNetLog()); |
| 1420 EXPECT_EQ(OK, rv); | 1435 EXPECT_EQ(OK, rv); |
| 1421 | 1436 |
| 1422 TestSocketRequest req3(&request_order_, &completion_count_); | 1437 TestSocketRequest req3(&request_order_, &completion_count_); |
| 1423 rv = InitHandle(req3.handle(), "a", LOWEST, &req3, pool_, NULL); | 1438 rv = InitHandle(req3.handle(), "a", LOWEST, &req3, pool_, BoundNetLog()); |
| 1424 EXPECT_EQ(ERR_IO_PENDING, rv); | 1439 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1425 | 1440 |
| 1426 TestSocketRequest req4(&request_order_, &completion_count_); | 1441 TestSocketRequest req4(&request_order_, &completion_count_); |
| 1427 rv = InitHandle(req4.handle(), "a", LOWEST, &req4, pool_, NULL); | 1442 rv = InitHandle(req4.handle(), "a", LOWEST, &req4, pool_, BoundNetLog()); |
| 1428 EXPECT_EQ(ERR_IO_PENDING, rv); | 1443 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1429 | 1444 |
| 1430 // Release two disconnected sockets. | 1445 // Release two disconnected sockets. |
| 1431 | 1446 |
| 1432 req.handle()->socket()->Disconnect(); | 1447 req.handle()->socket()->Disconnect(); |
| 1433 req.handle()->Reset(); | 1448 req.handle()->Reset(); |
| 1434 req2.handle()->socket()->Disconnect(); | 1449 req2.handle()->socket()->Disconnect(); |
| 1435 req2.handle()->Reset(); | 1450 req2.handle()->Reset(); |
| 1436 | 1451 |
| 1437 EXPECT_EQ(OK, req3.WaitForResult()); | 1452 EXPECT_EQ(OK, req3.WaitForResult()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1480 ClientSocketHandle* handle() { return &handle_; } | 1495 ClientSocketHandle* handle() { return &handle_; } |
| 1481 | 1496 |
| 1482 int WaitForResult() { | 1497 int WaitForResult() { |
| 1483 return callback_.WaitForResult(); | 1498 return callback_.WaitForResult(); |
| 1484 } | 1499 } |
| 1485 | 1500 |
| 1486 virtual void RunWithParams(const Tuple1<int>& params) { | 1501 virtual void RunWithParams(const Tuple1<int>& params) { |
| 1487 callback_.RunWithParams(params); | 1502 callback_.RunWithParams(params); |
| 1488 handle_.Reset(); | 1503 handle_.Reset(); |
| 1489 EXPECT_EQ(ERR_IO_PENDING, InitHandle(&handle2_, "a", kDefaultPriority, | 1504 EXPECT_EQ(ERR_IO_PENDING, InitHandle(&handle2_, "a", kDefaultPriority, |
| 1490 &callback2_, pool_, NULL)); | 1505 &callback2_, pool_, BoundNetLog())); |
| 1491 } | 1506 } |
| 1492 | 1507 |
| 1493 private: | 1508 private: |
| 1494 TestClientSocketPool* const pool_; | 1509 TestClientSocketPool* const pool_; |
| 1495 ClientSocketHandle handle_; | 1510 ClientSocketHandle handle_; |
| 1496 ClientSocketHandle handle2_; | 1511 ClientSocketHandle handle2_; |
| 1497 TestCompletionCallback callback_; | 1512 TestCompletionCallback callback_; |
| 1498 TestCompletionCallback callback2_; | 1513 TestCompletionCallback callback2_; |
| 1499 }; | 1514 }; |
| 1500 | 1515 |
| 1501 // This test covers the case where, within the same DoReleaseSocket() callback, | 1516 // This test covers the case where, within the same DoReleaseSocket() callback, |
| 1502 // we release the just acquired socket and start up a new request. See bug | 1517 // we release the just acquired socket and start up a new request. See bug |
| 1503 // 36871 for details. | 1518 // 36871 for details. |
| 1504 TEST_F(ClientSocketPoolBaseTest, ReleasedSocketReleasesToo) { | 1519 TEST_F(ClientSocketPoolBaseTest, ReleasedSocketReleasesToo) { |
| 1505 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1520 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1506 | 1521 |
| 1507 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); | 1522 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
| 1508 | 1523 |
| 1509 // Complete one request and release the socket. | 1524 // Complete one request and release the socket. |
| 1510 ClientSocketHandle handle; | 1525 ClientSocketHandle handle; |
| 1511 TestCompletionCallback callback; | 1526 TestCompletionCallback callback; |
| 1512 EXPECT_EQ(OK, InitHandle(&handle, "a", kDefaultPriority, &callback, pool_, | 1527 EXPECT_EQ(OK, InitHandle(&handle, "a", kDefaultPriority, &callback, pool_, |
| 1513 NULL)); | 1528 BoundNetLog())); |
| 1514 handle.Reset(); | 1529 handle.Reset(); |
| 1515 | 1530 |
| 1516 // Before the DoReleaseSocket() task has run, start up a | 1531 // Before the DoReleaseSocket() task has run, start up a |
| 1517 // TestReleasingSocketRequest. This one will be ERR_IO_PENDING since | 1532 // TestReleasingSocketRequest. This one will be ERR_IO_PENDING since |
| 1518 // num_releasing_sockets > 0 and there was no idle socket to use yet. | 1533 // num_releasing_sockets > 0 and there was no idle socket to use yet. |
| 1519 TestReleasingSocketRequest request(pool_.get()); | 1534 TestReleasingSocketRequest request(pool_.get()); |
| 1520 EXPECT_EQ(ERR_IO_PENDING, InitHandle(request.handle(), "a", kDefaultPriority, | 1535 EXPECT_EQ(ERR_IO_PENDING, InitHandle(request.handle(), "a", kDefaultPriority, |
| 1521 &request, pool_, NULL)); | 1536 &request, pool_, BoundNetLog())); |
| 1522 | 1537 |
| 1523 EXPECT_EQ(OK, request.WaitForResult()); | 1538 EXPECT_EQ(OK, request.WaitForResult()); |
| 1524 } | 1539 } |
| 1525 | 1540 |
| 1526 } // namespace | 1541 } // namespace |
| 1527 | 1542 |
| 1528 } // namespace net | 1543 } // namespace net |
| OLD | NEW |