pc: invalidate stats cache when firing onicecandidate

https://w3c.github.io/webrtc-stats/#guidelines-for-getstats-results-caching-throttling
"When the state of the RTCPeerConnection visibly changes as a result of an API call, a promise resolving or an event firing, subsequent new getStats() calls must return up-to-date dictionaries for the affected objects."

BUG=webrtc:14190

Change-Id: I4560be22795f30e0369d573bda0100e490efb57b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/265870
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Philipp Hancke <philipp.hancke@googlemail.com>
Cr-Commit-Position: refs/heads/main@{#37255}
This commit is contained in:
Philipp Hancke
2022-06-17 11:34:31 +02:00
committed by WebRTC LUCI CQ
parent 9f24225d43
commit 1fe14f2752
3 changed files with 38 additions and 0 deletions

View File

@ -2418,6 +2418,38 @@ TEST_P(PeerConnectionIntegrationTestWithFakeClock,
ClosePeerConnections();
}
TEST_P(PeerConnectionIntegrationTestWithFakeClock,
OnIceCandidateFlushesGetStatsCache) {
ASSERT_TRUE(CreatePeerConnectionWrappers());
ConnectFakeSignaling();
caller()->AddAudioTrack();
// Call getStats, assert there are no candidates.
rtc::scoped_refptr<const webrtc::RTCStatsReport> first_report =
caller()->NewGetStats();
ASSERT_TRUE(first_report);
auto first_candidate_stats =
first_report->GetStatsOfType<webrtc::RTCLocalIceCandidateStats>();
ASSERT_EQ(first_candidate_stats.size(), 0u);
// Start candidate gathering and wait for it to complete.
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_SIMULATED_WAIT(caller()->IceGatheringStateComplete(),
kDefaultTimeout, FakeClock());
// Call getStats again, assert there are candidates now.
rtc::scoped_refptr<const webrtc::RTCStatsReport> second_report =
caller()->NewGetStats();
ASSERT_TRUE(second_report);
auto second_candidate_stats =
second_report->GetStatsOfType<webrtc::RTCLocalIceCandidateStats>();
ASSERT_NE(second_candidate_stats.size(), 0u);
// The fake clock ensures that no time has passed so the cache must have been
// explicitly invalidated.
EXPECT_EQ(first_report->timestamp_us(), second_report->timestamp_us());
}
#endif // !defined(THREAD_SANITIZER)
// Verify that a TurnCustomizer passed in through RTCConfiguration