OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/socket_test_util.h" | 5 #include "net/socket/socket_test_util.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.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 "net/base/ssl_info.h" | 10 #include "net/base/ssl_info.h" |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 // static | 336 // static |
337 const int ClientSocketPoolTest::kRequestNotFound = -2; | 337 const int ClientSocketPoolTest::kRequestNotFound = -2; |
338 | 338 |
339 void ClientSocketPoolTest::SetUp() { | 339 void ClientSocketPoolTest::SetUp() { |
340 completion_count_ = 0; | 340 completion_count_ = 0; |
341 } | 341 } |
342 | 342 |
343 void ClientSocketPoolTest::TearDown() { | 343 void ClientSocketPoolTest::TearDown() { |
344 // The tests often call Reset() on handles at the end which may post | 344 // The tests often call Reset() on handles at the end which may post |
345 // DoReleaseSocket() tasks. | 345 // DoReleaseSocket() tasks. |
346 // Pending tasks created by client_socket_pool_base_unittest.cc are | |
347 // posted two milliseconds into the future and thus won't become | |
348 // scheduled until that time. | |
349 // We wait a few milliseconds to make sure that all such future tasks | |
350 // are ready to run, before calling RunAllPending(). This will work | |
351 // correctly even if Sleep() finishes late (and it should never finish | |
352 // early), as all we have to ensure is that actual wall-time has progressed | |
353 // past the scheduled starting time of the pending task. | |
354 PlatformThread::Sleep(10); | |
355 MessageLoop::current()->RunAllPending(); | 346 MessageLoop::current()->RunAllPending(); |
356 } | 347 } |
357 | 348 |
358 int ClientSocketPoolTest::GetOrderOfRequest(size_t index) { | 349 int ClientSocketPoolTest::GetOrderOfRequest(size_t index) { |
359 index--; | 350 index--; |
360 if (index < 0 || index >= requests_.size()) | 351 if (index < 0 || index >= requests_.size()) |
361 return kIndexOutOfBounds; | 352 return kIndexOutOfBounds; |
362 | 353 |
363 for (size_t i = 0; i < request_order_.size(); i++) | 354 for (size_t i = 0; i < request_order_.size(); i++) |
364 if (requests_[index] == request_order_[i]) | 355 if (requests_[index] == request_order_[i]) |
(...skipping 17 matching lines...) Expand all Loading... |
382 } | 373 } |
383 | 374 |
384 void ClientSocketPoolTest::ReleaseAllConnections(KeepAlive keep_alive) { | 375 void ClientSocketPoolTest::ReleaseAllConnections(KeepAlive keep_alive) { |
385 bool released_one; | 376 bool released_one; |
386 do { | 377 do { |
387 released_one = ReleaseOneConnection(keep_alive); | 378 released_one = ReleaseOneConnection(keep_alive); |
388 } while (released_one); | 379 } while (released_one); |
389 } | 380 } |
390 | 381 |
391 } // namespace net | 382 } // namespace net |
OLD | NEW |