TimeController: Rename Sleep to AdvanceTime.

This change renames TimeController's Sleep method to AdvanceTime, unifying
the same name with the same semantic as for downstream projects.

Bug: webrtc:11154
Change-Id: Id79bcf0eafcd0b47a76407ba220479d84df5a736
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/161092
Commit-Queue: Markus Handell <handellm@webrtc.org>
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29989}
This commit is contained in:
Markus Handell
2019-12-03 14:37:28 +01:00
committed by Commit Bot
parent 269ac81a86
commit 486cc55a02
17 changed files with 33 additions and 33 deletions

View File

@ -39,7 +39,7 @@ class TimeController {
const char* thread_name) = 0; const char* thread_name) = 0;
// Allow task queues and process threads created by this instance to execute // Allow task queues and process threads created by this instance to execute
// for the given |duration|. // 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 // Execute closure in an implementation defined scope where rtc::Event::Wait
// might yield to execute other tasks. This allows doing blocking waits on // might yield to execute other tasks. This allows doing blocking waits on
// tasks on other task queues froma a task queue without deadlocking. // tasks on other task queues froma a task queue without deadlocking.

View File

@ -160,7 +160,7 @@ class RtpVideoSenderTestFixture {
RtpVideoSender* router() { return router_.get(); } RtpVideoSender* router() { return router_.get(); }
MockTransport& transport() { return transport_; } MockTransport& transport() { return transport_; }
void AdvanceTime(TimeDelta delta) { time_controller_.Sleep(delta); } void AdvanceTime(TimeDelta delta) { time_controller_.AdvanceTime(delta); }
private: private:
NiceMock<MockTransport> transport_; NiceMock<MockTransport> transport_;

View File

@ -123,7 +123,7 @@ TEST_F(TaskQueuePacedSenderTest, PacesPackets) {
// Packets should be sent over a period of close to 1s. Expect a little lower // Packets should be sent over a period of close to 1s. Expect a little lower
// than this since initial probing is a bit quicker. // 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); EXPECT_EQ(packets_sent, kPacketsToSend);
ASSERT_TRUE(end_time.IsFinite()); ASSERT_TRUE(end_time.IsFinite());
EXPECT_NEAR((end_time - start_time).ms<double>(), 1000.0, 50.0); EXPECT_NEAR((end_time - start_time).ms<double>(), 1000.0, 50.0);
@ -140,7 +140,7 @@ TEST_F(TaskQueuePacedSenderTest, ReschedulesProcessOnRateChange) {
EXPECT_CALL(packet_router_, SendPacket).Times(kPacketsPerSecond); EXPECT_CALL(packet_router_, SendPacket).Times(kPacketsPerSecond);
pacer_.EnqueuePackets( pacer_.EnqueuePackets(
GeneratePackets(RtpPacketToSend::Type::kVideo, kPacketsPerSecond)); 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. // Insert three packets, and record send time of each of them.
// After the second packet is sent, double the send rate so we can // 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)); 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()); ASSERT_TRUE(third_packet_time.IsFinite());
EXPECT_NEAR((second_packet_time - first_packet_time).ms<double>(), 200.0, EXPECT_NEAR((second_packet_time - first_packet_time).ms<double>(), 200.0,
1.0); 1.0);

View File

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

View File

@ -141,10 +141,10 @@ TEST(TcpMessageRouteTest, DeliveredOnLossyNetwork) {
// If there was no loss, we would have delivered the message in ca 1 second, // If there was no loss, we would have delivered the message in ca 1 second,
// with 50% it should take much longer. // with 50% it should take much longer.
time.Sleep(TimeDelta::seconds(5)); time.AdvanceTime(TimeDelta::seconds(5));
ASSERT_EQ(deliver_count, 0); ASSERT_EQ(deliver_count, 0);
// But given enough time the messsage will be delivered, but only once. // 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); EXPECT_EQ(deliver_count, 1);
} }

View File

@ -32,7 +32,7 @@ Timestamp FeedbackGeneratorImpl::Now() {
} }
void FeedbackGeneratorImpl::Sleep(TimeDelta duration) { void FeedbackGeneratorImpl::Sleep(TimeDelta duration) {
time_controller_.Sleep(duration); time_controller_.AdvanceTime(duration);
} }
void FeedbackGeneratorImpl::SendPacket(size_t size) { void FeedbackGeneratorImpl::SendPacket(size_t size) {

View File

@ -272,7 +272,7 @@ void Scenario::At(TimeDelta offset, std::function<void()> function) {
void Scenario::RunFor(TimeDelta duration) { void Scenario::RunFor(TimeDelta duration) {
if (start_time_.IsInfinite()) if (start_time_.IsInfinite())
Start(); Start();
time_controller_->Sleep(duration); time_controller_->AdvanceTime(duration);
} }
void Scenario::RunUntil(TimeDelta target_time_since_start) { void Scenario::RunUntil(TimeDelta target_time_since_start) {
@ -285,11 +285,11 @@ void Scenario::RunUntil(TimeDelta target_time_since_start,
if (start_time_.IsInfinite()) if (start_time_.IsInfinite())
Start(); Start();
while (check_interval >= TimeUntilTarget(target_time_since_start)) { while (check_interval >= TimeUntilTarget(target_time_since_start)) {
time_controller_->Sleep(check_interval); time_controller_->AdvanceTime(check_interval);
if (exit_function()) if (exit_function())
return; return;
} }
time_controller_->Sleep(TimeUntilTarget(target_time_since_start)); time_controller_->AdvanceTime(TimeUntilTarget(target_time_since_start));
} }
void Scenario::Start() { void Scenario::Start() {

View File

@ -178,7 +178,7 @@ std::unique_ptr<ProcessThread> ExternalTimeController::CreateProcessThread(
this, impl_.CreateProcessThread(thread_name)); this, impl_.CreateProcessThread(thread_name));
} }
void ExternalTimeController::Sleep(TimeDelta duration) { void ExternalTimeController::AdvanceTime(TimeDelta duration) {
alarm_->Sleep(duration); alarm_->Sleep(duration);
} }

View File

@ -37,7 +37,7 @@ class ExternalTimeController : public TimeController, public TaskQueueFactory {
TaskQueueFactory* GetTaskQueueFactory() override; TaskQueueFactory* GetTaskQueueFactory() override;
std::unique_ptr<ProcessThread> CreateProcessThread( std::unique_ptr<ProcessThread> CreateProcessThread(
const char* thread_name) override; const char* thread_name) override;
void Sleep(TimeDelta duration) override; void AdvanceTime(TimeDelta duration) override;
void InvokeWithControlledYield(std::function<void()> closure) override; void InvokeWithControlledYield(std::function<void()> closure) override;
rtc::YieldInterface* YieldInterface() override; rtc::YieldInterface* YieldInterface() override;

View File

@ -98,7 +98,7 @@ TEST(ExternalTimeControllerTest, TaskIsStoppedOnStop) {
return kShortInterval; return kShortInterval;
}); });
// Sleep long enough to go through the initial phase. // 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); EXPECT_EQ(counter.load(), kShortIntervalCount);
task_queue.PostTask( task_queue.PostTask(
@ -106,7 +106,7 @@ TEST(ExternalTimeControllerTest, TaskIsStoppedOnStop) {
// Sleep long enough that the task would run at least once more if not // Sleep long enough that the task would run at least once more if not
// stopped. // stopped.
time_simulation.Sleep(kLongInterval * 2); time_simulation.AdvanceTime(kLongInterval * 2);
EXPECT_EQ(counter.load(), kShortIntervalCount); EXPECT_EQ(counter.load(), kShortIntervalCount);
} }
@ -126,7 +126,7 @@ TEST(ExternalTimeControllerTest, TaskCanStopItself) {
return TimeDelta::ms(2); return TimeDelta::ms(2);
}); });
}); });
time_simulation.Sleep(TimeDelta::ms(10)); time_simulation.AdvanceTime(TimeDelta::ms(10));
EXPECT_EQ(counter.load(), 1); EXPECT_EQ(counter.load(), 1);
} }
@ -162,7 +162,7 @@ TEST(ExternalTimeControllerTest, TasksYieldToEachOther) {
EXPECT_TRUE(event.Wait(200)); EXPECT_TRUE(event.Wait(200));
}); });
time_simulation.Sleep(TimeDelta::ms(300)); time_simulation.AdvanceTime(TimeDelta::ms(300));
} }
TEST(ExternalTimeControllerTest, CurrentTaskQueue) { TEST(ExternalTimeControllerTest, CurrentTaskQueue) {
@ -175,7 +175,7 @@ TEST(ExternalTimeControllerTest, CurrentTaskQueue) {
task_queue.PostTask([&] { EXPECT_TRUE(task_queue.IsCurrent()); }); task_queue.PostTask([&] { EXPECT_TRUE(task_queue.IsCurrent()); });
time_simulation.Sleep(TimeDelta::ms(10)); time_simulation.AdvanceTime(TimeDelta::ms(10));
} }
} // namespace webrtc } // namespace webrtc

View File

@ -30,7 +30,7 @@ std::unique_ptr<ProcessThread> RealTimeController::CreateProcessThread(
return ProcessThread::Create(thread_name); return ProcessThread::Create(thread_name);
} }
void RealTimeController::Sleep(TimeDelta duration) { void RealTimeController::AdvanceTime(TimeDelta duration) {
SleepMs(duration.ms()); SleepMs(duration.ms());
} }

View File

@ -28,7 +28,7 @@ class RealTimeController : public TimeController {
TaskQueueFactory* GetTaskQueueFactory() override; TaskQueueFactory* GetTaskQueueFactory() override;
std::unique_ptr<ProcessThread> CreateProcessThread( std::unique_ptr<ProcessThread> CreateProcessThread(
const char* thread_name) override; const char* thread_name) override;
void Sleep(TimeDelta duration) override; void AdvanceTime(TimeDelta duration) override;
void InvokeWithControlledYield(std::function<void()> closure) override; void InvokeWithControlledYield(std::function<void()> closure) override;
rtc::YieldInterface* YieldInterface() override; rtc::YieldInterface* YieldInterface() override;

View File

@ -418,7 +418,7 @@ GlobalSimulatedTimeController::CreateProcessThread(const char* thread_name) {
return impl_.CreateProcessThread(thread_name); return impl_.CreateProcessThread(thread_name);
} }
void GlobalSimulatedTimeController::Sleep(TimeDelta duration) { void GlobalSimulatedTimeController::AdvanceTime(TimeDelta duration) {
rtc::ScopedYieldPolicy yield_policy(&impl_); rtc::ScopedYieldPolicy yield_policy(&impl_);
Timestamp current_time = impl_.CurrentTime(); Timestamp current_time = impl_.CurrentTime();
Timestamp target_time = current_time + duration; Timestamp target_time = current_time + duration;

View File

@ -78,9 +78,9 @@ class SimulatedTimeControllerImpl : public TaskQueueFactory,
// TimeController implementation using completely simulated time. Task queues // TimeController implementation using completely simulated time. Task queues
// and process threads created by this controller will run delayed activities // and process threads created by this controller will run delayed activities
// when Sleep() is called. Overrides the global clock backing rtc::TimeMillis() // when AdvanceTime() is called. Overrides the global clock backing
// and rtc::TimeMicros(). Note that this is not thread safe since it modifies // rtc::TimeMillis() and rtc::TimeMicros(). Note that this is not thread safe
// global state. // since it modifies global state.
class GlobalSimulatedTimeController : public TimeController { class GlobalSimulatedTimeController : public TimeController {
public: public:
explicit GlobalSimulatedTimeController(Timestamp start_time); explicit GlobalSimulatedTimeController(Timestamp start_time);
@ -90,7 +90,7 @@ class GlobalSimulatedTimeController : public TimeController {
TaskQueueFactory* GetTaskQueueFactory() override; TaskQueueFactory* GetTaskQueueFactory() override;
std::unique_ptr<ProcessThread> CreateProcessThread( std::unique_ptr<ProcessThread> CreateProcessThread(
const char* thread_name) override; const char* thread_name) override;
void Sleep(TimeDelta duration) override; void AdvanceTime(TimeDelta duration) override;
void InvokeWithControlledYield(std::function<void()> closure) override; void InvokeWithControlledYield(std::function<void()> closure) override;
rtc::YieldInterface* YieldInterface() override; rtc::YieldInterface* YieldInterface() override;

View File

@ -46,7 +46,7 @@ TEST(SimulatedTimeControllerTest, TaskIsStoppedOnStop) {
return kShortInterval; return kShortInterval;
}); });
// Sleep long enough to go through the initial phase. // 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); EXPECT_EQ(counter.load(), kShortIntervalCount);
task_queue.PostTask( task_queue.PostTask(
@ -54,7 +54,7 @@ TEST(SimulatedTimeControllerTest, TaskIsStoppedOnStop) {
// Sleep long enough that the task would run at least once more if not // Sleep long enough that the task would run at least once more if not
// stopped. // stopped.
time_simulation.Sleep(kLongInterval * 2); time_simulation.AdvanceTime(kLongInterval * 2);
EXPECT_EQ(counter.load(), kShortIntervalCount); EXPECT_EQ(counter.load(), kShortIntervalCount);
} }
@ -73,7 +73,7 @@ TEST(SimulatedTimeControllerTest, TaskCanStopItself) {
return TimeDelta::ms(2); return TimeDelta::ms(2);
}); });
}); });
time_simulation.Sleep(TimeDelta::ms(10)); time_simulation.AdvanceTime(TimeDelta::ms(10));
EXPECT_EQ(counter.load(), 1); EXPECT_EQ(counter.load(), 1);
} }
TEST(SimulatedTimeControllerTest, Example) { TEST(SimulatedTimeControllerTest, Example) {

View File

@ -647,7 +647,7 @@ if (rtc_include_tests) {
"../test:test_common", "../test:test_common",
"../test:test_support", "../test:test_support",
"../test:video_test_common", "../test:video_test_common",
"../test/time_controller:time_controller", "../test/time_controller",
"//testing/gtest", "//testing/gtest",
"//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/memory",

View File

@ -536,13 +536,13 @@ TEST_F(VideoReceiveStreamTestWithSimulatedClock,
EXPECT_CALL(mock_transport_, SendRtcp).Times(1); EXPECT_CALL(mock_transport_, SendRtcp).Times(1);
video_receive_stream_.GenerateKeyFrame(); video_receive_stream_.GenerateKeyFrame();
PassEncodedFrameAndWait(MakeFrame(VideoFrameType::kVideoFrameDelta, 0)); PassEncodedFrameAndWait(MakeFrame(VideoFrameType::kVideoFrameDelta, 0));
time_controller_.Sleep(tick); time_controller_.AdvanceTime(tick);
PassEncodedFrameAndWait(MakeFrame(VideoFrameType::kVideoFrameDelta, 1)); PassEncodedFrameAndWait(MakeFrame(VideoFrameType::kVideoFrameDelta, 1));
testing::Mock::VerifyAndClearExpectations(&mock_transport_); testing::Mock::VerifyAndClearExpectations(&mock_transport_);
// T+200ms: still no key frame received, expect key frame request sent again. // T+200ms: still no key frame received, expect key frame request sent again.
EXPECT_CALL(mock_transport_, SendRtcp).Times(1); EXPECT_CALL(mock_transport_, SendRtcp).Times(1);
time_controller_.Sleep(tick); time_controller_.AdvanceTime(tick);
PassEncodedFrameAndWait(MakeFrame(VideoFrameType::kVideoFrameDelta, 2)); PassEncodedFrameAndWait(MakeFrame(VideoFrameType::kVideoFrameDelta, 2));
testing::Mock::VerifyAndClearExpectations(&mock_transport_); testing::Mock::VerifyAndClearExpectations(&mock_transport_);
@ -550,7 +550,7 @@ TEST_F(VideoReceiveStreamTestWithSimulatedClock,
// requests after this. // requests after this.
EXPECT_CALL(mock_transport_, SendRtcp).Times(0); EXPECT_CALL(mock_transport_, SendRtcp).Times(0);
PassEncodedFrameAndWait(MakeFrame(VideoFrameType::kVideoFrameKey, 3)); PassEncodedFrameAndWait(MakeFrame(VideoFrameType::kVideoFrameKey, 3));
time_controller_.Sleep(2 * tick); time_controller_.AdvanceTime(2 * tick);
PassEncodedFrameAndWait(MakeFrame(VideoFrameType::kVideoFrameDelta, 4)); PassEncodedFrameAndWait(MakeFrame(VideoFrameType::kVideoFrameDelta, 4));
} }