Run delay tasks on time when using GlobalSimulatedTimeController.

This change means tasks scheduled at the end time reached when making a call to GlobalSimulatedTimeController::AdvanceTime will also be executed.

In other words, with this change, if you schedule a task in X milliseconds and then call AdvanceTime(TimeDelta::ms(X)) the scheduled task will be executed.

Bug: none
Change-Id: I337e574a88b235639e82ffcacf1484daa6cf3172
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/164522
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Commit-Queue: Philip Eliasson <philipel@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30146}
This commit is contained in:
philipel 2020-01-03 14:43:10 +01:00 committed by Commit Bot
parent 3828c30b06
commit d572748885
3 changed files with 18 additions and 1 deletions

View File

@ -38,7 +38,7 @@ TEST(FrameGeneratorCapturerTest, CreateFromConfig) {
capturer->AddOrUpdateSink(&mock_sink, rtc::VideoSinkWants());
capturer->Start();
EXPECT_CALL(mock_sink, OnFrame(Property(&VideoFrame::width, Eq(300))))
.Times(20);
.Times(21);
time.AdvanceTime(TimeDelta::seconds(1));
}
} // namespace test

View File

@ -432,6 +432,9 @@ void GlobalSimulatedTimeController::AdvanceTime(TimeDelta duration) {
sim_clock_.AdvanceTimeMicroseconds(delta.us());
global_clock_.AdvanceTime(delta);
}
// After time has been simulated up until |target_time| we also need to run
// tasks meant to be executed at |target_time|.
impl_.RunReadyRunners();
}
} // namespace webrtc

View File

@ -76,6 +76,7 @@ TEST(SimulatedTimeControllerTest, TaskCanStopItself) {
time_simulation.AdvanceTime(TimeDelta::ms(10));
EXPECT_EQ(counter.load(), 1);
}
TEST(SimulatedTimeControllerTest, Example) {
class ObjectOnTaskQueue {
public:
@ -110,4 +111,17 @@ TEST(SimulatedTimeControllerTest, Example) {
};
task_queue.PostTask(Destructor{std::move(object)});
}
TEST(SimulatedTimeControllerTest, DelayTaskRunOnTime) {
GlobalSimulatedTimeController time_simulation(kStartTime);
rtc::TaskQueue task_queue(
time_simulation.GetTaskQueueFactory()->CreateTaskQueue(
"TestQueue", TaskQueueFactory::Priority::NORMAL));
bool delay_task_executed = false;
task_queue.PostDelayedTask([&] { delay_task_executed = true; }, 10);
time_simulation.AdvanceTime(TimeDelta::ms(10));
EXPECT_TRUE(delay_task_executed);
}
} // namespace webrtc