Fix flaky JsepTransportControllerTests.

In a handful of places we wait for the old IceConnectionState to reach some value and then we assume that the new connection states have also been updated. However those are updated in response to different events that might not have fired yet, so sometimes these tests will fail.

This change makes us wait explicitly for those states to update.

Bug: webrtc:9983
Change-Id: I5cb6652ee29c0b86c0834174442140a3863e08e4
Reviewed-on: https://webrtc-review.googlesource.com/c/110441
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25579}
diff --git a/pc/jseptransportcontroller_unittest.cc b/pc/jseptransportcontroller_unittest.cc
index 1ab5d29..cb2023f 100644
--- a/pc/jseptransportcontroller_unittest.cc
+++ b/pc/jseptransportcontroller_unittest.cc
@@ -722,11 +722,11 @@
   fake_ice->SetConnectionCount(0);
   EXPECT_EQ_WAIT(cricket::kIceConnectionFailed, connection_state_, kTimeout);
   EXPECT_EQ(1, connection_state_signal_count_);
-  EXPECT_EQ(PeerConnectionInterface::kIceConnectionFailed,
-            ice_connection_state_);
+  EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionFailed,
+                 ice_connection_state_, kTimeout);
   EXPECT_EQ(1, ice_connection_state_signal_count_);
-  EXPECT_EQ(PeerConnectionInterface::PeerConnectionState::kFailed,
-            combined_connection_state_);
+  EXPECT_EQ_WAIT(PeerConnectionInterface::PeerConnectionState::kFailed,
+                 combined_connection_state_, kTimeout);
   EXPECT_EQ(1, combined_connection_state_signal_count_);
 }
 
@@ -756,11 +756,11 @@
 
   EXPECT_EQ_WAIT(cricket::kIceConnectionFailed, connection_state_, kTimeout);
   EXPECT_EQ(1, connection_state_signal_count_);
-  EXPECT_EQ(PeerConnectionInterface::kIceConnectionFailed,
-            ice_connection_state_);
+  EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionFailed,
+                 ice_connection_state_, kTimeout);
   EXPECT_EQ(1, ice_connection_state_signal_count_);
-  EXPECT_EQ(PeerConnectionInterface::PeerConnectionState::kFailed,
-            combined_connection_state_);
+  EXPECT_EQ_WAIT(PeerConnectionInterface::PeerConnectionState::kFailed,
+                 combined_connection_state_, kTimeout);
   EXPECT_EQ(1, combined_connection_state_signal_count_);
 
   fake_audio_dtls->SetDtlsState(cricket::DTLS_TRANSPORT_CONNECTED);
@@ -771,11 +771,11 @@
   fake_video_dtls->SetWritable(true);
   EXPECT_EQ_WAIT(cricket::kIceConnectionConnected, connection_state_, kTimeout);
   EXPECT_EQ(2, connection_state_signal_count_);
-  EXPECT_EQ(PeerConnectionInterface::kIceConnectionConnected,
-            ice_connection_state_);
+  EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionConnected,
+                 ice_connection_state_, kTimeout);
   EXPECT_EQ(2, ice_connection_state_signal_count_);
-  EXPECT_EQ(PeerConnectionInterface::PeerConnectionState::kConnected,
-            combined_connection_state_);
+  EXPECT_EQ_WAIT(PeerConnectionInterface::PeerConnectionState::kConnected,
+                 combined_connection_state_, kTimeout);
   EXPECT_EQ(2, combined_connection_state_signal_count_);
 }
 
@@ -891,11 +891,11 @@
 
   EXPECT_EQ_WAIT(cricket::kIceConnectionFailed, connection_state_, kTimeout);
   EXPECT_EQ(1, connection_state_signal_count_);
-  EXPECT_EQ(PeerConnectionInterface::kIceConnectionFailed,
-            ice_connection_state_);
+  EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionFailed,
+                 ice_connection_state_, kTimeout);
   EXPECT_EQ(1, ice_connection_state_signal_count_);
-  EXPECT_EQ(PeerConnectionInterface::PeerConnectionState::kFailed,
-            combined_connection_state_);
+  EXPECT_EQ_WAIT(PeerConnectionInterface::PeerConnectionState::kFailed,
+                 combined_connection_state_, kTimeout);
   EXPECT_EQ(1, combined_connection_state_signal_count_);
 
   fake_audio_dtls->SetDtlsState(cricket::DTLS_TRANSPORT_CONNECTED);
@@ -906,11 +906,11 @@
   fake_video_dtls->SetWritable(true);
   EXPECT_EQ_WAIT(cricket::kIceConnectionCompleted, connection_state_, kTimeout);
   EXPECT_EQ(2, connection_state_signal_count_);
-  EXPECT_EQ(PeerConnectionInterface::kIceConnectionCompleted,
-            ice_connection_state_);
+  EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
+                 ice_connection_state_, kTimeout);
   EXPECT_EQ(2, ice_connection_state_signal_count_);
-  EXPECT_EQ(PeerConnectionInterface::PeerConnectionState::kConnected,
-            combined_connection_state_);
+  EXPECT_EQ_WAIT(PeerConnectionInterface::PeerConnectionState::kConnected,
+                 combined_connection_state_, kTimeout);
   EXPECT_EQ(2, combined_connection_state_signal_count_);
 }