diff --git a/api/test/time_controller.h b/api/test/time_controller.h index 4723716313..616622b942 100644 --- a/api/test/time_controller.h +++ b/api/test/time_controller.h @@ -39,7 +39,7 @@ class TimeController { const char* thread_name) = 0; // Allow task queues and process threads created by this instance to execute // for the given |duration|. - virtual void Sleep(TimeDelta duration) = 0; + virtual void AdvanceTime(TimeDelta duration) = 0; // Execute closure in an implementation defined scope where rtc::Event::Wait // might yield to execute other tasks. This allows doing blocking waits on // tasks on other task queues froma a task queue without deadlocking. diff --git a/call/rtp_video_sender_unittest.cc b/call/rtp_video_sender_unittest.cc index 8ea4124082..8190eea5f3 100644 --- a/call/rtp_video_sender_unittest.cc +++ b/call/rtp_video_sender_unittest.cc @@ -160,7 +160,7 @@ class RtpVideoSenderTestFixture { RtpVideoSender* router() { return router_.get(); } MockTransport& transport() { return transport_; } - void AdvanceTime(TimeDelta delta) { time_controller_.Sleep(delta); } + void AdvanceTime(TimeDelta delta) { time_controller_.AdvanceTime(delta); } private: NiceMock transport_; diff --git a/modules/pacing/task_queue_paced_sender_unittest.cc b/modules/pacing/task_queue_paced_sender_unittest.cc index 390523f093..0c3a092400 100644 --- a/modules/pacing/task_queue_paced_sender_unittest.cc +++ b/modules/pacing/task_queue_paced_sender_unittest.cc @@ -123,7 +123,7 @@ TEST_F(TaskQueuePacedSenderTest, PacesPackets) { // Packets should be sent over a period of close to 1s. Expect a little lower // than this since initial probing is a bit quicker. - time_controller_.Sleep(TimeDelta::seconds(1)); + time_controller_.AdvanceTime(TimeDelta::seconds(1)); EXPECT_EQ(packets_sent, kPacketsToSend); ASSERT_TRUE(end_time.IsFinite()); EXPECT_NEAR((end_time - start_time).ms(), 1000.0, 50.0); @@ -140,7 +140,7 @@ TEST_F(TaskQueuePacedSenderTest, ReschedulesProcessOnRateChange) { EXPECT_CALL(packet_router_, SendPacket).Times(kPacketsPerSecond); pacer_.EnqueuePackets( GeneratePackets(RtpPacketToSend::Type::kVideo, kPacketsPerSecond)); - time_controller_.Sleep(TimeDelta::seconds(1)); + time_controller_.AdvanceTime(TimeDelta::seconds(1)); // Insert three packets, and record send time of each of them. // After the second packet is sent, double the send rate so we can @@ -164,7 +164,7 @@ TEST_F(TaskQueuePacedSenderTest, ReschedulesProcessOnRateChange) { }); pacer_.EnqueuePackets(GeneratePackets(RtpPacketToSend::Type::kVideo, 3)); - time_controller_.Sleep(TimeDelta::ms(500)); + time_controller_.AdvanceTime(TimeDelta::ms(500)); ASSERT_TRUE(third_packet_time.IsFinite()); EXPECT_NEAR((second_packet_time - first_packet_time).ms(), 200.0, 1.0); diff --git a/test/frame_generator_capturer_unittest.cc b/test/frame_generator_capturer_unittest.cc index 9886b2abdf..7f910118ea 100644 --- a/test/frame_generator_capturer_unittest.cc +++ b/test/frame_generator_capturer_unittest.cc @@ -39,7 +39,7 @@ TEST(FrameGeneratorCapturerTest, CreateFromConfig) { capturer->Start(); EXPECT_CALL(mock_sink, OnFrame(Property(&VideoFrame::width, Eq(300)))) .Times(20); - time.Sleep(TimeDelta::seconds(1)); + time.AdvanceTime(TimeDelta::seconds(1)); } } // namespace test } // namespace webrtc diff --git a/test/network/cross_traffic_unittest.cc b/test/network/cross_traffic_unittest.cc index 94a2dffd1e..148ad09cfb 100644 --- a/test/network/cross_traffic_unittest.cc +++ b/test/network/cross_traffic_unittest.cc @@ -141,10 +141,10 @@ TEST(TcpMessageRouteTest, DeliveredOnLossyNetwork) { // If there was no loss, we would have delivered the message in ca 1 second, // with 50% it should take much longer. - time.Sleep(TimeDelta::seconds(5)); + time.AdvanceTime(TimeDelta::seconds(5)); ASSERT_EQ(deliver_count, 0); // But given enough time the messsage will be delivered, but only once. - time.Sleep(TimeDelta::seconds(60)); + time.AdvanceTime(TimeDelta::seconds(60)); EXPECT_EQ(deliver_count, 1); } diff --git a/test/network/feedback_generator.cc b/test/network/feedback_generator.cc index d9386c85f3..3ae6fb2086 100644 --- a/test/network/feedback_generator.cc +++ b/test/network/feedback_generator.cc @@ -32,7 +32,7 @@ Timestamp FeedbackGeneratorImpl::Now() { } void FeedbackGeneratorImpl::Sleep(TimeDelta duration) { - time_controller_.Sleep(duration); + time_controller_.AdvanceTime(duration); } void FeedbackGeneratorImpl::SendPacket(size_t size) { diff --git a/test/scenario/scenario.cc b/test/scenario/scenario.cc index 605d0e22cc..29a9cea104 100644 --- a/test/scenario/scenario.cc +++ b/test/scenario/scenario.cc @@ -272,7 +272,7 @@ void Scenario::At(TimeDelta offset, std::function function) { void Scenario::RunFor(TimeDelta duration) { if (start_time_.IsInfinite()) Start(); - time_controller_->Sleep(duration); + time_controller_->AdvanceTime(duration); } void Scenario::RunUntil(TimeDelta target_time_since_start) { @@ -285,11 +285,11 @@ void Scenario::RunUntil(TimeDelta target_time_since_start, if (start_time_.IsInfinite()) Start(); while (check_interval >= TimeUntilTarget(target_time_since_start)) { - time_controller_->Sleep(check_interval); + time_controller_->AdvanceTime(check_interval); if (exit_function()) return; } - time_controller_->Sleep(TimeUntilTarget(target_time_since_start)); + time_controller_->AdvanceTime(TimeUntilTarget(target_time_since_start)); } void Scenario::Start() { diff --git a/test/time_controller/external_time_controller.cc b/test/time_controller/external_time_controller.cc index 543b4e09e1..51e5641f43 100644 --- a/test/time_controller/external_time_controller.cc +++ b/test/time_controller/external_time_controller.cc @@ -178,7 +178,7 @@ std::unique_ptr ExternalTimeController::CreateProcessThread( this, impl_.CreateProcessThread(thread_name)); } -void ExternalTimeController::Sleep(TimeDelta duration) { +void ExternalTimeController::AdvanceTime(TimeDelta duration) { alarm_->Sleep(duration); } diff --git a/test/time_controller/external_time_controller.h b/test/time_controller/external_time_controller.h index c9b1287197..3ae302eff7 100644 --- a/test/time_controller/external_time_controller.h +++ b/test/time_controller/external_time_controller.h @@ -37,7 +37,7 @@ class ExternalTimeController : public TimeController, public TaskQueueFactory { TaskQueueFactory* GetTaskQueueFactory() override; std::unique_ptr CreateProcessThread( const char* thread_name) override; - void Sleep(TimeDelta duration) override; + void AdvanceTime(TimeDelta duration) override; void InvokeWithControlledYield(std::function closure) override; rtc::YieldInterface* YieldInterface() override; diff --git a/test/time_controller/external_time_controller_unittest.cc b/test/time_controller/external_time_controller_unittest.cc index 95a07d9248..b0b09cb78a 100644 --- a/test/time_controller/external_time_controller_unittest.cc +++ b/test/time_controller/external_time_controller_unittest.cc @@ -98,7 +98,7 @@ TEST(ExternalTimeControllerTest, TaskIsStoppedOnStop) { return kShortInterval; }); // Sleep long enough to go through the initial phase. - time_simulation.Sleep(kShortInterval * (kShortIntervalCount + kMargin)); + time_simulation.AdvanceTime(kShortInterval * (kShortIntervalCount + kMargin)); EXPECT_EQ(counter.load(), kShortIntervalCount); task_queue.PostTask( @@ -106,7 +106,7 @@ TEST(ExternalTimeControllerTest, TaskIsStoppedOnStop) { // Sleep long enough that the task would run at least once more if not // stopped. - time_simulation.Sleep(kLongInterval * 2); + time_simulation.AdvanceTime(kLongInterval * 2); EXPECT_EQ(counter.load(), kShortIntervalCount); } @@ -126,7 +126,7 @@ TEST(ExternalTimeControllerTest, TaskCanStopItself) { return TimeDelta::ms(2); }); }); - time_simulation.Sleep(TimeDelta::ms(10)); + time_simulation.AdvanceTime(TimeDelta::ms(10)); EXPECT_EQ(counter.load(), 1); } @@ -162,7 +162,7 @@ TEST(ExternalTimeControllerTest, TasksYieldToEachOther) { EXPECT_TRUE(event.Wait(200)); }); - time_simulation.Sleep(TimeDelta::ms(300)); + time_simulation.AdvanceTime(TimeDelta::ms(300)); } TEST(ExternalTimeControllerTest, CurrentTaskQueue) { @@ -175,7 +175,7 @@ TEST(ExternalTimeControllerTest, CurrentTaskQueue) { task_queue.PostTask([&] { EXPECT_TRUE(task_queue.IsCurrent()); }); - time_simulation.Sleep(TimeDelta::ms(10)); + time_simulation.AdvanceTime(TimeDelta::ms(10)); } } // namespace webrtc diff --git a/test/time_controller/real_time_controller.cc b/test/time_controller/real_time_controller.cc index f9948eb422..0494bc0f1f 100644 --- a/test/time_controller/real_time_controller.cc +++ b/test/time_controller/real_time_controller.cc @@ -30,7 +30,7 @@ std::unique_ptr RealTimeController::CreateProcessThread( return ProcessThread::Create(thread_name); } -void RealTimeController::Sleep(TimeDelta duration) { +void RealTimeController::AdvanceTime(TimeDelta duration) { SleepMs(duration.ms()); } diff --git a/test/time_controller/real_time_controller.h b/test/time_controller/real_time_controller.h index 20e6ff36fa..58d7682d6f 100644 --- a/test/time_controller/real_time_controller.h +++ b/test/time_controller/real_time_controller.h @@ -28,7 +28,7 @@ class RealTimeController : public TimeController { TaskQueueFactory* GetTaskQueueFactory() override; std::unique_ptr CreateProcessThread( const char* thread_name) override; - void Sleep(TimeDelta duration) override; + void AdvanceTime(TimeDelta duration) override; void InvokeWithControlledYield(std::function closure) override; rtc::YieldInterface* YieldInterface() override; diff --git a/test/time_controller/simulated_time_controller.cc b/test/time_controller/simulated_time_controller.cc index 5064501024..c2c135abc9 100644 --- a/test/time_controller/simulated_time_controller.cc +++ b/test/time_controller/simulated_time_controller.cc @@ -418,7 +418,7 @@ GlobalSimulatedTimeController::CreateProcessThread(const char* thread_name) { return impl_.CreateProcessThread(thread_name); } -void GlobalSimulatedTimeController::Sleep(TimeDelta duration) { +void GlobalSimulatedTimeController::AdvanceTime(TimeDelta duration) { rtc::ScopedYieldPolicy yield_policy(&impl_); Timestamp current_time = impl_.CurrentTime(); Timestamp target_time = current_time + duration; diff --git a/test/time_controller/simulated_time_controller.h b/test/time_controller/simulated_time_controller.h index a5802028bc..919b858981 100644 --- a/test/time_controller/simulated_time_controller.h +++ b/test/time_controller/simulated_time_controller.h @@ -78,9 +78,9 @@ class SimulatedTimeControllerImpl : public TaskQueueFactory, // TimeController implementation using completely simulated time. Task queues // and process threads created by this controller will run delayed activities -// when Sleep() is called. Overrides the global clock backing rtc::TimeMillis() -// and rtc::TimeMicros(). Note that this is not thread safe since it modifies -// global state. +// when AdvanceTime() is called. Overrides the global clock backing +// rtc::TimeMillis() and rtc::TimeMicros(). Note that this is not thread safe +// since it modifies global state. class GlobalSimulatedTimeController : public TimeController { public: explicit GlobalSimulatedTimeController(Timestamp start_time); @@ -90,7 +90,7 @@ class GlobalSimulatedTimeController : public TimeController { TaskQueueFactory* GetTaskQueueFactory() override; std::unique_ptr CreateProcessThread( const char* thread_name) override; - void Sleep(TimeDelta duration) override; + void AdvanceTime(TimeDelta duration) override; void InvokeWithControlledYield(std::function closure) override; rtc::YieldInterface* YieldInterface() override; diff --git a/test/time_controller/simulated_time_controller_unittest.cc b/test/time_controller/simulated_time_controller_unittest.cc index 5fc944358d..be640dd44e 100644 --- a/test/time_controller/simulated_time_controller_unittest.cc +++ b/test/time_controller/simulated_time_controller_unittest.cc @@ -46,7 +46,7 @@ TEST(SimulatedTimeControllerTest, TaskIsStoppedOnStop) { return kShortInterval; }); // Sleep long enough to go through the initial phase. - time_simulation.Sleep(kShortInterval * (kShortIntervalCount + kMargin)); + time_simulation.AdvanceTime(kShortInterval * (kShortIntervalCount + kMargin)); EXPECT_EQ(counter.load(), kShortIntervalCount); task_queue.PostTask( @@ -54,7 +54,7 @@ TEST(SimulatedTimeControllerTest, TaskIsStoppedOnStop) { // Sleep long enough that the task would run at least once more if not // stopped. - time_simulation.Sleep(kLongInterval * 2); + time_simulation.AdvanceTime(kLongInterval * 2); EXPECT_EQ(counter.load(), kShortIntervalCount); } @@ -73,7 +73,7 @@ TEST(SimulatedTimeControllerTest, TaskCanStopItself) { return TimeDelta::ms(2); }); }); - time_simulation.Sleep(TimeDelta::ms(10)); + time_simulation.AdvanceTime(TimeDelta::ms(10)); EXPECT_EQ(counter.load(), 1); } TEST(SimulatedTimeControllerTest, Example) { diff --git a/video/BUILD.gn b/video/BUILD.gn index 68cee87e6a..6c8565b15a 100644 --- a/video/BUILD.gn +++ b/video/BUILD.gn @@ -647,7 +647,7 @@ if (rtc_include_tests) { "../test:test_common", "../test:test_support", "../test:video_test_common", - "../test/time_controller:time_controller", + "../test/time_controller", "//testing/gtest", "//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/memory", diff --git a/video/video_receive_stream_unittest.cc b/video/video_receive_stream_unittest.cc index 2da7f122d0..b6c4200bd8 100644 --- a/video/video_receive_stream_unittest.cc +++ b/video/video_receive_stream_unittest.cc @@ -536,13 +536,13 @@ TEST_F(VideoReceiveStreamTestWithSimulatedClock, EXPECT_CALL(mock_transport_, SendRtcp).Times(1); video_receive_stream_.GenerateKeyFrame(); PassEncodedFrameAndWait(MakeFrame(VideoFrameType::kVideoFrameDelta, 0)); - time_controller_.Sleep(tick); + time_controller_.AdvanceTime(tick); PassEncodedFrameAndWait(MakeFrame(VideoFrameType::kVideoFrameDelta, 1)); testing::Mock::VerifyAndClearExpectations(&mock_transport_); // T+200ms: still no key frame received, expect key frame request sent again. EXPECT_CALL(mock_transport_, SendRtcp).Times(1); - time_controller_.Sleep(tick); + time_controller_.AdvanceTime(tick); PassEncodedFrameAndWait(MakeFrame(VideoFrameType::kVideoFrameDelta, 2)); testing::Mock::VerifyAndClearExpectations(&mock_transport_); @@ -550,7 +550,7 @@ TEST_F(VideoReceiveStreamTestWithSimulatedClock, // requests after this. EXPECT_CALL(mock_transport_, SendRtcp).Times(0); PassEncodedFrameAndWait(MakeFrame(VideoFrameType::kVideoFrameKey, 3)); - time_controller_.Sleep(2 * tick); + time_controller_.AdvanceTime(2 * tick); PassEncodedFrameAndWait(MakeFrame(VideoFrameType::kVideoFrameDelta, 4)); }