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:

committed by
Commit Bot

parent
269ac81a86
commit
486cc55a02
@ -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.
|
||||
|
@ -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<MockTransport> transport_;
|
||||
|
@ -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<double>(), 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<double>(), 200.0,
|
||||
1.0);
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -272,7 +272,7 @@ void Scenario::At(TimeDelta offset, std::function<void()> 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() {
|
||||
|
@ -178,7 +178,7 @@ std::unique_ptr<ProcessThread> ExternalTimeController::CreateProcessThread(
|
||||
this, impl_.CreateProcessThread(thread_name));
|
||||
}
|
||||
|
||||
void ExternalTimeController::Sleep(TimeDelta duration) {
|
||||
void ExternalTimeController::AdvanceTime(TimeDelta duration) {
|
||||
alarm_->Sleep(duration);
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ class ExternalTimeController : public TimeController, public TaskQueueFactory {
|
||||
TaskQueueFactory* GetTaskQueueFactory() override;
|
||||
std::unique_ptr<ProcessThread> CreateProcessThread(
|
||||
const char* thread_name) override;
|
||||
void Sleep(TimeDelta duration) override;
|
||||
void AdvanceTime(TimeDelta duration) override;
|
||||
void InvokeWithControlledYield(std::function<void()> closure) override;
|
||||
rtc::YieldInterface* YieldInterface() override;
|
||||
|
||||
|
@ -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
|
||||
|
@ -30,7 +30,7 @@ std::unique_ptr<ProcessThread> RealTimeController::CreateProcessThread(
|
||||
return ProcessThread::Create(thread_name);
|
||||
}
|
||||
|
||||
void RealTimeController::Sleep(TimeDelta duration) {
|
||||
void RealTimeController::AdvanceTime(TimeDelta duration) {
|
||||
SleepMs(duration.ms());
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ class RealTimeController : public TimeController {
|
||||
TaskQueueFactory* GetTaskQueueFactory() override;
|
||||
std::unique_ptr<ProcessThread> CreateProcessThread(
|
||||
const char* thread_name) override;
|
||||
void Sleep(TimeDelta duration) override;
|
||||
void AdvanceTime(TimeDelta duration) override;
|
||||
void InvokeWithControlledYield(std::function<void()> closure) override;
|
||||
rtc::YieldInterface* YieldInterface() override;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<ProcessThread> CreateProcessThread(
|
||||
const char* thread_name) override;
|
||||
void Sleep(TimeDelta duration) override;
|
||||
void AdvanceTime(TimeDelta duration) override;
|
||||
void InvokeWithControlledYield(std::function<void()> closure) override;
|
||||
rtc::YieldInterface* YieldInterface() override;
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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",
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user