| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/tcp_client_socket_pool.h" | 5 #include "net/socket/tcp_client_socket_pool.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "net/base/mock_host_resolver.h" | 9 #include "net/base/mock_host_resolver.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 // The pending host resolution will eventually complete, and destroy the | 357 // The pending host resolution will eventually complete, and destroy the |
| 358 // ClientSocketPool which will crash if the group was not cleared properly. | 358 // ClientSocketPool which will crash if the group was not cleared properly. |
| 359 TEST_F(TCPClientSocketPoolTest, CancelRequestClearGroup) { | 359 TEST_F(TCPClientSocketPoolTest, CancelRequestClearGroup) { |
| 360 TestSocketRequest req(&request_order_, &completion_count_); | 360 TestSocketRequest req(&request_order_, &completion_count_); |
| 361 HostResolver::RequestInfo info("www.google.com", 80); | 361 HostResolver::RequestInfo info("www.google.com", 80); |
| 362 EXPECT_EQ(ERR_IO_PENDING, | 362 EXPECT_EQ(ERR_IO_PENDING, |
| 363 req.handle()->Init( | 363 req.handle()->Init( |
| 364 "a", info, kDefaultPriority, &req, pool_.get(), NULL)); | 364 "a", info, kDefaultPriority, &req, pool_.get(), NULL)); |
| 365 req.handle()->Reset(); | 365 req.handle()->Reset(); |
| 366 | 366 |
| 367 PlatformThread::Sleep(100); | |
| 368 | |
| 369 // There is a race condition here. If the worker pool doesn't post the task | 367 // There is a race condition here. If the worker pool doesn't post the task |
| 370 // before we get here, then this might not run ConnectingSocket::OnIOComplete | 368 // before we get here, then this might not run ConnectingSocket::OnIOComplete |
| 371 // and therefore leak the canceled ConnectingSocket. However, other tests | 369 // and therefore leak the canceled ConnectingSocket. However, other tests |
| 372 // after this will call MessageLoop::RunAllPending() which should prevent a | 370 // after this will call MessageLoop::RunAllPending() which should prevent a |
| 373 // leak, unless the worker thread takes longer than all of them. | 371 // leak, unless the worker thread takes longer than all of them. |
| 372 PlatformThread::Sleep(10); |
| 374 MessageLoop::current()->RunAllPending(); | 373 MessageLoop::current()->RunAllPending(); |
| 375 } | 374 } |
| 376 | 375 |
| 377 TEST_F(TCPClientSocketPoolTest, TwoRequestsCancelOne) { | 376 TEST_F(TCPClientSocketPoolTest, TwoRequestsCancelOne) { |
| 378 TestSocketRequest req(&request_order_, &completion_count_); | 377 TestSocketRequest req(&request_order_, &completion_count_); |
| 379 TestSocketRequest req2(&request_order_, &completion_count_); | 378 TestSocketRequest req2(&request_order_, &completion_count_); |
| 380 | 379 |
| 381 HostResolver::RequestInfo info("www.google.com", 80); | 380 HostResolver::RequestInfo info("www.google.com", 80); |
| 382 EXPECT_EQ(ERR_IO_PENDING, | 381 EXPECT_EQ(ERR_IO_PENDING, |
| 383 req.handle()->Init( | 382 req.handle()->Init( |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 for (int i = 0; i < kNumRequests; i++) | 576 for (int i = 0; i < kNumRequests; i++) |
| 578 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 577 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 579 | 578 |
| 580 for (int i = 0; i < kNumRequests; i++) | 579 for (int i = 0; i < kNumRequests; i++) |
| 581 EXPECT_EQ(ERR_CONNECTION_FAILED, requests_[i]->WaitForResult()); | 580 EXPECT_EQ(ERR_CONNECTION_FAILED, requests_[i]->WaitForResult()); |
| 582 } | 581 } |
| 583 | 582 |
| 584 } // namespace | 583 } // namespace |
| 585 | 584 |
| 586 } // namespace net | 585 } // namespace net |
| OLD | NEW |