diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:35:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:35:49 +0000 |
commit | d8bbc7858622b6d9c278469aab701ca0b609cddf (patch) | |
tree | eff41dc61d9f714852212739e6b3738b82a2af87 /third_party/libwebrtc/test/time_controller/simulated_time_controller_unittest.cc | |
parent | Releasing progress-linux version 125.0.3-1~progress7.99u1. (diff) | |
download | firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip |
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | third_party/libwebrtc/test/time_controller/simulated_time_controller_unittest.cc | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/third_party/libwebrtc/test/time_controller/simulated_time_controller_unittest.cc b/third_party/libwebrtc/test/time_controller/simulated_time_controller_unittest.cc index f223ffe85d..c1c0ac2c0e 100644 --- a/third_party/libwebrtc/test/time_controller/simulated_time_controller_unittest.cc +++ b/third_party/libwebrtc/test/time_controller/simulated_time_controller_unittest.cc @@ -13,9 +13,9 @@ #include <atomic> #include <memory> +#include "api/task_queue/task_queue_base.h" #include "api/units/time_delta.h" #include "rtc_base/event.h" -#include "rtc_base/task_queue.h" #include "rtc_base/task_queue_for_test.h" #include "rtc_base/task_utils/repeating_task.h" #include "test/gmock.h" @@ -39,11 +39,11 @@ TEST(SimulatedTimeControllerTest, TaskIsStoppedOnStop) { const int kShortIntervalCount = 4; const int kMargin = 1; GlobalSimulatedTimeController time_simulation(kStartTime); - rtc::TaskQueue task_queue( + std::unique_ptr<TaskQueueBase, TaskQueueDeleter> task_queue = time_simulation.GetTaskQueueFactory()->CreateTaskQueue( - "TestQueue", TaskQueueFactory::Priority::NORMAL)); + "TestQueue", TaskQueueFactory::Priority::NORMAL); std::atomic_int counter(0); - auto handle = RepeatingTaskHandle::Start(task_queue.Get(), [&] { + auto handle = RepeatingTaskHandle::Start(task_queue.get(), [&] { if (++counter >= kShortIntervalCount) return kLongInterval; return kShortInterval; @@ -52,7 +52,7 @@ TEST(SimulatedTimeControllerTest, TaskIsStoppedOnStop) { time_simulation.AdvanceTime(kShortInterval * (kShortIntervalCount + kMargin)); EXPECT_EQ(counter.load(), kShortIntervalCount); - task_queue.PostTask( + task_queue->PostTask( [handle = std::move(handle)]() mutable { handle.Stop(); }); // Sleep long enough that the task would run at least once more if not @@ -64,13 +64,13 @@ TEST(SimulatedTimeControllerTest, TaskIsStoppedOnStop) { TEST(SimulatedTimeControllerTest, TaskCanStopItself) { std::atomic_int counter(0); GlobalSimulatedTimeController time_simulation(kStartTime); - rtc::TaskQueue task_queue( + std::unique_ptr<TaskQueueBase, TaskQueueDeleter> task_queue = time_simulation.GetTaskQueueFactory()->CreateTaskQueue( - "TestQueue", TaskQueueFactory::Priority::NORMAL)); + "TestQueue", TaskQueueFactory::Priority::NORMAL); RepeatingTaskHandle handle; - task_queue.PostTask([&] { - handle = RepeatingTaskHandle::Start(task_queue.Get(), [&] { + task_queue->PostTask([&] { + handle = RepeatingTaskHandle::Start(task_queue.get(), [&] { ++counter; handle.Stop(); return TimeDelta::Millis(2); @@ -86,29 +86,29 @@ TEST(SimulatedTimeControllerTest, Example) { void DoPeriodicTask() {} TimeDelta TimeUntilNextRun() { return TimeDelta::Millis(100); } void StartPeriodicTask(RepeatingTaskHandle* handle, - rtc::TaskQueue* task_queue) { - *handle = RepeatingTaskHandle::Start(task_queue->Get(), [this] { + TaskQueueBase* task_queue) { + *handle = RepeatingTaskHandle::Start(task_queue, [this] { DoPeriodicTask(); return TimeUntilNextRun(); }); } }; GlobalSimulatedTimeController time_simulation(kStartTime); - rtc::TaskQueue task_queue( + std::unique_ptr<TaskQueueBase, TaskQueueDeleter> task_queue = time_simulation.GetTaskQueueFactory()->CreateTaskQueue( - "TestQueue", TaskQueueFactory::Priority::NORMAL)); + "TestQueue", TaskQueueFactory::Priority::NORMAL); auto object = std::make_unique<ObjectOnTaskQueue>(); // Create and start the periodic task. RepeatingTaskHandle handle; - object->StartPeriodicTask(&handle, &task_queue); + object->StartPeriodicTask(&handle, task_queue.get()); // Restart the task - task_queue.PostTask( + task_queue->PostTask( [handle = std::move(handle)]() mutable { handle.Stop(); }); - object->StartPeriodicTask(&handle, &task_queue); - task_queue.PostTask( + object->StartPeriodicTask(&handle, task_queue.get()); + task_queue->PostTask( [handle = std::move(handle)]() mutable { handle.Stop(); }); - task_queue.PostTask([object = std::move(object)] {}); + task_queue->PostTask([object = std::move(object)] {}); } TEST(SimulatedTimeControllerTest, DelayTaskRunOnTime) { @@ -159,6 +159,8 @@ TEST(SimulatedTimeControllerTest, SkipsDelayedTaskForward) { })); main_thread->PostDelayedTask(fun.AsStdFunction(), shorter_duration); sim.SkipForwardBy(duration_during_which_nothing_runs); + // Run tasks that were pending during the skip. + sim.AdvanceTime(TimeDelta::Zero()); } } // namespace webrtc |