Reduce flakiness of repeating task test.

Bug: webrtc:9883
Change-Id: I9027de52dc6e3e20bbd7b5b977116b3be9077941
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/131324
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27462}
This commit is contained in:
Sebastian Jansson
2019-04-04 16:49:05 +02:00
committed by Commit Bot
parent ae2213b38d
commit c46a999342

View File

@ -75,8 +75,8 @@ class TaskHandleStopper {
} // namespace
TEST(RepeatingTaskTest, TaskIsStoppedOnStop) {
const TimeDelta kShortInterval = TimeDelta::ms(5);
const TimeDelta kLongInterval = TimeDelta::ms(20);
const TimeDelta kShortInterval = TimeDelta::ms(50);
const TimeDelta kLongInterval = TimeDelta::ms(200);
const int kShortIntervalCount = 4;
const int kMargin = 1;
@ -125,14 +125,14 @@ TEST(RepeatingTaskTest, CompensatesForShortRunTime) {
TaskQueueForTest task_queue("TestQueue");
RepeatingTaskHandle::Start(task_queue.Get(), [&] {
++counter;
// Sleeping for the 10 ms should be compensated.
Sleep(TimeDelta::ms(10));
return TimeDelta::ms(30);
// Sleeping for the 100 ms should be compensated.
Sleep(TimeDelta::ms(100));
return TimeDelta::ms(300);
});
Sleep(TimeDelta::ms(40));
Sleep(TimeDelta::ms(400));
// We expect that the task have been called twice, once directly at Start and
// once after 30 ms has passed.
// once after 300 ms has passed.
EXPECT_EQ(counter.load(), 2);
}