From 5ed4da7222372cf59e5525bb3b59a90c0d4fa2ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Bostr=C3=B6m?= Date: Sat, 24 Dec 2022 11:20:12 +0100 Subject: [PATCH] In preparation for track deletion, fix some more tests. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The tests should say something about RTPs too, because what they say about track will soon be irrelevant. A drive-by fix is to GetStatsOfType as RTCOutboundRTPStreamStats instead of RTPStreamStats, this is because of a limitation with using T::kType for runtime type information... GetStatsOfType does not work for Ts higher up in the stats hierarchy, so it would always have returned an empty list even if RTCOutboundRTPStreamStats were present. (Room for improvement here, but that's a different issue.) Bug: webrtc:14175 Change-Id: I0235bc0b66c52081859ee621c58249a6b6e98738 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/288583 Reviewed-by: Harald Alvestrand Commit-Queue: Henrik Boström Cr-Commit-Position: refs/heads/main@{#38984} --- pc/rtc_stats_collector_unittest.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pc/rtc_stats_collector_unittest.cc b/pc/rtc_stats_collector_unittest.cc index 31ccfed839..5a6ac545ca 100644 --- a/pc/rtc_stats_collector_unittest.cc +++ b/pc/rtc_stats_collector_unittest.cc @@ -3890,10 +3890,9 @@ TEST_F(RTCStatsCollectorTest, GetStatsWithNullReceiverSelector) { EXPECT_EQ(empty_report->size(), 0u); } -// When the PC has not had SetLocalDescription done, tracks all have -// SSRC 0, meaning "unconnected". -// In this state, we report on track stats, but not RTP stats. -TEST_F(RTCStatsCollectorTest, StatsReportedOnZeroSsrc) { +// Before SetLocalDescription() senders don't have an SSRC. +// To simulate this case we create a mock sender with SSRC=0. +TEST_F(RTCStatsCollectorTest, RtpIsMissingWhileSsrcIsZero) { rtc::scoped_refptr track = CreateFakeTrack(cricket::MEDIA_TYPE_AUDIO, "audioTrack", MediaStreamTrackInterface::kLive); @@ -3904,16 +3903,15 @@ TEST_F(RTCStatsCollectorTest, StatsReportedOnZeroSsrc) { rtc::scoped_refptr report = stats_->GetStatsReport(); - std::vector track_stats = - report->GetStatsOfType(); - EXPECT_EQ(1U, track_stats.size()); - - std::vector rtp_stream_stats = - report->GetStatsOfType(); - EXPECT_EQ(0U, rtp_stream_stats.size()); + auto tracks = report->GetStatsOfType(); + EXPECT_EQ(1U, tracks.size()); + auto outbound_rtps = report->GetStatsOfType(); + EXPECT_TRUE(outbound_rtps.empty()); } -TEST_F(RTCStatsCollectorTest, DoNotCrashOnSsrcChange) { +// We may also be in a case where the SSRC has been assigned but no +// `voice_sender_info` stats exist yet. +TEST_F(RTCStatsCollectorTest, DoNotCrashIfSsrcIsKnownButInfosAreStillMissing) { rtc::scoped_refptr track = CreateFakeTrack(cricket::MEDIA_TYPE_AUDIO, "audioTrack", MediaStreamTrackInterface::kLive); @@ -3928,6 +3926,8 @@ TEST_F(RTCStatsCollectorTest, DoNotCrashOnSsrcChange) { std::vector track_stats = report->GetStatsOfType(); EXPECT_EQ(1U, track_stats.size()); + auto outbound_rtps = report->GetStatsOfType(); + EXPECT_TRUE(outbound_rtps.empty()); } // Used for test below, to test calling GetStatsReport during a callback.