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 <yvesg@google.com>
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30101}
diff --git a/rtc_base/thread_unittest.cc b/rtc_base/thread_unittest.cc
index 464f2d4..0e04fae 100644
--- a/rtc_base/thread_unittest.cc
+++ b/rtc_base/thread_unittest.cc
@@ -920,6 +920,7 @@
}
TEST(ThreadPostDelayedTaskTest, InvokesInDelayOrder) {
+ ScopedFakeClock clock;
std::unique_ptr<rtc::Thread> background_thread(rtc::Thread::Create());
background_thread->Start();
@@ -940,8 +941,9 @@
// 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 {