De-flake NonSenderRttStats and make it faster to run on average.

It takes several seconds until we get an RTT measurement because that
requires RTCP packets to be received and those are not sent very often.

This CL makes the test faster on average by unblocking it as soon as
we see an RTT measurement (as opposed to always blocking for 10
seconds), this usually unblocks after around 5 seconds.

But to de-flake those rare instances where the test takes more than 10s
to run, the maximum timeout is extended to 20 seconds.

Patch Set 4: also fix use-of-uninitialized value.

Bug: webrtc:14981
Change-Id: Ieca94c90dfb52c3b17584a06660ff66c6462aa8b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/296822
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Commit-Queue: Gustaf Ullberg <gustaf@webrtc.org>
Auto-Submit: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Gustaf Ullberg <gustaf@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39531}
This commit is contained in:
Henrik Boström 2023-03-10 11:29:17 +01:00 committed by WebRTC LUCI CQ
parent 4463ff0296
commit 0c126ed47a
3 changed files with 31 additions and 4 deletions

View File

@ -198,6 +198,7 @@ if (rtc_include_tests) {
"../modules/rtp_rtcp:rtp_rtcp_format",
"../modules/utility:utility",
"../rtc_base:checks",
"../rtc_base:gunit_helpers",
"../rtc_base:macromagic",
"../rtc_base:refcount",
"../rtc_base:rtc_base_tests_utils",

View File

@ -9,6 +9,8 @@
*/
#include "audio/test/audio_end_to_end_test.h"
#include "rtc_base/gunit.h"
#include "rtc_base/task_queue_for_test.h"
#include "system_wrappers/include/sleep.h"
#include "test/gtest.h"
@ -20,9 +22,12 @@ using NonSenderRttTest = CallTest;
TEST_F(NonSenderRttTest, NonSenderRttStats) {
class NonSenderRttTest : public AudioEndToEndTest {
public:
const int kTestDurationMs = 10000;
const int kLongTimeoutMs = 20000;
const int64_t kRttMs = 30;
explicit NonSenderRttTest(TaskQueueBase* task_queue)
: task_queue_(task_queue) {}
BuiltInNetworkBehaviorConfig GetSendTransportConfig() const override {
BuiltInNetworkBehaviorConfig pipe_config;
pipe_config.queue_delay_ms = kRttMs / 2;
@ -38,7 +43,12 @@ TEST_F(NonSenderRttTest, NonSenderRttStats) {
send_config->send_codec_spec->enable_non_sender_rtt = true;
}
void PerformTest() override { SleepMs(kTestDurationMs); }
void PerformTest() override {
// Wait until we have an RTT measurement, but no longer than
// `kLongTimeoutMs`. This usually takes around 5 seconds, but in rare
// cases it can take more than 10 seconds.
EXPECT_TRUE_WAIT(HasRoundTripTimeMeasurement(), kLongTimeoutMs);
}
void OnStreamsStopped() override {
AudioReceiveStreamInterface::Stats recv_stats =
@ -49,7 +59,23 @@ TEST_F(NonSenderRttTest, NonSenderRttStats) {
EXPECT_GE(recv_stats.total_round_trip_time.ms(),
recv_stats.round_trip_time->ms());
}
} test;
protected:
bool HasRoundTripTimeMeasurement() {
bool has_rtt = false;
// GetStats() can only be called on `task_queue_`, block while we check.
SendTask(task_queue_, [this, &has_rtt]() {
if (receive_stream() &&
receive_stream()->GetStats(true).round_trip_time_measurements > 0) {
has_rtt = true;
}
});
return has_rtt;
}
private:
TaskQueueBase* task_queue_;
} test(task_queue());
RunBaseTest(&test);
}

View File

@ -99,7 +99,7 @@ class AudioReceiveStreamInterface : public MediaReceiveStreamInterface {
uint64_t sender_reports_reports_count = 0;
absl::optional<TimeDelta> round_trip_time;
TimeDelta total_round_trip_time = TimeDelta::Zero();
int round_trip_time_measurements;
int round_trip_time_measurements = 0;
};
struct Config {