Update call Rampup tests not to rely on DEPRECATED_SingleThreadedTaskQueueForTesting
Bug: webrtc:10933
Change-Id: I24ace9f9c1986b369ead0ddd81d1808edab5a6e7
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/157880
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29557}
diff --git a/call/rampup_tests.cc b/call/rampup_tests.cc
index 2741ebf..882baf6 100644
--- a/call/rampup_tests.cc
+++ b/call/rampup_tests.cc
@@ -38,7 +38,7 @@
namespace webrtc {
namespace {
-static const int64_t kPollIntervalMs = 20;
+constexpr TimeDelta kPollInterval = TimeDelta::Millis<20>();
static const int kExpectedHighVideoBitrateBps = 80000;
static const int kExpectedHighAudioBitrateBps = 30000;
static const int kLowBandwidthLimitBps = 20000;
@@ -54,17 +54,16 @@
}
} // namespace
-RampUpTester::RampUpTester(
- size_t num_video_streams,
- size_t num_audio_streams,
- size_t num_flexfec_streams,
- unsigned int start_bitrate_bps,
- int64_t min_run_time_ms,
- const std::string& extension_type,
- bool rtx,
- bool red,
- bool report_perf_stats,
- test::DEPRECATED_SingleThreadedTaskQueueForTesting* task_queue)
+RampUpTester::RampUpTester(size_t num_video_streams,
+ size_t num_audio_streams,
+ size_t num_flexfec_streams,
+ unsigned int start_bitrate_bps,
+ int64_t min_run_time_ms,
+ const std::string& extension_type,
+ bool rtx,
+ bool red,
+ bool report_perf_stats,
+ TaskQueueBase* task_queue)
: EndToEndTest(test::CallTest::kLongTimeoutMs),
clock_(Clock::GetRealTimeClock()),
num_video_streams_(num_video_streams),
@@ -94,14 +93,7 @@
RampUpTester::~RampUpTester() {
// Special case for WebRTC-QuickPerfTest/Enabled/
- SendTask(RTC_FROM_HERE, task_queue_, [this]() {
- if (pending_task_ !=
- static_cast<test::DEPRECATED_SingleThreadedTaskQueueForTesting::TaskId>(
- -1)) {
- task_queue_->CancelTask(pending_task_);
- pending_task_ = -1;
- }
- });
+ SendTask(RTC_FROM_HERE, task_queue_, [this] { pending_task_.Stop(); });
}
void RampUpTester::ModifySenderBitrateConfig(
@@ -323,15 +315,15 @@
void RampUpTester::OnCallsCreated(Call* sender_call, Call* receiver_call) {
RTC_DCHECK(sender_call);
sender_call_ = sender_call;
- pending_task_ = task_queue_->PostTask([this]() { PollStats(); });
+ pending_task_ = RepeatingTaskHandle::Start(task_queue_, [this] {
+ PollStats();
+ return kPollInterval;
+ });
}
void RampUpTester::PollStats() {
RTC_DCHECK_RUN_ON(task_queue_);
- EnsurePollTimeSet();
-
- pending_task_ = -1;
Call::Stats stats = sender_call_->GetStats();
EXPECT_GE(expected_bitrate_bps_, 0);
@@ -340,9 +332,7 @@
clock_->TimeInMilliseconds() - test_start_ms_ >= min_run_time_ms_)) {
ramp_up_finished_ms_ = clock_->TimeInMilliseconds();
observation_complete_.Set();
- } else {
- pending_task_ = task_queue_->PostDelayedTask([this]() { PollStats(); },
- GetIntervalForNextPoll());
+ pending_task_.Stop();
}
}
@@ -381,14 +371,7 @@
// Stop polling stats.
// Corner case for field_trials=WebRTC-QuickPerfTest/Enabled/
- SendTask(RTC_FROM_HERE, task_queue_, [this]() {
- if (pending_task_ !=
- static_cast<test::DEPRECATED_SingleThreadedTaskQueueForTesting::TaskId>(
- -1)) {
- task_queue_->CancelTask(pending_task_);
- pending_task_ = -1;
- }
- });
+ SendTask(RTC_FROM_HERE, task_queue_, [this] { pending_task_.Stop(); });
VideoSendStream::Stats send_stats = send_stream_->GetStats();
send_stream_ = nullptr; // To avoid dereferencing a bad pointer.
@@ -431,33 +414,16 @@
TriggerTestDone();
}
-void RampUpTester::EnsurePollTimeSet() {
- RTC_DCHECK_RUN_ON(task_queue_);
- if (!next_scheduled_poll_time_ms_)
- next_scheduled_poll_time_ms_ = rtc::TimeMillis();
-}
-
-int64_t RampUpTester::GetIntervalForNextPoll() {
- RTC_DCHECK_RUN_ON(task_queue_);
- RTC_DCHECK_NE(next_scheduled_poll_time_ms_, 0)
- << "No call to EnsurePollTimeSet()";
- auto now = rtc::TimeMillis();
- next_scheduled_poll_time_ms_ += kPollIntervalMs;
- auto interval = next_scheduled_poll_time_ms_ - now;
- return interval > 0 ? interval : 0;
-}
-
-RampUpDownUpTester::RampUpDownUpTester(
- size_t num_video_streams,
- size_t num_audio_streams,
- size_t num_flexfec_streams,
- unsigned int start_bitrate_bps,
- const std::string& extension_type,
- bool rtx,
- bool red,
- const std::vector<int>& loss_rates,
- bool report_perf_stats,
- test::DEPRECATED_SingleThreadedTaskQueueForTesting* task_queue)
+RampUpDownUpTester::RampUpDownUpTester(size_t num_video_streams,
+ size_t num_audio_streams,
+ size_t num_flexfec_streams,
+ unsigned int start_bitrate_bps,
+ const std::string& extension_type,
+ bool rtx,
+ bool red,
+ const std::vector<int>& loss_rates,
+ bool report_perf_stats,
+ TaskQueueBase* task_queue)
: RampUpTester(num_video_streams,
num_audio_streams,
num_flexfec_streams,
@@ -485,10 +451,9 @@
RampUpDownUpTester::~RampUpDownUpTester() {}
void RampUpDownUpTester::PollStats() {
- EnsurePollTimeSet();
-
- pending_task_ = -1;
- bool last_round = (test_state_ == kTestEnd);
+ if (test_state_ == kTestEnd) {
+ pending_task_.Stop();
+ }
int transmit_bitrate_bps = 0;
bool suspended = false;
@@ -506,11 +471,6 @@
}
EvolveTestState(transmit_bitrate_bps, suspended);
-
- if (!last_round) {
- pending_task_ = task_queue_->PostDelayedTask([this]() { PollStats(); },
- GetIntervalForNextPoll());
- }
}
void RampUpDownUpTester::ModifyReceiverBitrateConfig(