Stabilize RenegotiateManyVideoTransceiversAndWatchAudioDelay test

Bug: webrtc:42225724
Change-Id: I0bb86f0fa1eba8e2ddda54391fe99f59369779eb
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/461720
Auto-Submit: Tomas Gunnarsson <tommi@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#47336}
diff --git a/pc/peer_connection_integrationtest.cc b/pc/peer_connection_integrationtest.cc
index 579e34d..a372bb6 100644
--- a/pc/peer_connection_integrationtest.cc
+++ b/pc/peer_connection_integrationtest.cc
@@ -3808,6 +3808,8 @@
     caller()->UpdateDelayStats("caller reception", current_size);
     callee()->UpdateDelayStats("callee reception", current_size);
   }
+  EXPECT_TRUE(caller()->AudioDelayStatsPercentageChecked());
+  EXPECT_TRUE(callee()->AudioDelayStatsPercentageChecked());
 }
 
 TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
diff --git a/pc/test/integration_test_helpers.cc b/pc/test/integration_test_helpers.cc
index 3dd1fc3..127e762 100644
--- a/pc/test/integration_test_helpers.cc
+++ b/pc/test/integration_test_helpers.cc
@@ -208,7 +208,9 @@
   // TODO(https://crbug.com/webrtc/15393): Improve audio quality during
   // renegotiation so that we can reduce these thresholds, 99% is not even
   // close to the 20% deemed unacceptable above or the 0% that would be ideal.
-  if (delta_samples > 0) {
+  // Require at least 2000 samples (roughly 2x 20ms packets).
+  if (delta_samples >= 2000) {
+    audio_delay_stats_percentage_checked_ = true;
 #if !defined(NDEBUG)
     EXPECT_LT(1.0 * delta_concealed / delta_samples, 0.99)
         << "Concealed " << delta_concealed << " of " << delta_samples
diff --git a/pc/test/integration_test_helpers.h b/pc/test/integration_test_helpers.h
index be76075..518d7cf 100644
--- a/pc/test/integration_test_helpers.h
+++ b/pc/test/integration_test_helpers.h
@@ -735,6 +735,10 @@
 
   void UpdateDelayStats(std::string tag, int desc_size);
 
+  bool AudioDelayStatsPercentageChecked() const {
+    return audio_delay_stats_percentage_checked_;
+  }
+
   // Sets number of candidates expected
   void ExpectCandidates(int candidate_count) {
     candidates_expected_ = candidate_count;
@@ -1272,6 +1276,7 @@
   uint64_t audio_samples_stat_ = 0;
   uint64_t audio_concealed_stat_ = 0;
   std::string rtp_stats_id_;
+  bool audio_delay_stats_percentage_checked_ = false;
 
   std::function<void(PeerConnectionInterface::PeerConnectionState)>
       connection_change_callback_ = nullptr;