From 094396fb765d3e001644bb38cb922a664301e26e Mon Sep 17 00:00:00 2001 From: Steve Anton Date: Mon, 16 Dec 2019 00:56:02 -0800 Subject: [PATCH] Use a fake clock for rtc::Thread::PostDelayedTask test The test would flake using a real clock since time may pass between calls to PostDelayedTask which would result in the tasks running out of the expected order. Bug: webrtc:11208, webrtc:11219 Change-Id: Ice5fe6ec4e9bf2ce89f00c6de7ed06b89dbe88cc Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/162100 Reviewed-by: Yves Gerey Commit-Queue: Steve Anton Cr-Commit-Position: refs/heads/master@{#30101} --- rtc_base/thread_unittest.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rtc_base/thread_unittest.cc b/rtc_base/thread_unittest.cc index 464f2d4b53..0e04fae3f8 100644 --- a/rtc_base/thread_unittest.cc +++ b/rtc_base/thread_unittest.cc @@ -920,6 +920,7 @@ TEST(ThreadPostDelayedTaskTest, InvokesAsynchronously) { } TEST(ThreadPostDelayedTaskTest, InvokesInDelayOrder) { + ScopedFakeClock clock; std::unique_ptr background_thread(rtc::Thread::Create()); background_thread->Start(); @@ -940,8 +941,9 @@ TEST(ThreadPostDelayedTaskTest, InvokesInDelayOrder) { // All tasks have been posted before the first one is unblocked. first.Set(); - // Only if the chain is invoked in posted order will the last event be set. - fourth.Wait(Event::kForever); + // Only if the chain is invoked in delay order will the last event be set. + clock.AdvanceTime(webrtc::TimeDelta::ms(11)); + EXPECT_TRUE(fourth.Wait(0)); } class ThreadFactory : public webrtc::TaskQueueFactory {