OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 | 352 |
353 Thread worker; | 353 Thread worker; |
354 worker.Start(); | 354 worker.Start(); |
355 | 355 |
356 // Post an event that won't be executed for 10 seconds. | 356 // Post an event that won't be executed for 10 seconds. |
357 Event message_handler_dispatched(false, false); | 357 Event message_handler_dispatched(false, false); |
358 auto functor = [&message_handler_dispatched] { | 358 auto functor = [&message_handler_dispatched] { |
359 message_handler_dispatched.Set(); | 359 message_handler_dispatched.Set(); |
360 }; | 360 }; |
361 FunctorMessageHandler<void, decltype(functor)> handler(functor); | 361 FunctorMessageHandler<void, decltype(functor)> handler(functor); |
362 worker.PostDelayed(10000, &handler); | 362 worker.PostDelayed(60000, &handler); |
363 | 363 |
364 // Wait for a bit for the worker thread to be started and enter its socket | 364 // Wait for a bit for the worker thread to be started and enter its socket |
365 // select(). | 365 // select(). Otherwise this test would be trivial since the worker thread |
366 // would process the event as soon as it was started. | |
366 Thread::Current()->SleepMs(1000); | 367 Thread::Current()->SleepMs(1000); |
tommi
2016/06/02 07:59:01
A whole second seems like a lot. Can we synchroni
Taylor Brandstetter
2016/06/02 17:19:54
I picked a long time so that it's guaranteed to be
| |
367 | 368 |
368 // Advance the fake clock, expecting the worker thread to wake up | 369 // Advance the fake clock, expecting the worker thread to wake up |
369 // and dispatch the message quickly. | 370 // and dispatch the message instantly. |
370 clock.AdvanceTime(TimeDelta::FromSeconds(10u)); | 371 clock.AdvanceTime(TimeDelta::FromSeconds(60u)); |
371 message_handler_dispatched.Wait(Event::kForever); | 372 EXPECT_TRUE(message_handler_dispatched.Wait(0)); |
372 worker.Stop(); | 373 worker.Stop(); |
373 | 374 |
374 SetClock(nullptr); | 375 SetClock(nullptr); |
375 | 376 |
376 // The message should have been dispatched long before the 10 seconds fully | 377 // The message should have been dispatched long before the 60 seconds fully |
377 // elapsed. | 378 // elapsed (just a sanity check). |
378 int64_t real_end_time_ms = TimeMillis(); | 379 int64_t real_end_time_ms = TimeMillis(); |
379 EXPECT_LT(real_end_time_ms - real_start_time_ms, 2000); | 380 EXPECT_LT(real_end_time_ms - real_start_time_ms, 10000); |
380 } | 381 } |
381 | 382 |
382 } // namespace rtc | 383 } // namespace rtc |
OLD | NEW |