Fix thread usage in PC level tests for getting to the IceConnected state

Bug: webrtc:11743
Change-Id: I18a6318c35b350b3d729bbd5ac1d25f035e6ad9d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178809
Reviewed-by: Tommi <tommi@webrtc.org>
Reviewed-by: Andrey Logvin <landrey@webrtc.org>
Commit-Queue: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31658}
diff --git a/api/test/time_controller.h b/api/test/time_controller.h
index 419bd20..bd3192dd 100644
--- a/api/test/time_controller.h
+++ b/api/test/time_controller.h
@@ -60,6 +60,8 @@
 
   // Waits until condition() == true, polling condition() in small time
   // intervals.
+  // Returns true if condition() was evaluated to true before |max_duration|
+  // elapsed and false otherwise.
   bool Wait(const std::function<bool()>& condition,
             TimeDelta max_duration = TimeDelta::Seconds(5));
 };
diff --git a/test/pc/e2e/peer_connection_quality_test.cc b/test/pc/e2e/peer_connection_quality_test.cc
index 60eaa1e..2027b3b 100644
--- a/test/pc/e2e/peer_connection_quality_test.cc
+++ b/test/pc/e2e/peer_connection_quality_test.cc
@@ -578,15 +578,18 @@
 void PeerConnectionE2EQualityTest::WaitUntilPeersAreConnected(
     rtc::Thread* signaling_thread) {
   // This means that ICE and DTLS are connected.
-  time_controller_.Wait(
+  alice_connected_ = time_controller_.Wait(
       [&]() {
-        return signaling_thread->Invoke<bool>(RTC_FROM_HERE, [&]() {
-          return alice_->IsIceConnected() && bob_->IsIceConnected();
-        });
+        return signaling_thread->Invoke<bool>(
+            RTC_FROM_HERE, [&]() { return alice_->IsIceConnected(); });
       },
-      2 * kDefaultTimeout);
-  alice_connected_ = alice_->IsIceConnected();
-  bob_connected_ = bob_->IsIceConnected();
+      kDefaultTimeout);
+  bob_connected_ = time_controller_.Wait(
+      [&]() {
+        return signaling_thread->Invoke<bool>(
+            RTC_FROM_HERE, [&]() { return bob_->IsIceConnected(); });
+      },
+      kDefaultTimeout);
 }
 
 void PeerConnectionE2EQualityTest::ExchangeOfferAnswer(