diff options
Diffstat (limited to '')
7 files changed, 48 insertions, 47 deletions
diff --git a/third_party/libwebrtc/test/time_controller/BUILD.gn b/third_party/libwebrtc/test/time_controller/BUILD.gn index b4b368a42a..6686528345 100644 --- a/third_party/libwebrtc/test/time_controller/BUILD.gn +++ b/third_party/libwebrtc/test/time_controller/BUILD.gn @@ -24,6 +24,7 @@ rtc_library("time_controller") { ] deps = [ + "../../api:field_trials_view", "../../api:sequence_checker", "../../api:time_controller", "../../api/task_queue", @@ -57,10 +58,10 @@ if (rtc_include_tests) { ":time_controller", "../:test_support", "../../api:time_controller", + "../../api/task_queue", "../../api/units:time_delta", "../../rtc_base:macromagic", "../../rtc_base:rtc_event", - "../../rtc_base:rtc_task_queue", "../../rtc_base:task_queue_for_test", "../../rtc_base:threading", "../../rtc_base/synchronization:mutex", diff --git a/third_party/libwebrtc/test/time_controller/external_time_controller_unittest.cc b/third_party/libwebrtc/test/time_controller/external_time_controller_unittest.cc index 13d63fe8ed..302055999a 100644 --- a/third_party/libwebrtc/test/time_controller/external_time_controller_unittest.cc +++ b/third_party/libwebrtc/test/time_controller/external_time_controller_unittest.cc @@ -14,8 +14,8 @@ #include <memory> #include <utility> +#include "api/task_queue/task_queue_base.h" #include "rtc_base/event.h" -#include "rtc_base/task_queue.h" #include "rtc_base/task_utils/repeating_task.h" #include "test/gmock.h" #include "test/gtest.h" @@ -88,11 +88,11 @@ TEST(ExternalTimeControllerTest, TaskIsStoppedOnStop) { const int kMargin = 1; FakeAlarm alarm(kStartTime); ExternalTimeController time_simulation(&alarm); - 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; @@ -101,7 +101,7 @@ TEST(ExternalTimeControllerTest, 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 @@ -114,13 +114,13 @@ TEST(ExternalTimeControllerTest, TaskCanStopItself) { std::atomic_int counter(0); FakeAlarm alarm(kStartTime); ExternalTimeController time_simulation(&alarm); - 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); @@ -134,12 +134,12 @@ TEST(ExternalTimeControllerTest, YieldForTask) { FakeAlarm alarm(kStartTime); ExternalTimeController time_simulation(&alarm); - rtc::TaskQueue task_queue( + std::unique_ptr<TaskQueueBase, TaskQueueDeleter> task_queue = time_simulation.GetTaskQueueFactory()->CreateTaskQueue( - "TestQueue", TaskQueueFactory::Priority::NORMAL)); + "TestQueue", TaskQueueFactory::Priority::NORMAL); rtc::Event event; - task_queue.PostTask([&] { event.Set(); }); + task_queue->PostTask([&] { event.Set(); }); EXPECT_TRUE(event.Wait(TimeDelta::Millis(200))); } @@ -147,16 +147,16 @@ TEST(ExternalTimeControllerTest, TasksYieldToEachOther) { FakeAlarm alarm(kStartTime); ExternalTimeController time_simulation(&alarm); - rtc::TaskQueue task_queue( + std::unique_ptr<TaskQueueBase, TaskQueueDeleter> task_queue = time_simulation.GetTaskQueueFactory()->CreateTaskQueue( - "TestQueue", TaskQueueFactory::Priority::NORMAL)); - rtc::TaskQueue other_queue( + "TestQueue", TaskQueueFactory::Priority::NORMAL); + std::unique_ptr<TaskQueueBase, TaskQueueDeleter> other_queue = time_simulation.GetTaskQueueFactory()->CreateTaskQueue( - "OtherQueue", TaskQueueFactory::Priority::NORMAL)); + "OtherQueue", TaskQueueFactory::Priority::NORMAL); - task_queue.PostTask([&] { + task_queue->PostTask([&] { rtc::Event event; - other_queue.PostTask([&] { event.Set(); }); + other_queue->PostTask([&] { event.Set(); }); EXPECT_TRUE(event.Wait(TimeDelta::Millis(200))); }); @@ -167,11 +167,11 @@ TEST(ExternalTimeControllerTest, CurrentTaskQueue) { FakeAlarm alarm(kStartTime); ExternalTimeController time_simulation(&alarm); - rtc::TaskQueue task_queue( + std::unique_ptr<TaskQueueBase, TaskQueueDeleter> task_queue = time_simulation.GetTaskQueueFactory()->CreateTaskQueue( - "TestQueue", TaskQueueFactory::Priority::NORMAL)); + "TestQueue", TaskQueueFactory::Priority::NORMAL); - task_queue.PostTask([&] { EXPECT_TRUE(task_queue.IsCurrent()); }); + task_queue->PostTask([&] { EXPECT_TRUE(task_queue->IsCurrent()); }); time_simulation.AdvanceTime(TimeDelta::Millis(10)); } diff --git a/third_party/libwebrtc/test/time_controller/real_time_controller.cc b/third_party/libwebrtc/test/time_controller/real_time_controller.cc index 7cc750d6d4..537532d20f 100644 --- a/third_party/libwebrtc/test/time_controller/real_time_controller.cc +++ b/third_party/libwebrtc/test/time_controller/real_time_controller.cc @@ -9,6 +9,7 @@ */ #include "test/time_controller/real_time_controller.h" +#include "api/field_trials_view.h" #include "api/task_queue/default_task_queue_factory.h" #include "rtc_base/null_socket_server.h" @@ -30,8 +31,8 @@ class MainThread : public rtc::Thread { CurrentThreadSetter current_setter_; }; } // namespace -RealTimeController::RealTimeController() - : task_queue_factory_(CreateDefaultTaskQueueFactory()), +RealTimeController::RealTimeController(const FieldTrialsView* field_trials) + : task_queue_factory_(CreateDefaultTaskQueueFactory(field_trials)), main_thread_(std::make_unique<MainThread>()) { main_thread_->SetName("Main", this); } diff --git a/third_party/libwebrtc/test/time_controller/real_time_controller.h b/third_party/libwebrtc/test/time_controller/real_time_controller.h index 5f02eaf85f..0085732e63 100644 --- a/third_party/libwebrtc/test/time_controller/real_time_controller.h +++ b/third_party/libwebrtc/test/time_controller/real_time_controller.h @@ -13,6 +13,7 @@ #include <functional> #include <memory> +#include "api/field_trials_view.h" #include "api/task_queue/task_queue_factory.h" #include "api/test/time_controller.h" #include "api/units/time_delta.h" @@ -21,7 +22,7 @@ namespace webrtc { class RealTimeController : public TimeController { public: - RealTimeController(); + RealTimeController(const FieldTrialsView* field_trials = nullptr); Clock* GetClock() override; TaskQueueFactory* GetTaskQueueFactory() override; diff --git a/third_party/libwebrtc/test/time_controller/simulated_time_controller.cc b/third_party/libwebrtc/test/time_controller/simulated_time_controller.cc index dbb36fdfcc..ce666c4bf5 100644 --- a/third_party/libwebrtc/test/time_controller/simulated_time_controller.cc +++ b/third_party/libwebrtc/test/time_controller/simulated_time_controller.cc @@ -218,9 +218,6 @@ void GlobalSimulatedTimeController::SkipForwardBy(TimeDelta duration) { impl_.AdvanceTime(target_time); sim_clock_.AdvanceTimeMicroseconds(duration.us()); global_clock_.AdvanceTime(duration); - - // Run tasks that were pending during the skip. - impl_.RunReadyRunners(); } void GlobalSimulatedTimeController::Register( diff --git a/third_party/libwebrtc/test/time_controller/simulated_time_controller.h b/third_party/libwebrtc/test/time_controller/simulated_time_controller.h index f3f0da9274..df7f866b14 100644 --- a/third_party/libwebrtc/test/time_controller/simulated_time_controller.h +++ b/third_party/libwebrtc/test/time_controller/simulated_time_controller.h @@ -139,7 +139,6 @@ class GlobalSimulatedTimeController : public TimeController { void AdvanceTime(TimeDelta duration) override; // Advances time by `duration`and do not run delayed tasks in the meantime. - // Runs any pending tasks at the end. // Useful for simulating contention on destination queues. void SkipForwardBy(TimeDelta duration); 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 |