diff --git a/p2p/BUILD.gn b/p2p/BUILD.gn index 8ede171086..05807b388a 100644 --- a/p2p/BUILD.gn +++ b/p2p/BUILD.gn @@ -1206,6 +1206,7 @@ if (rtc_include_tests) { ":p2p_server_utils", ":p2p_test_utils", ":p2p_transport_channel", + ":p2p_transport_channel_ice_field_trials", ":packet_transport_internal", ":port", ":port_allocator", @@ -1230,6 +1231,8 @@ if (rtc_include_tests) { "../api:libjingle_peerconnection_api", "../api:mock_async_dns_resolver", "../api:packet_socket_factory", + "../api:rtc_error", + "../api:rtc_error_matchers", "../api:scoped_refptr", "../api/crypto:options", "../api/task_queue", @@ -1265,6 +1268,7 @@ if (rtc_include_tests) { "../rtc_base:socket_server", "../rtc_base:ssl", "../rtc_base:ssl_adapter", + "../rtc_base:stream", "../rtc_base:stringutils", "../rtc_base:testclient", "../rtc_base:threading", @@ -1277,6 +1281,7 @@ if (rtc_include_tests) { "../test:rtc_expect_death", "../test:scoped_key_value_config", "../test:test_support", + "../test:wait_until", "//testing/gtest", "//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/functional:any_invocable", diff --git a/p2p/base/p2p_transport_channel_unittest.cc b/p2p/base/p2p_transport_channel_unittest.cc index c23867ef92..b7fd49a0b0 100644 --- a/p2p/base/p2p_transport_channel_unittest.cc +++ b/p2p/base/p2p_transport_channel_unittest.cc @@ -33,6 +33,7 @@ #include "api/scoped_refptr.h" #include "api/task_queue/pending_task_safety_flag.h" #include "api/test/mock_async_dns_resolver.h" +#include "api/test/rtc_error_matchers.h" #include "api/transport/enums.h" #include "api/transport/stun.h" #include "api/units/time_delta.h" @@ -91,21 +92,23 @@ #include "test/gmock.h" #include "test/gtest.h" #include "test/scoped_key_value_config.h" +#include "test/wait_until.h" namespace { using rtc::SocketAddress; using ::testing::_; using ::testing::Assign; -using ::testing::Combine; using ::testing::Contains; using ::testing::DoAll; -using ::testing::InSequence; -using ::testing::InvokeWithoutArgs; +using ::testing::Eq; +using ::testing::Gt; +using ::testing::IsFalse; +using ::testing::IsTrue; using ::testing::MockFunction; +using ::testing::Ne; using ::testing::Return; using ::testing::ReturnRef; -using ::testing::SaveArg; using ::testing::SetArgPointee; using ::testing::SizeIs; using ::testing::Values; @@ -286,6 +289,7 @@ bool HasRemoteAddress(const cricket::CandidatePairInterface* pair, } // namespace namespace cricket { +using ::testing::NotNull; // This test simulates 2 P2P endpoints that want to establish connectivity // with each other over various network topologies and conditions, which can be @@ -707,8 +711,13 @@ class P2PTransportChannelTestBase : public ::testing::Test, // Create the channels and wait for them to connect. CreateChannels(); - EXPECT_TRUE_SIMULATED_WAIT(CheckConnected(ep1_ch1(), ep2_ch1()), - expected.connect_wait + kShortTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis( + expected.connect_wait + kShortTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); connect_time = rtc::TimeMillis() - connect_start; if (connect_time < expected.connect_wait) { RTC_LOG(LS_INFO) << "Connect time: " << connect_time << " ms"; @@ -726,9 +735,15 @@ class P2PTransportChannelTestBase : public ::testing::Test, // This is done only for the RFC 5245 as controlled agent will use // USE-CANDIDATE from controlling (ep1) agent. We can easily predict from // EP1 result matrix. - EXPECT_TRUE_SIMULATED_WAIT( - CheckCandidate1(expected) && CheckCandidate2(expected), - kDefaultTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return CheckCandidate1(expected) && + CheckCandidate2(expected); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Also do EXPECT_EQ on each part so that failures are more verbose. ExpectCandidate1(expected); ExpectCandidate2(expected); @@ -754,14 +769,28 @@ class P2PTransportChannelTestBase : public ::testing::Test, const char* data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; int len = static_cast(strlen(data)); // local_channel1 <==> remote_channel1 - EXPECT_EQ_SIMULATED_WAIT(len, SendData(ep1_ch1(), data, len), - kMediumTimeout, *clock); - EXPECT_TRUE_SIMULATED_WAIT(CheckDataOnChannel(ep2_ch1(), data, len), - kMediumTimeout, *clock); - EXPECT_EQ_SIMULATED_WAIT(len, SendData(ep2_ch1(), data, len), - kMediumTimeout, *clock); - EXPECT_TRUE_SIMULATED_WAIT(CheckDataOnChannel(ep1_ch1(), data, len), - kMediumTimeout, *clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return SendData(ep1_ch1(), data, len); }, Eq(len), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &*clock}), + webrtc::IsRtcOk()); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return CheckDataOnChannel(ep2_ch1(), data, len); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &*clock}), + webrtc::IsRtcOk()); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return SendData(ep2_ch1(), data, len); }, Eq(len), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &*clock}), + webrtc::IsRtcOk()); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return CheckDataOnChannel(ep1_ch1(), data, len); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &*clock}), + webrtc::IsRtcOk()); } } @@ -774,8 +803,12 @@ class P2PTransportChannelTestBase : public ::testing::Test, rtc::ScopedFakeClock clock; ep1_ch1()->SetRemoteIceParameters(kIceParams[1]); ep2_ch1()->SetRemoteIceParameters(kIceParams[0]); - EXPECT_TRUE_SIMULATED_WAIT(CheckConnected(ep1_ch1(), ep2_ch1()), - kMediumTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); const Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1()); const Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1()); @@ -790,18 +823,30 @@ class P2PTransportChannelTestBase : public ::testing::Test, ep2_ch1()->SetRemoteIceParameters(kIceParams[2]); ep2_ch1()->MaybeStartGathering(); - EXPECT_TRUE_SIMULATED_WAIT(LocalCandidate(ep1_ch1())->generation() != - old_local_candidate1->generation(), - kMediumTimeout, clock); - EXPECT_TRUE_SIMULATED_WAIT(LocalCandidate(ep2_ch1())->generation() != - old_local_candidate2->generation(), - kMediumTimeout, clock); - EXPECT_TRUE_SIMULATED_WAIT(RemoteCandidate(ep1_ch1())->generation() != - old_remote_candidate1->generation(), - kMediumTimeout, clock); - EXPECT_TRUE_SIMULATED_WAIT(RemoteCandidate(ep2_ch1())->generation() != - old_remote_candidate2->generation(), - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return LocalCandidate(ep1_ch1())->generation(); }, + Ne(old_local_candidate1->generation()), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return LocalCandidate(ep2_ch1())->generation(); }, + Ne(old_local_candidate2->generation()), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return RemoteCandidate(ep1_ch1())->generation(); }, + Ne(old_remote_candidate1->generation()), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return RemoteCandidate(ep2_ch1())->generation(); }, + Ne(old_remote_candidate2->generation()), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_EQ(1u, RemoteCandidate(ep2_ch1())->generation()); EXPECT_EQ(1u, RemoteCandidate(ep1_ch1())->generation()); } @@ -1303,10 +1348,15 @@ TEST_F(P2PTransportChannelTest, GetStats) { ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, kDefaultPortAllocatorFlags); CreateChannels(); - EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && - ep2_ch1()->receiving() && - ep2_ch1()->writable(), - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return ep1_ch1()->receiving() && ep1_ch1()->writable() && + ep2_ch1()->receiving() && ep2_ch1()->writable(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Sends and receives 10 packets. TestSendRecv(&clock); @@ -1358,10 +1408,15 @@ TEST_F(P2PTransportChannelTest, GetStatsSwitchConnection) { AddAddress(0, kAlternateAddrs[1], "rmnet0", rtc::ADAPTER_TYPE_CELLULAR); CreateChannels(continual_gathering_config, continual_gathering_config); - EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && - ep2_ch1()->receiving() && - ep2_ch1()->writable(), - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return ep1_ch1()->receiving() && ep1_ch1()->writable() && + ep2_ch1()->receiving() && ep2_ch1()->writable(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Sends and receives 10 packets. TestSendRecv(&clock); @@ -1392,8 +1447,11 @@ TEST_F(P2PTransportChannelTest, GetStatsSwitchConnection) { ep1_ch1()->RemoveConnectionForTest( const_cast(old_selected_connection)); - EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection() != nullptr, - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ep1_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Sends and receives 10 packets. TestSendRecv(&clock); @@ -1430,15 +1488,24 @@ TEST_F(P2PTransportChannelTest, IceConfig default_config; CreateChannels(continual_gathering_config, default_config); - EXPECT_TRUE_SIMULATED_WAIT(CheckConnected(ep1_ch1(), ep2_ch1()), - kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Adding address in ep1 will trigger continual gathering. AddAddress(0, kAlternateAddrs[0]); - EXPECT_EQ_SIMULATED_WAIT(1, - GetEndpoint(0)->GetIceRegatheringCountForReason( - IceRegatheringReason::NETWORK_CHANGE), - kDefaultTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return GetEndpoint(0)->GetIceRegatheringCountForReason( + IceRegatheringReason::NETWORK_CHANGE); + }, + Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); ep2_ch1()->SetIceParameters(kIceParams[3]); ep2_ch1()->SetRemoteIceParameters(kIceParams[2]); @@ -1467,8 +1534,12 @@ TEST_F(P2PTransportChannelTest, config2.regather_on_failed_networks_interval = 2000; CreateChannels(config1, config2); - EXPECT_TRUE_SIMULATED_WAIT(CheckConnected(ep1_ch1(), ep2_ch1()), - kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); // Timeout value such that all connections are deleted. @@ -1499,7 +1570,10 @@ TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) { // Wait until the callee becomes writable to make sure that a ping request is // received by the caller before their remote ICE credentials are set. - ASSERT_TRUE_WAIT(ep2_ch1()->selected_connection() != nullptr, kMediumTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ep2_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); // Add two sets of remote ICE credentials, so that the ones used by the // candidate will be generation 1 instead of 0. ep1_ch1()->SetRemoteIceParameters(kIceParams[3]); @@ -1507,9 +1581,13 @@ TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) { // The caller should have the selected connection connected to the peer // reflexive candidate. const Connection* selected_connection = nullptr; - ASSERT_TRUE_WAIT( - (selected_connection = ep1_ch1()->selected_connection()) != nullptr, - kMediumTimeout); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { + return selected_connection = ep1_ch1()->selected_connection(); + }, + Ne(nullptr), {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); EXPECT_TRUE(selected_connection->remote_candidate().is_prflx()); EXPECT_EQ(kIceUfrag[1], selected_connection->remote_candidate().username()); EXPECT_EQ(kIcePwd[1], selected_connection->remote_candidate().password()); @@ -1517,9 +1595,16 @@ TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) { ResumeCandidates(1); // Verify ep1's selected connection is updated to use the 'local' candidate. - EXPECT_TRUE_WAIT( - ep1_ch1()->selected_connection()->remote_candidate().is_local(), - kMediumTimeout); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { + return ep1_ch1() + ->selected_connection() + ->remote_candidate() + .is_local(); + }, + IsTrue(), {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection()); DestroyChannels(); } @@ -1540,9 +1625,15 @@ TEST_F(P2PTransportChannelTest, PeerReflexiveRemoteCandidateIsSanitized) { // candidate. PauseCandidates(1); - ASSERT_TRUE_WAIT(ep2_ch1()->selected_connection() != nullptr, kMediumTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ep2_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); ep1_ch1()->SetRemoteIceParameters(kIceParams[1]); - ASSERT_TRUE_WAIT(ep1_ch1()->selected_connection() != nullptr, kMediumTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ep1_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); // Check the selected candidate pair. auto pair_ep1 = ep1_ch1()->GetSelectedCandidatePair(); @@ -1563,10 +1654,17 @@ TEST_F(P2PTransportChannelTest, PeerReflexiveRemoteCandidateIsSanitized) { // Let ep1 receive the remote candidate to update its type from prflx to host. ResumeCandidates(1); - ASSERT_TRUE_WAIT( - ep1_ch1()->selected_connection() != nullptr && - ep1_ch1()->selected_connection()->remote_candidate().is_local(), - kMediumTimeout); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { + return ep1_ch1()->selected_connection() != nullptr && + ep1_ch1() + ->selected_connection() + ->remote_candidate() + .is_local(); + }, + IsTrue(), {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); // We should be able to reveal the address after it is learnt via // AddIceCandidate. @@ -1605,7 +1703,10 @@ TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) { // Wait until the callee becomes writable to make sure that a ping request is // received by the caller before their remote ICE credentials are set. - ASSERT_TRUE_WAIT(ep2_ch1()->selected_connection() != nullptr, kMediumTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ep2_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); // Add two sets of remote ICE credentials, so that the ones used by the // candidate will be generation 1 instead of 0. ep1_ch1()->SetRemoteIceParameters(kIceParams[3]); @@ -1614,9 +1715,13 @@ TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) { // The caller's selected connection should be connected to the peer reflexive // candidate. const Connection* selected_connection = nullptr; - ASSERT_TRUE_WAIT( - (selected_connection = ep1_ch1()->selected_connection()) != nullptr, - kMediumTimeout); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { + return selected_connection = ep1_ch1()->selected_connection(); + }, + Ne(nullptr), {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); EXPECT_TRUE(selected_connection->remote_candidate().is_prflx()); EXPECT_EQ(kIceUfrag[1], selected_connection->remote_candidate().username()); EXPECT_EQ(kIcePwd[1], selected_connection->remote_candidate().password()); @@ -1624,9 +1729,16 @@ TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) { ResumeCandidates(1); - EXPECT_TRUE_WAIT( - ep1_ch1()->selected_connection()->remote_candidate().is_prflx(), - kMediumTimeout); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { + return ep1_ch1() + ->selected_connection() + ->remote_candidate() + .is_prflx(); + }, + IsTrue(), {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection()); DestroyChannels(); } @@ -1654,7 +1766,11 @@ TEST_F(P2PTransportChannelTest, // Wait for the initial connection to be made. ep1_ch1()->SetRemoteIceParameters(kIceParams[1]); ep2_ch1()->SetRemoteIceParameters(kIceParams[0]); - EXPECT_TRUE_WAIT(CheckConnected(ep1_ch1(), ep2_ch1()), kDefaultTimeout); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Simulate an ICE restart on ep2, but don't signal the candidate or new // ICE parameters until after a prflx connection has been made. @@ -1666,9 +1782,16 @@ TEST_F(P2PTransportChannelTest, // The caller should have the selected connection connected to the peer // reflexive candidate. - EXPECT_TRUE_WAIT( - ep1_ch1()->selected_connection()->remote_candidate().is_prflx(), - kDefaultTimeout); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { + return ep1_ch1() + ->selected_connection() + ->remote_candidate() + .is_prflx(); + }, + IsTrue(), {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); const Connection* prflx_selected_connection = ep1_ch1()->selected_connection(); @@ -1682,9 +1805,16 @@ TEST_F(P2PTransportChannelTest, // their information to update the peer reflexive candidate. ResumeCandidates(1); - EXPECT_TRUE_WAIT( - ep1_ch1()->selected_connection()->remote_candidate().is_relay(), - kDefaultTimeout); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { + return ep1_ch1() + ->selected_connection() + ->remote_candidate() + .is_relay(); + }, + IsTrue(), {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_EQ(prflx_selected_connection, ep1_ch1()->selected_connection()); DestroyChannels(); } @@ -1698,9 +1828,15 @@ TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) { CreateChannels(); const Connection* selected_connection = NULL; // Wait until the callee's connections are created. - EXPECT_TRUE_SIMULATED_WAIT( - (selected_connection = ep2_ch1()->selected_connection()) != NULL, - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return selected_connection = + ep2_ch1()->selected_connection(); + }, + NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Wait to make sure the selected connection is not changed. SIMULATED_WAIT(ep2_ch1()->selected_connection() != selected_connection, kShortTimeout, clock); @@ -1741,8 +1877,12 @@ TEST_F(P2PTransportChannelTest, IncomingOnlyOpen) { CreateChannels(); ep1_ch1()->set_incoming_only(true); - EXPECT_TRUE_SIMULATED_WAIT(CheckConnected(ep1_ch1(), ep2_ch1()), - kMediumTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); DestroyChannels(); } @@ -1809,10 +1949,15 @@ TEST_F(P2PTransportChannelTest, TestTcpConnectionsFromActiveToPassive) { ResumeCandidates(0); ResumeCandidates(1); - EXPECT_TRUE_SIMULATED_WAIT( - CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), kPublicAddrs[0], - kPublicAddrs[1]), - kShortTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return CheckCandidatePairAndConnected( + ep1_ch1(), ep2_ch1(), kPublicAddrs[0], kPublicAddrs[1]); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kShortTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); TestSendRecv(&clock); DestroyChannels(); @@ -1829,8 +1974,12 @@ TEST_F(P2PTransportChannelTest, TestTcpConnectionTcptypeSet) { SetAllowTcpListen(1, true); // actpass. CreateChannels(); - EXPECT_TRUE_SIMULATED_WAIT(CheckConnected(ep1_ch1(), ep2_ch1()), - kMediumTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); SIMULATED_WAIT(false, kDefaultTimeout, clock); EXPECT_EQ(RemoteCandidate(ep1_ch1())->tcptype(), "passive"); @@ -1856,13 +2005,23 @@ TEST_F(P2PTransportChannelTest, TestIceRoleConflict) { GetEndpoint(1)->allocator_->ice_tiebreaker(); // Since both the channels initiated with controlling state, the channel with // the lower tiebreaker should receive SignalRoleConflict. - EXPECT_TRUE_SIMULATED_WAIT( - GetRoleConflict(first_endpoint_has_lower_tiebreaker ? 0 : 1), - kShortTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { + return GetRoleConflict(first_endpoint_has_lower_tiebreaker ? 0 : 1); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kShortTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_FALSE(GetRoleConflict(first_endpoint_has_lower_tiebreaker ? 1 : 0)); - EXPECT_TRUE_SIMULATED_WAIT(CheckConnected(ep1_ch1(), ep2_ch1()), - kShortTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kShortTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection()); @@ -1884,7 +2043,11 @@ TEST_F(P2PTransportChannelTest, TestIceConfigWillPassDownToPort) { CreateChannels(); - EXPECT_EQ_SIMULATED_WAIT(2u, ep1_ch1()->ports().size(), kShortTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ep1_ch1()->ports().size(); }, Eq(2u), + {.timeout = webrtc::TimeDelta::Millis(kShortTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); const std::vector ports_before = ep1_ch1()->ports(); for (size_t i = 0; i < ports_before.size(); ++i) { @@ -1898,8 +2061,12 @@ TEST_F(P2PTransportChannelTest, TestIceConfigWillPassDownToPort) { EXPECT_EQ(ICEROLE_CONTROLLED, ports_before[i]->GetIceRole()); } - EXPECT_TRUE_SIMULATED_WAIT(CheckConnected(ep1_ch1(), ep2_ch1()), - kShortTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kShortTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection()); @@ -1946,10 +2113,16 @@ TEST_F(P2PTransportChannelTest, TestIPv6Connections) { CreateChannels(); - EXPECT_TRUE_SIMULATED_WAIT( - CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), kIPv6PublicAddrs[0], - kIPv6PublicAddrs[1]), - kShortTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), + kIPv6PublicAddrs[0], + kIPv6PublicAddrs[1]); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kShortTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); TestSendRecv(&clock); DestroyChannels(); @@ -1969,8 +2142,12 @@ TEST_F(P2PTransportChannelTest, TestForceTurn) { CreateChannels(); - EXPECT_TRUE_SIMULATED_WAIT(CheckConnected(ep1_ch1(), ep2_ch1()), - kMediumTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection()); @@ -1998,8 +2175,12 @@ TEST_F(P2PTransportChannelTest, TestContinualGathering) { IceConfig default_config; CreateChannels(continual_gathering_config, default_config); - EXPECT_TRUE_SIMULATED_WAIT(CheckConnected(ep1_ch1(), ep2_ch1()), - kMediumTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); SIMULATED_WAIT( IceGatheringState::kIceGatheringComplete == ep1_ch1()->gathering_state(), kShortTimeout, clock); @@ -2041,8 +2222,12 @@ TEST_F(P2PTransportChannelTest, TestUsingPooledSessionBeforeDoneGathering) { EXPECT_TRUE(pooled_session_2->ReadyCandidates().empty()); // Now let the endpoints connect and try exchanging some data. CreateChannels(); - EXPECT_TRUE_SIMULATED_WAIT(CheckConnected(ep1_ch1(), ep2_ch1()), - kMediumTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); TestSendRecv(&clock); // Make sure the P2PTransportChannels are actually using ports from the // pooled sessions. @@ -2079,13 +2264,23 @@ TEST_F(P2PTransportChannelTest, TestUsingPooledSessionAfterDoneGathering) { ASSERT_NE(nullptr, pooled_session_2); // Wait for the pooled sessions to finish gathering before the // P2PTransportChannels try to use them. - EXPECT_TRUE_SIMULATED_WAIT(pooled_session_1->CandidatesAllocationDone() && - pooled_session_2->CandidatesAllocationDone(), - kDefaultTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return pooled_session_1->CandidatesAllocationDone() && + pooled_session_2->CandidatesAllocationDone(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Now let the endpoints connect and try exchanging some data. CreateChannels(); - EXPECT_TRUE_SIMULATED_WAIT(CheckConnected(ep1_ch1(), ep2_ch1()), - kMediumTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); TestSendRecv(&clock); // Make sure the P2PTransportChannels are actually using ports from the // pooled sessions. @@ -2115,8 +2310,11 @@ TEST_F(P2PTransportChannelTest, TurnToTurnPresumedWritable) { config.presume_writable_when_fully_relayed = true; ep1_ch1()->SetIceConfig(config); ep1_ch1()->MaybeStartGathering(); - EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete, - ep1_ch1()->gathering_state(), kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ep1_ch1()->gathering_state(); }, + Eq(IceGatheringState::kIceGatheringComplete), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Add two remote candidates; a host candidate (with higher priority) // and TURN candidate. ep1_ch1()->AddRemoteCandidate( @@ -2125,7 +2323,10 @@ TEST_F(P2PTransportChannelTest, TurnToTurnPresumedWritable) { CreateUdpCandidate(IceCandidateType::kRelay, "2.2.2.2", 2, 0)); // Expect that the TURN-TURN candidate pair will be prioritized since it's // "probably writable". - EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection() != nullptr, kShortTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ep1_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kShortTimeout)}), + webrtc::IsRtcOk()); EXPECT_TRUE(LocalCandidate(ep1_ch1())->is_relay()); EXPECT_TRUE(RemoteCandidate(ep1_ch1())->is_relay()); // Also expect that the channel instantly indicates that it's writable since @@ -2171,8 +2372,13 @@ TEST_F(P2PTransportChannelTest, TurnToPrflxPresumedWritable) { ep2_ch1()->MaybeStartGathering(); // Wait for the TURN<->prflx connection. - EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable(), - kShortTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return ep1_ch1()->receiving() && ep1_ch1()->writable(); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kShortTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); ASSERT_NE(nullptr, ep1_ch1()->selected_connection()); EXPECT_TRUE(LocalCandidate(ep1_ch1())->is_relay()); EXPECT_TRUE(RemoteCandidate(ep1_ch1())->is_prflx()); @@ -2181,8 +2387,12 @@ TEST_F(P2PTransportChannelTest, TurnToPrflxPresumedWritable) { EXPECT_FALSE(ep1_ch1()->selected_connection()->writable()); // Now wait for it to actually become writable. - EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->writable(), - kShortTimeout, fake_clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ep1_ch1()->selected_connection()->writable(); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kShortTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); // Explitly destroy channels, before fake clock is destroyed. DestroyChannels(); @@ -2206,14 +2416,21 @@ TEST_F(P2PTransportChannelTest, PresumedWritablePreferredOverUnreliable) { ep1_ch1()->MaybeStartGathering(); ep2_ch1()->MaybeStartGathering(); // Wait for initial connection as usual. - EXPECT_TRUE_SIMULATED_WAIT(CheckConnected(ep1_ch1(), ep2_ch1()), - kShortTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kShortTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); const Connection* old_selected_connection = ep1_ch1()->selected_connection(); // Destroy the second channel and wait for the current connection on the // first channel to become "unreliable", making it no longer writable. GetEndpoint(1)->cd1_.ch_.reset(); - EXPECT_TRUE_SIMULATED_WAIT(!ep1_ch1()->writable(), kDefaultTimeout, - fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return !ep1_ch1()->writable(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_NE(nullptr, ep1_ch1()->selected_connection()); // Add a remote TURN candidate. The first channel should still have a TURN // port available to make a TURN<->TURN pair that's presumed writable. @@ -2241,12 +2458,18 @@ TEST_F(P2PTransportChannelTest, SignalReadyToSendWithPresumedWritable) { config.presume_writable_when_fully_relayed = true; ep1_ch1()->SetIceConfig(config); ep1_ch1()->MaybeStartGathering(); - EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete, - ep1_ch1()->gathering_state(), kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ep1_ch1()->gathering_state(); }, + Eq(IceGatheringState::kIceGatheringComplete), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); ep1_ch1()->AddRemoteCandidate( CreateUdpCandidate(IceCandidateType::kRelay, "1.1.1.1", 1, 0)); // Sanity checking the type of the connection. - EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection() != nullptr, kShortTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ep1_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kShortTimeout)}), + webrtc::IsRtcOk()); EXPECT_TRUE(LocalCandidate(ep1_ch1())->is_relay()); EXPECT_TRUE(RemoteCandidate(ep1_ch1())->is_relay()); @@ -2296,8 +2519,13 @@ TEST_F(P2PTransportChannelTest, ep1_ch1()->MaybeStartGathering(); ep2_ch1()->MaybeStartGathering(); - EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable(), - kMediumTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return ep1_ch1()->receiving() && ep1_ch1()->writable(); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); ASSERT_NE(nullptr, ep1_ch1()->selected_connection()); @@ -2328,8 +2556,12 @@ TEST_F(P2PTransportChannelTest, CreateChannels(ep1_config, ep2_config); // Wait until both sides become writable for the first time. - EXPECT_TRUE_SIMULATED_WAIT(CheckConnected(ep1_ch1(), ep2_ch1()), - kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Block the ingress traffic to ep1 so that there is no check response from // ep2. ASSERT_NE(nullptr, LocalCandidate(ep1_ch1())); @@ -2337,8 +2569,13 @@ TEST_F(P2PTransportChannelTest, LocalCandidate(ep1_ch1())->address()); // Wait until ep1 becomes unwritable. At the same time ep2 should be still // fine so that it will keep sending pings. - EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1() != nullptr && !ep1_ch1()->writable(), - kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return ep1_ch1() != nullptr && !ep1_ch1()->writable(); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(ep2_ch1() != nullptr && ep2_ch1()->writable()); // Now let the pings from ep2 to flow but block any pings from ep1, so that // ep1 can only become writable again after receiving an incoming ping from @@ -2348,8 +2585,12 @@ TEST_F(P2PTransportChannelTest, fw()->ClearRules(); fw()->AddRule(false, rtc::FP_ANY, rtc::FD_OUT, LocalCandidate(ep1_ch1())->address()); - EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1() != nullptr && ep1_ch1()->writable(), - kDefaultTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ep1_ch1() != nullptr && ep1_ch1()->writable(); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); DestroyChannels(); } @@ -2486,10 +2727,15 @@ TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControlledSide) { // Create channels and let them go writable, as usual. CreateChannels(config, config); - EXPECT_TRUE_SIMULATED_WAIT( - CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), kPublicAddrs[0], - kPublicAddrs[1]), - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return CheckCandidatePairAndConnected( + ep1_ch1(), ep2_ch1(), kPublicAddrs[0], kPublicAddrs[1]); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Blackhole any traffic to or from the public addrs. RTC_LOG(LS_INFO) << "Failing over..."; @@ -2497,14 +2743,23 @@ TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControlledSide) { // The selected connections may switch, so keep references to them. const Connection* selected_connection1 = ep1_ch1()->selected_connection(); // We should detect loss of receiving within 1 second or so. - EXPECT_TRUE_SIMULATED_WAIT(!selected_connection1->receiving(), kMediumTimeout, - clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return !selected_connection1->receiving(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // We should switch over to use the alternate addr on both sides // when we are not receiving. - EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() && - ep2_ch1()->selected_connection()->receiving(), - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return ep1_ch1()->selected_connection()->receiving() && + ep2_ch1()->selected_connection()->receiving(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0])); EXPECT_TRUE( RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1])); @@ -2531,10 +2786,15 @@ TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControllingSide) { IceConfig config = CreateIceConfig(1000, GATHER_ONCE); // Create channels and let them go writable, as usual. CreateChannels(config, config); - EXPECT_TRUE_SIMULATED_WAIT( - CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), kPublicAddrs[0], - kPublicAddrs[1]), - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return CheckCandidatePairAndConnected( + ep1_ch1(), ep2_ch1(), kPublicAddrs[0], kPublicAddrs[1]); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Blackhole any traffic to or from the public addrs. RTC_LOG(LS_INFO) << "Failing over..."; @@ -2543,10 +2803,16 @@ TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControllingSide) { // We should detect loss of receiving within 1 second or so. // We should switch over to use the alternate addr on both sides // when we are not receiving. - EXPECT_TRUE_SIMULATED_WAIT( - CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), kAlternateAddrs[0], - kPublicAddrs[1]), - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), + kAlternateAddrs[0], + kPublicAddrs[1]); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); DestroyChannels(); } @@ -2593,10 +2859,15 @@ TEST_F(P2PTransportChannelMultihomedTest, TestFailoverWithManyConnections) { IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY); // Create channels and let them go writable, as usual. CreateChannels(config, config, true /* ice_renomination */); - EXPECT_TRUE_SIMULATED_WAIT( - CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), wifiIpv6[0], - wifiIpv6[1]), - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return CheckCandidatePairAndConnected( + ep1_ch1(), ep2_ch1(), wifiIpv6[0], wifiIpv6[1]); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Blackhole any traffic to or from the wifi on endpoint 1. RTC_LOG(LS_INFO) << "Failing over..."; @@ -2606,9 +2877,15 @@ TEST_F(P2PTransportChannelMultihomedTest, TestFailoverWithManyConnections) { // The selected connections may switch, so keep references to them. const Connection* selected_connection1 = ep1_ch1()->selected_connection(); const Connection* selected_connection2 = ep2_ch1()->selected_connection(); - EXPECT_TRUE_SIMULATED_WAIT( - !selected_connection1->receiving() && !selected_connection2->receiving(), - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return !selected_connection1->receiving() && + !selected_connection2->receiving(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Per-network best connections will be pinged at relatively higher rate when // the selected connection becomes not receiving. @@ -2617,9 +2894,13 @@ TEST_F(P2PTransportChannelMultihomedTest, TestFailoverWithManyConnections) { ASSERT_NE(nullptr, per_network_best_connection1); int64_t last_ping_sent1 = per_network_best_connection1->last_ping_sent(); int num_pings_sent1 = per_network_best_connection1->num_pings_sent(); - EXPECT_TRUE_SIMULATED_WAIT( - num_pings_sent1 < per_network_best_connection1->num_pings_sent(), - kMediumTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return per_network_best_connection1->num_pings_sent(); }, + Gt(num_pings_sent1), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); ASSERT_GT(per_network_best_connection1->num_pings_sent() - num_pings_sent1, 0); int64_t ping_interval1 = @@ -2632,10 +2913,15 @@ TEST_F(P2PTransportChannelMultihomedTest, TestFailoverWithManyConnections) { // It should switch over to use the cellular IPv6 addr on endpoint 1 before // it timed out on writing. - EXPECT_TRUE_SIMULATED_WAIT( - CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), cellularIpv6[0], - wifiIpv6[1]), - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return CheckCandidatePairAndConnected( + ep1_ch1(), ep2_ch1(), cellularIpv6[0], wifiIpv6[1]); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); DestroyChannels(); } @@ -2660,12 +2946,22 @@ TEST_F(P2PTransportChannelMultihomedTest, TestIceRenomination) { IceConfig config = CreateIceConfig(1000, GATHER_ONCE); // Create channels with ICE renomination and let them go writable as usual. CreateChannels(config, config, true); - ASSERT_TRUE_SIMULATED_WAIT(CheckConnected(ep1_ch1(), ep2_ch1()), - kMediumTimeout, clock); - EXPECT_TRUE_SIMULATED_WAIT( - ep2_ch1()->selected_connection()->remote_nomination() > 0 && - ep1_ch1()->selected_connection()->acked_nomination() > 0, - kDefaultTimeout, clock); + ASSERT_THAT( + webrtc::WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { + return ep2_ch1()->selected_connection()->remote_nomination() > 0 && + ep1_ch1()->selected_connection()->acked_nomination() > 0; + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); const Connection* selected_connection1 = ep1_ch1()->selected_connection(); Connection* selected_connection2 = const_cast(ep2_ch1()->selected_connection()); @@ -2681,15 +2977,21 @@ TEST_F(P2PTransportChannelMultihomedTest, TestIceRenomination) { fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); // The selected connection on the controlling side should switch. - EXPECT_TRUE_SIMULATED_WAIT( - ep1_ch1()->selected_connection() != selected_connection1, kMediumTimeout, - clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ep1_ch1()->selected_connection(); }, + Ne(selected_connection1), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // The connection on the controlled side should be nominated again // and have an increased nomination. - EXPECT_TRUE_SIMULATED_WAIT( - ep2_ch1()->selected_connection()->remote_nomination() > - remote_nomination2, - kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return ep2_ch1()->selected_connection()->remote_nomination(); }, + Gt(remote_nomination2), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); DestroyChannels(); } @@ -2714,10 +3016,15 @@ TEST_F(P2PTransportChannelMultihomedTest, // Create channels and let them go writable, as usual. CreateChannels(); - EXPECT_TRUE_SIMULATED_WAIT( - CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), kPublicAddrs[0], - kPublicAddrs[1]), - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return CheckCandidatePairAndConnected( + ep1_ch1(), ep2_ch1(), kPublicAddrs[0], kPublicAddrs[1]); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Make the receiving timeout shorter for testing. IceConfig config = CreateIceConfig(1000, GATHER_ONCE); @@ -2732,17 +3039,26 @@ TEST_F(P2PTransportChannelMultihomedTest, // The selected connections may switch, so keep references to them. const Connection* selected_connection1 = ep1_ch1()->selected_connection(); // We should detect loss of receiving within 1 second or so. - EXPECT_TRUE_SIMULATED_WAIT(!selected_connection1->receiving(), kMediumTimeout, - clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return !selected_connection1->receiving(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // After a short while, the link recovers itself. SIMULATED_WAIT(false, 10, clock); fw()->ClearRules(); // We should remain on the public address on both sides and no connection // switches should have happened. - EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() && - ep2_ch1()->selected_connection()->receiving(), - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return ep1_ch1()->selected_connection()->receiving() && + ep2_ch1()->selected_connection()->receiving(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); EXPECT_TRUE(LocalCandidate(ep2_ch1())->address().EqualIPs(kPublicAddrs[1])); EXPECT_EQ(0, reset_selected_candidate_pair_switches()); @@ -2766,10 +3082,15 @@ TEST_F(P2PTransportChannelMultihomedTest, // Create channels and let them go writable, as usual. CreateChannels(); - EXPECT_TRUE_SIMULATED_WAIT( - CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), kPublicAddrs[0], - kPublicAddrs[1]), - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return CheckCandidatePairAndConnected( + ep1_ch1(), ep2_ch1(), kPublicAddrs[0], kPublicAddrs[1]); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Make the receiving timeout shorter for testing. IceConfig config = CreateIceConfig(1000, GATHER_ONCE); @@ -2783,18 +3104,26 @@ TEST_F(P2PTransportChannelMultihomedTest, // The selected connections may switch, so keep references to them. const Connection* selected_connection1 = ep1_ch1()->selected_connection(); // We should detect loss of receiving within 1 second or so. - EXPECT_TRUE_SIMULATED_WAIT(!selected_connection1->receiving(), kMediumTimeout, - clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return !selected_connection1->receiving(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // The link recovers after a short while. SIMULATED_WAIT(false, 10, clock); fw()->ClearRules(); // We should not switch to the alternate addr on both sides because of the // dampening. - EXPECT_TRUE_SIMULATED_WAIT( - CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), kPublicAddrs[0], - kPublicAddrs[1]), - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return CheckCandidatePairAndConnected( + ep1_ch1(), ep2_ch1(), kPublicAddrs[0], kPublicAddrs[1]); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_EQ(0, reset_selected_candidate_pair_switches()); DestroyChannels(); } @@ -2824,17 +3153,27 @@ TEST_F(P2PTransportChannelMultihomedTest, TestRemoteFailover) { ep1_ch1()->SetIceConfig(config); ep2_ch1()->SetIceConfig(config); // Need to wait to make sure the connections on both networks are writable. - EXPECT_TRUE_SIMULATED_WAIT( - CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), wifi[0], wifi[1]), - kDefaultTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), + wifi[0], wifi[1]); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); Connection* backup_conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0]); ASSERT_NE(nullptr, backup_conn); // After a short while, the backup connection will be writable but not // receiving because backup connection is pinged at a slower rate. - EXPECT_TRUE_SIMULATED_WAIT( - backup_conn->writable() && !backup_conn->receiving(), kDefaultTimeout, - clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return backup_conn->writable() && !backup_conn->receiving(); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); reset_selected_candidate_pair_switches(); // Blackhole any traffic to or from the remote WiFi networks. RTC_LOG(LS_INFO) << "Failing over..."; @@ -2867,9 +3206,13 @@ TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiToWifiConnection) { EXPECT_TRUE_WAIT_MARGIN(CheckConnected(ep1_ch1(), ep2_ch1()), 1000, 1000); // Need to wait to make sure the connections on both networks are writable. - EXPECT_TRUE_WAIT( - CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), wifi[0], wifi[1]), - 1000); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), + wifi[0], wifi[1]); + }, + IsTrue()), + webrtc::IsRtcOk()); DestroyChannels(); } @@ -2918,16 +3261,22 @@ TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) { CreateIceConfig(2000, GATHER_ONCE, backup_ping_interval)); // After the state becomes COMPLETED, the backup connection will be pinged // once every `backup_ping_interval` milliseconds. - ASSERT_TRUE_WAIT(ep2_ch1()->GetState() == IceTransportState::STATE_COMPLETED, - 1000); + ASSERT_THAT(webrtc::WaitUntil([&] { return ep2_ch1()->GetState(); }, + Eq(IceTransportState::STATE_COMPLETED)), + webrtc::IsRtcOk()); auto connections = ep2_ch1()->connections(); ASSERT_EQ(2U, connections.size()); Connection* backup_conn = GetBackupConnection(ep2_ch1()); - EXPECT_TRUE_WAIT(backup_conn->writable(), kMediumTimeout); + EXPECT_THAT( + webrtc::WaitUntil([&] { return backup_conn->writable(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); int64_t last_ping_response_ms = backup_conn->last_ping_response_received(); - EXPECT_TRUE_WAIT( - last_ping_response_ms < backup_conn->last_ping_response_received(), - kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return backup_conn->last_ping_response_received(); }, + Gt(last_ping_response_ms), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); int time_elapsed = backup_conn->last_ping_response_received() - last_ping_response_ms; RTC_LOG(LS_INFO) << "Time elapsed: " << time_elapsed; @@ -2959,20 +3308,26 @@ TEST_F(P2PTransportChannelMultihomedTest, TestStableWritableRate) { ep2_ch1()->SetIceConfig(config); // After the state becomes COMPLETED and is stable and writable, the // connection will be pinged once every `ping_interval_ms` milliseconds. - ASSERT_TRUE_WAIT(ep2_ch1()->GetState() == IceTransportState::STATE_COMPLETED, - 1000); + ASSERT_THAT(webrtc::WaitUntil([&] { return ep2_ch1()->GetState(); }, + Eq(IceTransportState::STATE_COMPLETED)), + webrtc::IsRtcOk()); auto connections = ep2_ch1()->connections(); ASSERT_EQ(2U, connections.size()); Connection* conn = GetBestConnection(ep2_ch1()); - EXPECT_TRUE_WAIT(conn->writable(), kMediumTimeout); + EXPECT_THAT( + webrtc::WaitUntil([&] { return conn->writable(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); int64_t last_ping_response_ms; // Burn through some pings so the connection is stable. for (int i = 0; i < 5; i++) { last_ping_response_ms = conn->last_ping_response_received(); - EXPECT_TRUE_WAIT( - last_ping_response_ms < conn->last_ping_response_received(), - kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return conn->last_ping_response_received(); }, + Gt(last_ping_response_ms), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); } EXPECT_TRUE(conn->stable(last_ping_response_ms)) << "Connection not stable"; int time_elapsed = @@ -2992,10 +3347,18 @@ TEST_F(P2PTransportChannelMultihomedTest, TestGetState) { CreateChannels(); // Both transport channels will reach STATE_COMPLETED quickly. - EXPECT_EQ_SIMULATED_WAIT(IceTransportState::STATE_COMPLETED, - ep1_ch1()->GetState(), kShortTimeout, clock); - EXPECT_EQ_SIMULATED_WAIT(IceTransportState::STATE_COMPLETED, - ep2_ch1()->GetState(), kShortTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ep1_ch1()->GetState(); }, + Eq(IceTransportState::STATE_COMPLETED), + {.timeout = webrtc::TimeDelta::Millis(kShortTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ep2_ch1()->GetState(); }, + Eq(IceTransportState::STATE_COMPLETED), + {.timeout = webrtc::TimeDelta::Millis(kShortTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); DestroyChannels(); } @@ -3014,8 +3377,12 @@ TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) { SetAllocatorFlags(0, kOnlyLocalPorts); SetAllocatorFlags(1, kOnlyLocalPorts); - ASSERT_TRUE_SIMULATED_WAIT(CheckConnected(ep1_ch1(), ep2_ch1()), - kDefaultTimeout, clock); + ASSERT_THAT( + webrtc::WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // More than one port has been created. EXPECT_LE(1U, ep1_ch1()->ports().size()); // Endpoint 1 enabled continual gathering; the port will be removed @@ -3023,8 +3390,10 @@ TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) { RemoveAddress(0, kPublicAddrs[0]); EXPECT_TRUE(ep1_ch1()->ports().empty()); // The remote candidates will be removed eventually. - EXPECT_TRUE_SIMULATED_WAIT(ep2_ch1()->remote_candidates().empty(), 1000, - clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ep2_ch1()->remote_candidates().empty(); }, + IsTrue(), {.clock = &clock}), + webrtc::IsRtcOk()); size_t num_ports = ep2_ch1()->ports().size(); EXPECT_LE(1U, num_ports); @@ -3034,9 +3403,12 @@ TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) { // other participant will not be removed. RemoveAddress(1, kPublicAddrs[1]); - EXPECT_EQ_SIMULATED_WAIT(0U, ep2_ch1()->ports().size(), kDefaultTimeout, - clock); - SIMULATED_WAIT(0U == ep1_ch1()->remote_candidates().size(), 500, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ep2_ch1()->ports().size(); }, Eq(0U), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); + SIMULATED_WAIT(ep1_ch1()->remote_candidates().empty(), 500, clock); EXPECT_EQ(num_remote_candidates, ep1_ch1()->remote_candidates().size()); DestroyChannels(); @@ -3063,36 +3435,58 @@ TEST_F(P2PTransportChannelMultihomedTest, // to be created and the new one will be the best connection. AddAddress(1, wifi[1], "test_wifi1", rtc::ADAPTER_TYPE_WIFI); const Connection* conn; - EXPECT_TRUE_WAIT((conn = ep1_ch1()->selected_connection()) != nullptr && - HasRemoteAddress(conn, wifi[1]), - kDefaultTimeout); - EXPECT_TRUE_WAIT((conn = ep2_ch1()->selected_connection()) != nullptr && - HasLocalAddress(conn, wifi[1]), - kDefaultTimeout); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { + return (conn = ep1_ch1()->selected_connection()) != nullptr && + HasRemoteAddress(conn, wifi[1]); + }, + IsTrue(), {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { + return (conn = ep2_ch1()->selected_connection()) != nullptr && + HasLocalAddress(conn, wifi[1]); + }, + IsTrue(), {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Add a new cellular interface on end point 1, we should expect a new // backup connection created using this new interface. AddAddress(0, cellular[0], "test_cellular0", rtc::ADAPTER_TYPE_CELLULAR); - EXPECT_TRUE_WAIT( - ep1_ch1()->GetState() == IceTransportState::STATE_COMPLETED && - absl::c_any_of(ep1_ch1()->connections(), - [channel = ep1_ch1(), - address = cellular[0]](const Connection* conn) { - return HasLocalAddress(conn, address) && - conn != channel->selected_connection() && - conn->writable(); - }), - kDefaultTimeout); - EXPECT_TRUE_WAIT( - ep2_ch1()->GetState() == IceTransportState::STATE_COMPLETED && - absl::c_any_of(ep2_ch1()->connections(), - [channel = ep2_ch1(), - address = cellular[0]](const Connection* conn) { - return HasRemoteAddress(conn, address) && - conn != channel->selected_connection() && - conn->receiving(); - }), - kDefaultTimeout); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { + return ep1_ch1()->GetState() == + IceTransportState::STATE_COMPLETED && + absl::c_any_of( + ep1_ch1()->connections(), + [channel = ep1_ch1(), + address = cellular[0]](const Connection* conn) { + return HasLocalAddress(conn, address) && + conn != channel->selected_connection() && + conn->writable(); + }); + }, + IsTrue(), {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { + return ep2_ch1()->GetState() == + IceTransportState::STATE_COMPLETED && + absl::c_any_of( + ep2_ch1()->connections(), + [channel = ep2_ch1(), + address = cellular[0]](const Connection* conn) { + return HasRemoteAddress(conn, address) && + conn != channel->selected_connection() && + conn->receiving(); + }); + }, + IsTrue(), {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); DestroyChannels(); } @@ -3112,29 +3506,46 @@ TEST_F(P2PTransportChannelMultihomedTest, CreateIceConfig(1000, GATHER_CONTINUALLY); // Create channels and let them go writable, as usual. CreateChannels(continual_gathering_config, continual_gathering_config); - EXPECT_TRUE_SIMULATED_WAIT( - CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), kPublicAddrs[0], - kPublicAddrs[1]), - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return CheckCandidatePairAndConnected( + ep1_ch1(), ep2_ch1(), kPublicAddrs[0], kPublicAddrs[1]); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Add the new address first and then remove the other one. RTC_LOG(LS_INFO) << "Draining..."; AddAddress(1, kAlternateAddrs[1]); RemoveAddress(1, kPublicAddrs[1]); // We should switch to use the alternate address after an exchange of pings. - EXPECT_TRUE_SIMULATED_WAIT( - CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), kPublicAddrs[0], - kAlternateAddrs[1]), - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), + kPublicAddrs[0], + kAlternateAddrs[1]); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Remove one address first and then add another address. RTC_LOG(LS_INFO) << "Draining again..."; RemoveAddress(1, kAlternateAddrs[1]); AddAddress(1, kAlternateAddrs[0]); - EXPECT_TRUE_SIMULATED_WAIT( - CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), kPublicAddrs[0], - kAlternateAddrs[0]), - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), + kPublicAddrs[0], + kAlternateAddrs[0]); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); DestroyChannels(); } @@ -3156,22 +3567,38 @@ TEST_F(P2PTransportChannelMultihomedTest, TestRestoreBackupConnection) { IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY); config.regather_on_failed_networks_interval = 2000; CreateChannels(config, config); - EXPECT_TRUE_SIMULATED_WAIT( - CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), wifi[0], wifi[1]), - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(), + wifi[0], wifi[1]); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Destroy all backup connections. DestroyAllButBestConnection(ep1_ch1()); // Ensure the backup connection is removed first. - EXPECT_TRUE_SIMULATED_WAIT( - GetConnectionWithLocalAddress(ep1_ch1(), cellular[0]) == nullptr, - kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return GetConnectionWithLocalAddress(ep1_ch1(), cellular[0]); }, + Eq(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); const Connection* conn; - EXPECT_TRUE_SIMULATED_WAIT( - (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) != - nullptr && - conn != ep1_ch1()->selected_connection() && conn->writable(), - kDefaultTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return (conn = GetConnectionWithLocalAddress( + ep1_ch1(), cellular[0])) != nullptr && + conn != ep1_ch1()->selected_connection() && + conn->writable(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); DestroyChannels(); } @@ -3184,10 +3611,16 @@ TEST_F(P2PTransportChannelMultihomedTest, TestVpnDefault) { IceConfig config; CreateChannels(config, config, false); - EXPECT_TRUE_SIMULATED_WAIT( - CheckConnected(ep1_ch1(), ep2_ch1()) && - !ep1_ch1()->selected_connection()->network()->IsVpn(), - kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { + return CheckConnected(ep1_ch1(), ep2_ch1()) && + !ep1_ch1()->selected_connection()->network()->IsVpn(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); } TEST_F(P2PTransportChannelMultihomedTest, TestVpnPreferVpn) { @@ -3201,19 +3634,30 @@ TEST_F(P2PTransportChannelMultihomedTest, TestVpnPreferVpn) { config.vpn_preference = webrtc::VpnPreference::kPreferVpn; RTC_LOG(LS_INFO) << "KESO: config.vpn_preference: " << config.vpn_preference; CreateChannels(config, config, false); - EXPECT_TRUE_SIMULATED_WAIT( - CheckConnected(ep1_ch1(), ep2_ch1()) && - ep1_ch1()->selected_connection()->network()->IsVpn(), - kDefaultTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return CheckConnected(ep1_ch1(), ep2_ch1()) && + ep1_ch1()->selected_connection()->network()->IsVpn(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Block VPN. fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kAlternateAddrs[0]); // Check that it switches to non-VPN - EXPECT_TRUE_SIMULATED_WAIT( - CheckConnected(ep1_ch1(), ep2_ch1()) && - !ep1_ch1()->selected_connection()->network()->IsVpn(), - kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { + return CheckConnected(ep1_ch1(), ep2_ch1()) && + !ep1_ch1()->selected_connection()->network()->IsVpn(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); } TEST_F(P2PTransportChannelMultihomedTest, TestVpnAvoidVpn) { @@ -3226,19 +3670,30 @@ TEST_F(P2PTransportChannelMultihomedTest, TestVpnAvoidVpn) { IceConfig config; config.vpn_preference = webrtc::VpnPreference::kAvoidVpn; CreateChannels(config, config, false); - EXPECT_TRUE_SIMULATED_WAIT( - CheckConnected(ep1_ch1(), ep2_ch1()) && - !ep1_ch1()->selected_connection()->network()->IsVpn(), - kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { + return CheckConnected(ep1_ch1(), ep2_ch1()) && + !ep1_ch1()->selected_connection()->network()->IsVpn(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Block non-VPN. fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); // Check that it switches to VPN - EXPECT_TRUE_SIMULATED_WAIT( - CheckConnected(ep1_ch1(), ep2_ch1()) && - ep1_ch1()->selected_connection()->network()->IsVpn(), - kDefaultTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return CheckConnected(ep1_ch1(), ep2_ch1()) && + ep1_ch1()->selected_connection()->network()->IsVpn(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); } TEST_F(P2PTransportChannelMultihomedTest, TestVpnNeverVpn) { @@ -3251,18 +3706,28 @@ TEST_F(P2PTransportChannelMultihomedTest, TestVpnNeverVpn) { IceConfig config; config.vpn_preference = webrtc::VpnPreference::kNeverUseVpn; CreateChannels(config, config, false); - EXPECT_TRUE_SIMULATED_WAIT( - CheckConnected(ep1_ch1(), ep2_ch1()) && - !ep1_ch1()->selected_connection()->network()->IsVpn(), - kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { + return CheckConnected(ep1_ch1(), ep2_ch1()) && + !ep1_ch1()->selected_connection()->network()->IsVpn(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Block non-VPN. fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); // Check that it does not switches to VPN clock.AdvanceTime(webrtc::TimeDelta::Millis(kDefaultTimeout)); - EXPECT_TRUE_SIMULATED_WAIT(!CheckConnected(ep1_ch1(), ep2_ch1()), - kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return !CheckConnected(ep1_ch1(), ep2_ch1()); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); } TEST_F(P2PTransportChannelMultihomedTest, TestVpnOnlyVpn) { @@ -3275,18 +3740,27 @@ TEST_F(P2PTransportChannelMultihomedTest, TestVpnOnlyVpn) { IceConfig config; config.vpn_preference = webrtc::VpnPreference::kOnlyUseVpn; CreateChannels(config, config, false); - EXPECT_TRUE_SIMULATED_WAIT( - CheckConnected(ep1_ch1(), ep2_ch1()) && - ep1_ch1()->selected_connection()->network()->IsVpn(), - kDefaultTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return CheckConnected(ep1_ch1(), ep2_ch1()) && + ep1_ch1()->selected_connection()->network()->IsVpn(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Block VPN. fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kAlternateAddrs[0]); // Check that it does not switch to non-VPN clock.AdvanceTime(webrtc::TimeDelta::Millis(kDefaultTimeout)); - EXPECT_TRUE_SIMULATED_WAIT(!CheckConnected(ep1_ch1(), ep2_ch1()), - kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return !CheckConnected(ep1_ch1(), ep2_ch1()); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); } TEST_F(P2PTransportChannelMultihomedTest, StunDictionaryPerformsSync) { @@ -3317,8 +3791,12 @@ TEST_F(P2PTransportChannelMultihomedTest, StunDictionaryPerformsSync) { EXPECT_EQ(view.GetByteString(12)->string_view(), "keso"); }); EXPECT_CALL(writer_synced_func, Call).Times(1); - EXPECT_TRUE_SIMULATED_WAIT(CheckConnected(ep1_ch1(), ep2_ch1()), - kMediumTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); } // A collection of tests which tests a single P2PTransportChannel by sending @@ -3355,11 +3833,18 @@ class P2PTransportChannelPingTest : public ::testing::Test, int port_num, rtc::ThreadProcessingFakeClock* clock = nullptr) { if (clock == nullptr) { - EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, - kMediumTimeout); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return GetConnectionTo(ch, ip, port_num); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); } else { - EXPECT_TRUE_SIMULATED_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, - kMediumTimeout, *clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return GetConnectionTo(ch, ip, port_num); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &*clock}), + webrtc::IsRtcOk()); } return GetConnectionTo(ch, ip, port_num); } @@ -3413,9 +3898,12 @@ class P2PTransportChannelPingTest : public ::testing::Test, bool writable) { channel->AddRemoteCandidate( CreateUdpCandidate(IceCandidateType::kHost, ip_addr, port, priority)); - EXPECT_TRUE_SIMULATED_WAIT( - GetConnectionTo(channel, ip_addr, port) != nullptr, kMediumTimeout, - *clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return GetConnectionTo(channel, ip_addr, port); }, + Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &*clock}), + webrtc::IsRtcOk()); Connection* conn = GetConnectionTo(channel, ip_addr, port); if (conn && writable) { @@ -3597,10 +4085,14 @@ TEST_F(P2PTransportChannelPingTest, TestAllConnectionsPingedSufficiently) { // Low-priority connection becomes writable so that the other connection // is not pruned. conn1->ReceivedPingResponse(LOW_RTT, "id"); - EXPECT_TRUE_WAIT( - conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL && - conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, - kDefaultTimeout); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { + return conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL && + conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL; + }, + IsTrue(), {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); } // Verify that the connections are pinged at the right time. @@ -3709,8 +4201,11 @@ TEST_F(P2PTransportChannelPingTest, PingingStartedAsSoonAsPossible) { ch.SetIceRole(ICEROLE_CONTROLLING); ch.SetIceParameters(kIceParams[0]); ch.MaybeStartGathering(); - EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete, ch.gathering_state(), - kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.gathering_state(); }, + Eq(IceGatheringState::kIceGatheringComplete), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Simulate a binding request being received, creating a peer reflexive // candidate pair while we still don't have remote ICE parameters. @@ -3736,7 +4231,9 @@ TEST_F(P2PTransportChannelPingTest, PingingStartedAsSoonAsPossible) { // the first ping is sent as soon as possible, within one simulated clock // tick. ch.SetRemoteIceParameters(kIceParams[1]); - EXPECT_TRUE_SIMULATED_WAIT(conn->num_pings_sent() > 0, 1, clock); + EXPECT_THAT(webrtc::WaitUntil([&] { return conn->num_pings_sent(); }, Gt(0), + {.clock = &clock}), + webrtc::IsRtcOk()); } TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { @@ -3800,8 +4297,11 @@ TEST_F(P2PTransportChannelPingTest, TestSignalStateChanged) { // Pruning the connection reduces the set of active connections and changes // the channel state. conn1->Prune(); - EXPECT_EQ_WAIT(IceTransportState::STATE_FAILED, channel_state(), - kDefaultTimeout); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return channel_state(); }, Eq(IceTransportState::STATE_FAILED), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); } // Test adding remote candidates with different ufrags. If a remote candidate @@ -3845,8 +4345,11 @@ TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { ch.AddRemoteCandidate(CreateUdpCandidate(IceCandidateType::kHost, "3.3.3.3", 3, 0, kIceUfrag[2])); Connection* conn3 = nullptr; - ASSERT_TRUE_WAIT((conn3 = GetConnectionTo(&ch, "3.3.3.3", 3)) != nullptr, - kMediumTimeout); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return conn3 = GetConnectionTo(&ch, "3.3.3.3", 3); }, + Ne(nullptr), {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); const Candidate& new_candidate = conn3->remote_candidate(); EXPECT_EQ(kIcePwd[2], new_candidate.password()); EXPECT_EQ(1U, new_candidate.generation()); @@ -3887,11 +4390,17 @@ TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) { conn2->ReceivedPingResponse(LOW_RTT, "id"); // Wait for conn2 to be selected. - EXPECT_EQ_WAIT(conn2, ch.selected_connection(), kMediumTimeout); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ch.selected_connection(); }, Eq(conn2), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); // Destroy the connection to test SignalUnknownAddress. ch.RemoveConnectionForTest(conn1); - EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, - kMediumTimeout); + EXPECT_THAT( + webrtc::WaitUntil([&] { return GetConnectionTo(&ch, "1.1.1.1", 1); }, + Eq(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); // Create a minimal STUN message with prflx priority. IceMessage request(STUN_BINDING_REQUEST); @@ -3942,8 +4451,16 @@ TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) { conn1->OnReadPacket( rtc::ReceivedPacket::CreateFromLegacy("ABC", 3, rtc::TimeMicros())); - EXPECT_TRUE_SIMULATED_WAIT(ch.receiving(), kShortTimeout, clock); - EXPECT_TRUE_SIMULATED_WAIT(!ch.receiving(), kShortTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ch.receiving(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kShortTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); + EXPECT_THAT( + webrtc::WaitUntil([&] { return !ch.receiving(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kShortTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); } // The controlled side will select a connection as the "selected connection" @@ -3973,7 +4490,10 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { // A connection needs to be writable before it is selected for transmission. conn1->ReceivedPingResponse(LOW_RTT, "id"); - EXPECT_EQ_WAIT(conn1, ch.selected_connection(), kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.selected_connection(); }, Eq(conn1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_TRUE(CandidatePairMatchesNetworkRoute(conn1)); EXPECT_TRUE(ConnectionMatchesChangeEvent( conn1, "remote candidate generation maybe changed")); @@ -3986,7 +4506,10 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); ASSERT_TRUE(conn2 != nullptr); conn2->ReceivedPingResponse(LOW_RTT, "id"); - EXPECT_EQ_WAIT(conn2, ch.selected_connection(), kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.selected_connection(); }, Eq(conn2), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_TRUE(CandidatePairMatchesNetworkRoute(conn2)); EXPECT_TRUE( ConnectionMatchesChangeEvent(conn2, "candidate pair state changed")); @@ -4032,7 +4555,10 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { reset_channel_ready_to_send(); // The selected connection switches after conn4 becomes writable. conn4->ReceivedPingResponse(LOW_RTT, "id"); - EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.selected_connection(); }, Eq(conn4), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_TRUE(CandidatePairMatchesNetworkRoute(conn4)); EXPECT_TRUE( ConnectionMatchesChangeEvent(conn4, "candidate pair state changed")); @@ -4062,7 +4588,10 @@ TEST_F(P2PTransportChannelPingTest, TestPingOnNomination) { // A connection needs to be writable before it is selected for transmission. conn1->ReceivedPingResponse(LOW_RTT, "id"); - EXPECT_EQ_WAIT(conn1, ch.selected_connection(), kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.selected_connection(); }, Eq(conn1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_TRUE(CandidatePairMatchesNetworkRoute(conn1)); // When a higher priority candidate comes in, the new connection is chosen @@ -4072,7 +4601,10 @@ TEST_F(P2PTransportChannelPingTest, TestPingOnNomination) { Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); ASSERT_TRUE(conn2 != nullptr); conn2->ReceivedPingResponse(LOW_RTT, "id"); - EXPECT_EQ_WAIT(conn2, ch.selected_connection(), kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.selected_connection(); }, Eq(conn2), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_TRUE(CandidatePairMatchesNetworkRoute(conn2)); // Now nominate conn1 (low prio), it shall be choosen. @@ -4106,7 +4638,10 @@ TEST_F(P2PTransportChannelPingTest, TestPingOnSwitch) { // A connection needs to be writable before it is selected for transmission. conn1->ReceivedPingResponse(LOW_RTT, "id"); - EXPECT_EQ_WAIT(conn1, ch.selected_connection(), kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.selected_connection(); }, Eq(conn1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_TRUE(CandidatePairMatchesNetworkRoute(conn1)); // When a higher priority candidate comes in, the new connection is chosen @@ -4119,7 +4654,10 @@ TEST_F(P2PTransportChannelPingTest, TestPingOnSwitch) { const int before = conn2->num_pings_sent(); conn2->ReceivedPingResponse(LOW_RTT, "id"); - EXPECT_EQ_WAIT(conn2, ch.selected_connection(), kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.selected_connection(); }, Eq(conn2), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_TRUE(CandidatePairMatchesNetworkRoute(conn2)); // And the additional ping should have been sent directly. @@ -4149,7 +4687,10 @@ TEST_F(P2PTransportChannelPingTest, TestPingOnSelected) { // A connection needs to be writable before it is selected for transmission. conn1->ReceivedPingResponse(LOW_RTT, "id"); - EXPECT_EQ_WAIT(conn1, ch.selected_connection(), kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.selected_connection(); }, Eq(conn1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_TRUE(CandidatePairMatchesNetworkRoute(conn1)); // And the additional ping should have been sent directly. @@ -4184,7 +4725,10 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { EXPECT_EQ(conn1->stats().sent_ping_responses, 1u); EXPECT_NE(conn1, ch.selected_connection()); conn1->ReceivedPingResponse(LOW_RTT, "id"); - EXPECT_EQ_WAIT(conn1, ch.selected_connection(), kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.selected_connection(); }, Eq(conn1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Another connection is nominated via use_candidate. ch.AddRemoteCandidate( @@ -4222,7 +4766,10 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { // conn4 is not the selected connection yet because it is not writable. EXPECT_EQ(conn2, ch.selected_connection()); conn4->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. - EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.selected_connection(); }, Eq(conn4), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Test that the request from an unknown address contains a ufrag from an old // generation. @@ -4253,7 +4800,10 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); ASSERT_TRUE(conn1 != nullptr); conn1->ReceivedPingResponse(LOW_RTT, "id"); - EXPECT_EQ_WAIT(conn1, ch.selected_connection(), kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.selected_connection(); }, Eq(conn1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // If a data packet is received on conn2, the selected connection should // switch to conn2 because the controlled side must mirror the media path @@ -4285,7 +4835,10 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { ASSERT_TRUE(conn3 != nullptr); EXPECT_NE(conn3, ch.selected_connection()); // Not writable yet. conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. - EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.selected_connection(); }, Eq(conn3), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Now another data packet will not switch the selected connection because the // selected connection was nominated by the controlling side. @@ -4293,7 +4846,10 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { conn2->ReceivedPingResponse(LOW_RTT, "id"); conn2->OnReadPacket( rtc::ReceivedPacket::CreateFromLegacy("XYZ", 3, rtc::TimeMicros())); - EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.selected_connection(); }, Eq(conn3), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); } TEST_F(P2PTransportChannelPingTest, @@ -4412,8 +4968,11 @@ TEST_F(P2PTransportChannelPingTest, ASSERT_TRUE(conn2 != nullptr); // conn1 is the selected connection because it has a higher priority, - EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), kDefaultTimeout, - clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ch.selected_connection(); }, Eq(conn1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(CandidatePairMatchesNetworkRoute(conn1)); reset_selected_candidate_pair_switches(); @@ -4461,8 +5020,11 @@ TEST_F(P2PTransportChannelPingTest, TestEstimatedDisconnectedTime) { ASSERT_TRUE(conn2 != nullptr); // conn1 is the selected connection because it has a higher priority, - EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), kDefaultTimeout, - clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ch.selected_connection(); }, Eq(conn1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(CandidatePairMatchesNetworkRoute(conn1)); // No estimateded disconnect time at first connect <=> value is 0. EXPECT_EQ(LastEstimatedDisconnectedTimeMs(), 0); @@ -4544,18 +5106,32 @@ TEST_F(P2PTransportChannelPingTest, // conn2 becomes writable; it is selected even though it is not nominated. conn2->ReceivedPingResponse(LOW_RTT, "id"); - EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(), - kDefaultTimeout, clock); - EXPECT_EQ_SIMULATED_WAIT(conn2, ch.selected_connection(), kDefaultTimeout, - clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return reset_selected_candidate_pair_switches(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ch.selected_connection(); }, Eq(conn2), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(CandidatePairMatchesNetworkRoute(conn2)); // If conn1 is also writable, it will become selected. conn1->ReceivedPingResponse(LOW_RTT, "id"); - EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(), - kDefaultTimeout, clock); - EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), kDefaultTimeout, - clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return reset_selected_candidate_pair_switches(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ch.selected_connection(); }, Eq(conn1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(CandidatePairMatchesNetworkRoute(conn1)); // Make sure sorting won't reselect candidate pair. @@ -4628,11 +5204,19 @@ TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { ASSERT_TRUE(conn2 != nullptr); conn2->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving NominateConnection(conn2); - EXPECT_TRUE_SIMULATED_WAIT(conn1->pruned(), kMediumTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return conn1->pruned(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE)); // Wait until conn2 becomes not receiving. - EXPECT_TRUE_SIMULATED_WAIT(!conn2->receiving(), kMediumTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return !conn2->receiving(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); ch.AddRemoteCandidate( CreateUdpCandidate(IceCandidateType::kHost, "3.3.3.3", 3, 1)); @@ -4701,13 +5285,21 @@ TEST_F(P2PTransportChannelPingTest, TestGetState) { EXPECT_EQ(webrtc::IceTransportState::kChecking, ch.GetIceTransportState()); // `conn1` becomes writable and receiving; it then should prune `conn2`. conn1->ReceivedPingResponse(LOW_RTT, "id"); - EXPECT_TRUE_SIMULATED_WAIT(conn2->pruned(), kShortTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return conn2->pruned(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kShortTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_EQ(IceTransportState::STATE_COMPLETED, ch.GetState()); EXPECT_EQ(webrtc::IceTransportState::kConnected, ch.GetIceTransportState()); conn1->Prune(); // All connections are pruned. // Need to wait until the channel state is updated. - EXPECT_EQ_SIMULATED_WAIT(IceTransportState::STATE_FAILED, ch.GetState(), - kShortTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ch.GetState(); }, + Eq(IceTransportState::STATE_FAILED), + {.timeout = webrtc::TimeDelta::Millis(kShortTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_EQ(webrtc::IceTransportState::kFailed, ch.GetIceTransportState()); } @@ -4731,8 +5323,11 @@ TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { ASSERT_TRUE(conn1 != nullptr); EXPECT_EQ(nullptr, ch.selected_connection()); conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving - EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), kDefaultTimeout, - clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ch.selected_connection(); }, Eq(conn1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Add a low-priority connection `conn2`, which will be pruned, but it will // not be deleted right away. Once the current selected connection becomes not @@ -4742,27 +5337,49 @@ TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 1)); Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock); ASSERT_TRUE(conn2 != nullptr); - EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return !conn2->active(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // `conn2` should not send a ping yet. EXPECT_EQ(IceCandidatePairState::WAITING, conn2->state()); EXPECT_EQ(IceTransportState::STATE_COMPLETED, ch.GetState()); // Wait for `conn1` becoming not receiving. - EXPECT_TRUE_SIMULATED_WAIT(!conn1->receiving(), kMediumTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return !conn1->receiving(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Make sure conn2 is not deleted. conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock); ASSERT_TRUE(conn2 != nullptr); - EXPECT_EQ_SIMULATED_WAIT(IceCandidatePairState::IN_PROGRESS, conn2->state(), - kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return conn2->state(); }, + Eq(IceCandidatePairState::IN_PROGRESS), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); conn2->ReceivedPingResponse(LOW_RTT, "id"); - EXPECT_EQ_SIMULATED_WAIT(conn2, ch.selected_connection(), kDefaultTimeout, - clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ch.selected_connection(); }, Eq(conn2), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_EQ(IceTransportState::STATE_CONNECTING, ch.GetState()); // When `conn1` comes back again, `conn2` will be pruned again. conn1->ReceivedPingResponse(LOW_RTT, "id"); - EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), kDefaultTimeout, - clock); - EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ch.selected_connection(); }, Eq(conn1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); + EXPECT_THAT( + webrtc::WaitUntil([&] { return !conn2->active(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_EQ(IceTransportState::STATE_COMPLETED, ch.GetState()); } @@ -4782,7 +5399,11 @@ TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { ASSERT_TRUE(conn1 != nullptr); conn1->ReceivedPing(); // Becomes receiving conn1->Prune(); - EXPECT_TRUE_SIMULATED_WAIT(ch.connections().empty(), kShortTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ch.connections().empty(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kShortTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Have two connections but both become write-time-out later. ch.AddRemoteCandidate( @@ -4798,7 +5419,11 @@ TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { // Now prune both conn2 and conn3; they will be deleted soon. conn2->Prune(); conn3->Prune(); - EXPECT_TRUE_SIMULATED_WAIT(ch.connections().empty(), kShortTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ch.connections().empty(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kShortTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); } // Tests that after a port allocator session is started, it will be stopped @@ -4922,8 +5547,12 @@ TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeoutAndPruned) { // If the session prunes all ports, the port will be destroyed. ch.allocator_session()->PruneAllPorts(); - EXPECT_EQ_SIMULATED_WAIT(nullptr, GetPort(&ch), 1, fake_clock); - EXPECT_EQ_SIMULATED_WAIT(nullptr, GetPrunedPort(&ch), 1, fake_clock); + EXPECT_THAT(webrtc::WaitUntil([&] { return GetPort(&ch); }, Eq(nullptr), + {.clock = &fake_clock}), + webrtc::IsRtcOk()); + EXPECT_THAT(webrtc::WaitUntil([&] { return GetPrunedPort(&ch); }, Eq(nullptr), + {.clock = &fake_clock}), + webrtc::IsRtcOk()); } TEST_F(P2PTransportChannelPingTest, TestMaxOutstandingPingsFieldTrial) { @@ -4945,8 +5574,13 @@ TEST_F(P2PTransportChannelPingTest, TestMaxOutstandingPingsFieldTrial) { ASSERT_TRUE(conn1 != nullptr); ASSERT_TRUE(conn2 != nullptr); - EXPECT_TRUE_WAIT(conn1->num_pings_sent() == 3 && conn2->num_pings_sent() == 3, - kDefaultTimeout); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { + return conn1->num_pings_sent() == 3 && conn2->num_pings_sent() == 3; + }, + IsTrue(), {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Check that these connections don't send any more pings. EXPECT_EQ(nullptr, ch.FindNextPingableConnection()); @@ -4983,7 +5617,7 @@ class P2PTransportChannelMostLikelyToWorkFirstTest channel_->SetIceConfig(config); PrepareChannel(channel_.get()); channel_->MaybeStartGathering(); - return *channel_.get(); + return *channel_; } BasicPortAllocator* allocator() { return allocator_.get(); } @@ -5020,7 +5654,10 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, const int max_strong_interval = 500; P2PTransportChannel& ch = StartTransportChannel(true, max_strong_interval, &field_trials_); - EXPECT_TRUE_WAIT(ch.ports().size() == 2, kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.ports().size(); }, Eq(2), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_EQ(ch.ports()[0]->Type(), IceCandidateType::kHost); EXPECT_EQ(ch.ports()[1]->Type(), IceCandidateType::kRelay); @@ -5029,7 +5666,10 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, ch.AddRemoteCandidate( CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 2)); - EXPECT_TRUE_WAIT(ch.connections().size() == 4, kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.connections().size(); }, Eq(4), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Relay/Relay should be the first pingable connection. Connection* conn = FindNextPingableConnectionAndPingIt(&ch); @@ -5081,13 +5721,19 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, TestRelayRelayFirstWhenEverythingPinged) { P2PTransportChannel& ch = StartTransportChannel(true, 500, &field_trials_); - EXPECT_TRUE_WAIT(ch.ports().size() == 2, kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.ports().size(); }, Eq(2), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_EQ(ch.ports()[0]->Type(), IceCandidateType::kHost); EXPECT_EQ(ch.ports()[1]->Type(), IceCandidateType::kRelay); ch.AddRemoteCandidate( CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 1)); - EXPECT_TRUE_WAIT(ch.connections().size() == 2, kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.connections().size(); }, Eq(2), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Initially, only have Local/Local and Local/Relay. VerifyNextPingableConnection(IceCandidateType::kHost, @@ -5098,7 +5744,10 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, // Remote Relay candidate arrives. ch.AddRemoteCandidate( CreateUdpCandidate(IceCandidateType::kRelay, "2.2.2.2", 2, 2)); - EXPECT_TRUE_WAIT(ch.connections().size() == 4, kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.connections().size(); }, Eq(4), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Relay/Relay should be the first since it hasn't been pinged before. VerifyNextPingableConnection(IceCandidateType::kRelay, @@ -5119,13 +5768,19 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, TestNoStarvationOnNonRelayConnection) { P2PTransportChannel& ch = StartTransportChannel(true, 500, &field_trials_); - EXPECT_TRUE_WAIT(ch.ports().size() == 2, kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.ports().size(); }, Eq(2), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_EQ(ch.ports()[0]->Type(), IceCandidateType::kHost); EXPECT_EQ(ch.ports()[1]->Type(), IceCandidateType::kRelay); ch.AddRemoteCandidate( CreateUdpCandidate(IceCandidateType::kRelay, "1.1.1.1", 1, 1)); - EXPECT_TRUE_WAIT(ch.connections().size() == 2, kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.connections().size(); }, Eq(2), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Initially, only have Relay/Relay and Local/Relay. Ping Relay/Relay first. VerifyNextPingableConnection(IceCandidateType::kRelay, @@ -5138,7 +5793,10 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, // Remote Local candidate arrives. ch.AddRemoteCandidate( CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 2)); - EXPECT_TRUE_WAIT(ch.connections().size() == 4, kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.connections().size(); }, Eq(4), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Local/Local should be the first since it hasn't been pinged before. VerifyNextPingableConnection(IceCandidateType::kHost, @@ -5162,19 +5820,28 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, field_trials_, "WebRTC-IceFieldTrials/skip_relay_to_non_relay_connections:true/"); P2PTransportChannel& ch = StartTransportChannel(true, 500, &field_trials); - EXPECT_TRUE_WAIT(ch.ports().size() == 2, kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.ports().size(); }, Eq(2), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_EQ(ch.ports()[0]->Type(), IceCandidateType::kHost); EXPECT_EQ(ch.ports()[1]->Type(), IceCandidateType::kRelay); // Remote Relay candidate arrives. ch.AddRemoteCandidate( CreateUdpCandidate(IceCandidateType::kRelay, "1.1.1.1", 1, 1)); - EXPECT_TRUE_WAIT(ch.connections().size() == 1, kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.connections().size(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Remote Local candidate arrives. ch.AddRemoteCandidate( CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 2)); - EXPECT_TRUE_WAIT(ch.connections().size() == 2, kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.connections().size(); }, Eq(2), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); } // Test the ping sequence is UDP Relay/Relay followed by TCP Relay/Relay, @@ -5188,7 +5855,10 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, TestTcpTurn) { allocator()->AddTurnServerForTesting(config); P2PTransportChannel& ch = StartTransportChannel(true, 500, &field_trials_); - EXPECT_TRUE_WAIT(ch.ports().size() == 3, kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.ports().size(); }, Eq(3), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_EQ(ch.ports()[0]->Type(), IceCandidateType::kHost); EXPECT_EQ(ch.ports()[1]->Type(), IceCandidateType::kRelay); EXPECT_EQ(ch.ports()[2]->Type(), IceCandidateType::kRelay); @@ -5196,7 +5866,10 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, TestTcpTurn) { // Remote Relay candidate arrives. ch.AddRemoteCandidate( CreateUdpCandidate(IceCandidateType::kRelay, "1.1.1.1", 1, 1)); - EXPECT_TRUE_WAIT(ch.connections().size() == 3, kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch.connections().size(); }, Eq(3), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // UDP Relay/Relay should be pinged first. VerifyNextPingableConnection(IceCandidateType::kRelay, @@ -5233,7 +5906,10 @@ TEST(P2PTransportChannelResolverTest, HostnameCandidateIsResolved) { hostname_candidate.set_address(hostname_address); channel->AddRemoteCandidate(hostname_candidate); - ASSERT_EQ_WAIT(1u, channel->remote_candidates().size(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return channel->remote_candidates().size(); }, Eq(1u), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); const RemoteCandidate& candidate = channel->remote_candidates()[0]; EXPECT_FALSE(candidate.address().IsUnresolvedIP()); } @@ -5259,7 +5935,11 @@ TEST_F(P2PTransportChannelTest, // number is assgined to ep1's host candidate. PauseCandidates(0); PauseCandidates(1); - ASSERT_EQ_WAIT(1u, GetEndpoint(0)->saved_candidates_.size(), kMediumTimeout); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return GetEndpoint(0)->saved_candidates_.size(); }, Eq(1u), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); const auto& local_candidate = GetEndpoint(0)->saved_candidates_[0].candidate; // The IP address of ep1's host candidate should be obfuscated. EXPECT_TRUE(local_candidate.address().IsUnresolvedIP()); @@ -5271,13 +5951,20 @@ TEST_F(P2PTransportChannelTest, // pair and start to ping. After receiving the ping, ep2 discovers a prflx // remote candidate and form a candidate pair as well. ResumeCandidates(1); - ASSERT_TRUE_WAIT(ep1_ch1()->selected_connection() != nullptr, kMediumTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ep1_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); // ep2 should have the selected connection connected to the prflx remote // candidate. const Connection* selected_connection = nullptr; - ASSERT_TRUE_WAIT( - (selected_connection = ep2_ch1()->selected_connection()) != nullptr, - kMediumTimeout); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { + return selected_connection = ep2_ch1()->selected_connection(); + }, + Ne(nullptr), {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); EXPECT_TRUE(selected_connection->remote_candidate().is_prflx()); EXPECT_EQ(kIceUfrag[0], selected_connection->remote_candidate().username()); EXPECT_EQ(kIcePwd[0], selected_connection->remote_candidate().password()); @@ -5285,9 +5972,16 @@ TEST_F(P2PTransportChannelTest, resolver_fixture.SetAddressToReturn(local_address); ResumeCandidates(0); // Verify ep2's selected connection is updated to use the 'local' candidate. - EXPECT_TRUE_WAIT( - ep2_ch1()->selected_connection()->remote_candidate().is_local(), - kMediumTimeout); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { + return ep2_ch1() + ->selected_connection() + ->remote_candidate() + .is_local(); + }, + IsTrue(), {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); EXPECT_EQ(selected_connection, ep2_ch1()->selected_connection()); DestroyChannels(); @@ -5317,7 +6011,11 @@ TEST_F(P2PTransportChannelTest, PauseCandidates(0); PauseCandidates(1); - ASSERT_EQ_WAIT(1u, GetEndpoint(0)->saved_candidates_.size(), kMediumTimeout); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return GetEndpoint(0)->saved_candidates_.size(); }, Eq(1u), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); const auto& local_candidate = GetEndpoint(0)->saved_candidates_[0].candidate; // The IP address of ep1's host candidate should be obfuscated. ASSERT_TRUE(local_candidate.address().IsUnresolvedIP()); @@ -5330,7 +6028,10 @@ TEST_F(P2PTransportChannelTest, // by ep1. Let ep2 signal its host candidate with an IP address to ep1, so // that ep1 can form a candidate pair, select it and start to ping ep2. ResumeCandidates(1); - ASSERT_TRUE_WAIT(ep1_ch1()->selected_connection() != nullptr, kMediumTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ep1_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); // Let the mock resolver of ep2 receives the correct resolution. resolver_fixture.SetAddressToReturn(local_address); @@ -5339,16 +6040,26 @@ TEST_F(P2PTransportChannelTest, // // There is a caveat in our implementation associated with this expectation. // See the big comment in P2PTransportChannel::OnUnknownAddress. - ASSERT_TRUE_WAIT(ep2_ch1()->selected_connection() != nullptr, kMediumTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ep2_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); EXPECT_TRUE(ep2_ch1()->selected_connection()->remote_candidate().is_prflx()); // ep2 should also be able resolve the hostname candidate. The resolved remote // host candidate should be merged with the prflx remote candidate. resolver_fixture.FireDelayedResolution(); - EXPECT_TRUE_WAIT( - ep2_ch1()->selected_connection()->remote_candidate().is_local(), - kMediumTimeout); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { + return ep2_ch1() + ->selected_connection() + ->remote_candidate() + .is_local(); + }, + IsTrue(), {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); EXPECT_EQ(1u, ep2_ch1()->remote_candidates().size()); DestroyChannels(); @@ -5373,7 +6084,11 @@ TEST_F(P2PTransportChannelTest, CanConnectWithHostCandidateWithMdnsName) { // number is assgined to ep1's host candidate. PauseCandidates(0); PauseCandidates(1); - ASSERT_EQ_WAIT(1u, GetEndpoint(0)->saved_candidates_.size(), kMediumTimeout); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return GetEndpoint(0)->saved_candidates_.size(); }, Eq(1u), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); const auto& local_candidate_ep1 = GetEndpoint(0)->saved_candidates_[0].candidate; // The IP address of ep1's host candidate should be obfuscated. @@ -5389,8 +6104,10 @@ TEST_F(P2PTransportChannelTest, CanConnectWithHostCandidateWithMdnsName) { // We should be able to receive a ping from ep2 and establish a connection // with a peer reflexive candidate from ep2. - ASSERT_TRUE_WAIT((ep1_ch1()->selected_connection()) != nullptr, - kMediumTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ep1_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); EXPECT_TRUE(ep1_ch1()->selected_connection()->local_candidate().is_local()); EXPECT_TRUE(ep1_ch1()->selected_connection()->remote_candidate().is_prflx()); @@ -5424,8 +6141,16 @@ TEST_F(P2PTransportChannelTest, PauseCandidates(0); PauseCandidates(1); // Ep1 has a UDP host, a srflx and a relay candidates. - ASSERT_EQ_WAIT(3u, GetEndpoint(0)->saved_candidates_.size(), kMediumTimeout); - ASSERT_EQ_WAIT(1u, GetEndpoint(1)->saved_candidates_.size(), kMediumTimeout); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return GetEndpoint(0)->saved_candidates_.size(); }, Eq(3u), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return GetEndpoint(1)->saved_candidates_.size(); }, Eq(1u), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); for (const auto& candidates_data : GetEndpoint(0)->saved_candidates_) { const auto& local_candidate_ep1 = candidates_data.candidate; @@ -5441,12 +6166,21 @@ TEST_F(P2PTransportChannelTest, ResumeCandidates(0); ResumeCandidates(1); - ASSERT_EQ_WAIT(kIceGatheringComplete, ep1_ch1()->gathering_state(), - kMediumTimeout); + ASSERT_THAT( + webrtc::WaitUntil([&] { return ep1_ch1()->gathering_state(); }, + Eq(kIceGatheringComplete), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); // We should have the following candidate pairs on both endpoints: // ep1_host <-> ep2_host, ep1_srflx <-> ep2_host, ep1_relay <-> ep2_host - ASSERT_EQ_WAIT(3u, ep1_ch1()->connections().size(), kMediumTimeout); - ASSERT_EQ_WAIT(3u, ep2_ch1()->connections().size(), kMediumTimeout); + ASSERT_THAT( + webrtc::WaitUntil([&] { return ep1_ch1()->connections().size(); }, Eq(3u), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); + ASSERT_THAT( + webrtc::WaitUntil([&] { return ep2_ch1()->connections().size(); }, Eq(3u), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); IceTransportStats ice_transport_stats1; IceTransportStats ice_transport_stats2; @@ -5501,8 +6235,11 @@ TEST_F(P2PTransportChannelTest, EXPECT_EQ(0u, ice_transport_stats.selected_candidate_pair_changes); // Let the channels connect. - EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection() != nullptr, - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ep1_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); ASSERT_TRUE(ep1_ch1()->GetStats(&ice_transport_stats)); EXPECT_EQ(1u, ice_transport_stats.selected_candidate_pair_changes); @@ -5522,8 +6259,11 @@ TEST_F(P2PTransportChannelTest, EXPECT_EQ(0u, ice_transport_stats.selected_candidate_pair_changes); // Let the channels connect. - EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection() != nullptr, - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ep1_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); ASSERT_TRUE(ep1_ch1()->GetStats(&ice_transport_stats)); EXPECT_EQ(1u, ice_transport_stats.selected_candidate_pair_changes); @@ -5532,8 +6272,11 @@ TEST_F(P2PTransportChannelTest, for (Connection* con : ep1_ch1()->connections()) { con->Prune(); } - EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection() == nullptr, - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ep1_ch1()->selected_connection(); }, Eq(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); ASSERT_TRUE(ep1_ch1()->GetStats(&ice_transport_stats)); EXPECT_EQ(2u, ice_transport_stats.selected_candidate_pair_changes); @@ -5553,8 +6296,11 @@ TEST_F(P2PTransportChannelTest, EXPECT_EQ(0u, ice_transport_stats.selected_candidate_pair_changes); // Let the channels connect. - EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection() != nullptr, - kMediumTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ep1_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); ASSERT_TRUE(ep1_ch1()->GetStats(&ice_transport_stats)); EXPECT_EQ(1u, ice_transport_stats.selected_candidate_pair_changes); @@ -5567,11 +6313,17 @@ TEST_F(P2PTransportChannelTest, con->Prune(); } } - EXPECT_TRUE_SIMULATED_WAIT( - ep1_ch1()->selected_connection() != nullptr && - (ep1_ch1()->GetStats(&ice_transport_stats), - ice_transport_stats.selected_candidate_pair_changes >= 2u), - kMediumTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { + return ep1_ch1()->selected_connection() != nullptr && + (ep1_ch1()->GetStats(&ice_transport_stats), + ice_transport_stats.selected_candidate_pair_changes >= 2u); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); ASSERT_TRUE(ep1_ch1()->GetStats(&ice_transport_stats)); EXPECT_GE(ice_transport_stats.selected_candidate_pair_changes, 2u); @@ -5598,7 +6350,11 @@ TEST_F(P2PTransportChannelTest, // number is assigned to ep1's host candidate. PauseCandidates(0); PauseCandidates(1); - ASSERT_EQ_WAIT(1u, GetEndpoint(0)->saved_candidates_.size(), kMediumTimeout); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return GetEndpoint(0)->saved_candidates_.size(); }, Eq(1u), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); const auto& candidates_data = GetEndpoint(0)->saved_candidates_[0]; const auto& local_candidate_ep1 = candidates_data.candidate; ASSERT_TRUE(local_candidate_ep1.is_local()); @@ -5611,9 +6367,14 @@ TEST_F(P2PTransportChannelTest, ResumeCandidates(0); ResumeCandidates(1); - ASSERT_TRUE_WAIT(ep1_ch1()->selected_connection() != nullptr && - ep2_ch1()->selected_connection() != nullptr, - kMediumTimeout); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { + return ep1_ch1()->selected_connection() != nullptr && + ep2_ch1()->selected_connection() != nullptr; + }, + IsTrue(), {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); const auto pair_ep1 = ep1_ch1()->GetSelectedCandidatePair(); ASSERT_TRUE(pair_ep1.has_value()); @@ -5642,8 +6403,11 @@ TEST_F(P2PTransportChannelTest, // Start gathering and we should have only a single relay port. ep1_ch1()->SetIceConfig(config); ep1_ch1()->MaybeStartGathering(); - EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete, - ep1_ch1()->gathering_state(), kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ep1_ch1()->gathering_state(); }, + Eq(IceGatheringState::kIceGatheringComplete), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_EQ(1u, ep1_ch1()->ports().size()); // Add a plain remote host candidate and three remote mDNS candidates with the // host, srflx and relay types. Note that the candidates differ in their @@ -5723,8 +6487,10 @@ TEST_F(P2PTransportChannelTest, CreateChannels(); // We should be able to form a srflx-host connection to ep2. - ASSERT_TRUE_WAIT((ep1_ch1()->selected_connection()) != nullptr, - kMediumTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ep1_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); EXPECT_TRUE(ep1_ch1()->selected_connection()->local_candidate().is_stun()); EXPECT_TRUE(ep1_ch1()->selected_connection()->remote_candidate().is_local()); @@ -5753,27 +6519,49 @@ TEST_F(P2PTransportChannelTest, IceConfig ice_config = CreateIceConfig(1000, GATHER_CONTINUALLY); ice_config.surface_ice_candidates_on_ice_transport_type_changed = true; CreateChannels(ice_config, ice_config); - ASSERT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection() != nullptr, - kDefaultTimeout, clock); - ASSERT_TRUE_SIMULATED_WAIT(ep2_ch1()->selected_connection() != nullptr, - kDefaultTimeout, clock); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ep1_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ep2_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(ep1_ch1()->selected_connection()->local_candidate().is_relay()); EXPECT_TRUE(ep2_ch1()->selected_connection()->local_candidate().is_relay()); // Loosen the candidate filter at ep1. ep1->allocator_->SetCandidateFilter(CF_ALL); - EXPECT_TRUE_SIMULATED_WAIT( - ep1_ch1()->selected_connection() != nullptr && - ep1_ch1()->selected_connection()->local_candidate().is_local(), - kDefaultTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return ep1_ch1()->selected_connection() != nullptr && + ep1_ch1() + ->selected_connection() + ->local_candidate() + .is_local(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(ep1_ch1()->selected_connection()->remote_candidate().is_relay()); // Loosen the candidate filter at ep2. ep2->allocator_->SetCandidateFilter(CF_ALL); - EXPECT_TRUE_SIMULATED_WAIT( - ep2_ch1()->selected_connection() != nullptr && - ep2_ch1()->selected_connection()->local_candidate().is_local(), - kDefaultTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return ep2_ch1()->selected_connection() != nullptr && + ep2_ch1() + ->selected_connection() + ->local_candidate() + .is_local(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // We have migrated to a host-host candidate pair. EXPECT_TRUE(ep2_ch1()->selected_connection()->remote_candidate().is_local()); @@ -5784,9 +6572,17 @@ TEST_F(P2PTransportChannelTest, fw()->AddRule(false, rtc::FP_ANY, kPublicAddrs[1], kTurnUdpExtAddr); // We should be able to reuse the previously gathered relay candidates. - EXPECT_TRUE_SIMULATED_WAIT( - ep1_ch1()->selected_connection()->local_candidate().is_relay(), - kDefaultTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return ep1_ch1() + ->selected_connection() + ->local_candidate() + .is_relay(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(ep1_ch1()->selected_connection()->remote_candidate().is_relay()); DestroyChannels(); } @@ -5817,25 +6613,47 @@ TEST_F(P2PTransportChannelTest, IceConfig ice_config = CreateIceConfig(1000, GATHER_CONTINUALLY); ice_config.surface_ice_candidates_on_ice_transport_type_changed = true; CreateChannels(ice_config, ice_config); - ASSERT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection() != nullptr, - kDefaultTimeout, clock); - ASSERT_TRUE_SIMULATED_WAIT(ep2_ch1()->selected_connection() != nullptr, - kDefaultTimeout, clock); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ep1_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ep2_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); const uint32_t kCandidateFilterNoHost = CF_ALL & ~CF_HOST; // Loosen the candidate filter at ep1. ep1->allocator_->SetCandidateFilter(kCandidateFilterNoHost); - EXPECT_TRUE_SIMULATED_WAIT( - ep1_ch1()->selected_connection() != nullptr && - ep1_ch1()->selected_connection()->local_candidate().is_stun(), - kDefaultTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return ep1_ch1()->selected_connection() != nullptr && + ep1_ch1() + ->selected_connection() + ->local_candidate() + .is_stun(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(ep1_ch1()->selected_connection()->remote_candidate().is_relay()); // Loosen the candidate filter at ep2. ep2->allocator_->SetCandidateFilter(kCandidateFilterNoHost); - EXPECT_TRUE_SIMULATED_WAIT( - ep2_ch1()->selected_connection() != nullptr && - ep2_ch1()->selected_connection()->local_candidate().is_stun(), - kDefaultTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return ep2_ch1()->selected_connection() != nullptr && + ep2_ch1() + ->selected_connection() + ->local_candidate() + .is_stun(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // We have migrated to a srflx-srflx candidate pair. EXPECT_TRUE(ep2_ch1()->selected_connection()->remote_candidate().is_stun()); @@ -5845,9 +6663,17 @@ TEST_F(P2PTransportChannelTest, fw()->AddRule(false, rtc::FP_ANY, kPrivateAddrs[0], kTurnUdpExtAddr); fw()->AddRule(false, rtc::FP_ANY, kPrivateAddrs[1], kTurnUdpExtAddr); // We should be able to reuse the previously gathered relay candidates. - EXPECT_TRUE_SIMULATED_WAIT( - ep1_ch1()->selected_connection()->local_candidate().is_relay(), - kDefaultTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return ep1_ch1() + ->selected_connection() + ->local_candidate() + .is_relay(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(ep1_ch1()->selected_connection()->remote_candidate().is_relay()); DestroyChannels(); } @@ -5873,10 +6699,16 @@ TEST_F(P2PTransportChannelTest, IceConfig ice_config = CreateIceConfig(1000, GATHER_ONCE); ice_config.surface_ice_candidates_on_ice_transport_type_changed = true; CreateChannels(ice_config, ice_config); - ASSERT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection() != nullptr, - kDefaultTimeout, clock); - ASSERT_TRUE_SIMULATED_WAIT(ep2_ch1()->selected_connection() != nullptr, - kDefaultTimeout, clock); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ep1_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ep2_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Loosen the candidate filter at ep1. ep1->allocator_->SetCandidateFilter(CF_ALL); // Wait for a period for any potential surfacing of new candidates. @@ -5916,18 +6748,35 @@ TEST_F(P2PTransportChannelTest, CreateChannels(ice_config, ice_config); // We have gathered host, srflx and relay candidates. - EXPECT_TRUE_SIMULATED_WAIT(ep1->saved_candidates_.size() == 3u, - kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ep1->saved_candidates_.size(); }, Eq(3u), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); ResumeCandidates(0); ResumeCandidates(1); - ASSERT_TRUE_SIMULATED_WAIT( - ep1_ch1()->selected_connection() != nullptr && - ep1_ch1()->selected_connection()->local_candidate().is_local() && - ep2_ch1()->selected_connection() != nullptr && - ep1_ch1()->selected_connection()->remote_candidate().is_local(), - kDefaultTimeout, clock); - ASSERT_TRUE_SIMULATED_WAIT(ep2_ch1()->selected_connection() != nullptr, - kDefaultTimeout, clock); + ASSERT_THAT(webrtc::WaitUntil( + [&] { + return ep1_ch1()->selected_connection() != nullptr && + ep1_ch1() + ->selected_connection() + ->local_candidate() + .is_local() && + ep2_ch1()->selected_connection() != nullptr && + ep1_ch1() + ->selected_connection() + ->remote_candidate() + .is_local(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ep2_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Test that we have a host-host candidate pair selected and the number of // candidates signaled to the remote peer stays the same. auto test_invariants = [this]() { @@ -5987,21 +6836,41 @@ TEST_F(P2PTransportChannelTest, SurfaceRequiresCoordination) { // On the caller we only have relay, // on the callee we have host, srflx and relay. - EXPECT_TRUE_SIMULATED_WAIT(ep1->saved_candidates_.size() == 1u, - kDefaultTimeout, clock); - EXPECT_TRUE_SIMULATED_WAIT(ep2->saved_candidates_.size() == 3u, - kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ep1->saved_candidates_.size(); }, Eq(1u), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ep2->saved_candidates_.size(); }, Eq(3u), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); ResumeCandidates(0); ResumeCandidates(1); - ASSERT_TRUE_SIMULATED_WAIT( - ep1_ch1()->selected_connection() != nullptr && - ep1_ch1()->selected_connection()->local_candidate().is_relay() && - ep2_ch1()->selected_connection() != nullptr && - ep1_ch1()->selected_connection()->remote_candidate().is_relay(), - kDefaultTimeout, clock); - ASSERT_TRUE_SIMULATED_WAIT(ep2_ch1()->selected_connection() != nullptr, - kDefaultTimeout, clock); + ASSERT_THAT(webrtc::WaitUntil( + [&] { + return ep1_ch1()->selected_connection() != nullptr && + ep1_ch1() + ->selected_connection() + ->local_candidate() + .is_relay() && + ep2_ch1()->selected_connection() != nullptr && + ep1_ch1() + ->selected_connection() + ->remote_candidate() + .is_relay(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ep2_ch1()->selected_connection(); }, Ne(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Wait until the callee discards it's candidates // since they don't manage to connect. @@ -6044,7 +6913,11 @@ TEST_F(P2PTransportChannelPingTest, TestInitialSelectDampening0) { conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving // It shall not be selected until 0ms has passed....i.e it should be connected // directly. - EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), kMargin, clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return ch.selected_connection(); }, Eq(conn1), + {.timeout = webrtc::TimeDelta::Millis(kMargin), .clock = &clock}), + webrtc::IsRtcOk()); } TEST_F(P2PTransportChannelPingTest, TestInitialSelectDampening) { @@ -6070,7 +6943,11 @@ TEST_F(P2PTransportChannelPingTest, TestInitialSelectDampening) { conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving // It shall not be selected until 100ms has passed. SIMULATED_WAIT(conn1 == ch.selected_connection(), 100 - kMargin, clock); - EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), 2 * kMargin, clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return ch.selected_connection(); }, Eq(conn1), + {.timeout = webrtc::TimeDelta::Millis(2 * kMargin), .clock = &clock}), + webrtc::IsRtcOk()); } TEST_F(P2PTransportChannelPingTest, TestInitialSelectDampeningPingReceived) { @@ -6098,7 +6975,11 @@ TEST_F(P2PTransportChannelPingTest, TestInitialSelectDampeningPingReceived) { conn1->ReceivedPing("id1"); // // It shall not be selected until 100ms has passed. SIMULATED_WAIT(conn1 == ch.selected_connection(), 100 - kMargin, clock); - EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), 2 * kMargin, clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return ch.selected_connection(); }, Eq(conn1), + {.timeout = webrtc::TimeDelta::Millis(2 * kMargin), .clock = &clock}), + webrtc::IsRtcOk()); } TEST_F(P2PTransportChannelPingTest, TestInitialSelectDampeningBoth) { @@ -6129,7 +7010,11 @@ TEST_F(P2PTransportChannelPingTest, TestInitialSelectDampeningBoth) { SIMULATED_WAIT(conn1 == ch.selected_connection(), 50 - kMargin, clock); // Now receiving ping and new timeout should kick in. conn1->ReceivedPing("id1"); // - EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), 2 * kMargin, clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return ch.selected_connection(); }, Eq(conn1), + {.timeout = webrtc::TimeDelta::Millis(2 * kMargin), .clock = &clock}), + webrtc::IsRtcOk()); } TEST(P2PTransportChannelIceControllerTest, InjectIceController) { @@ -6236,7 +7121,10 @@ TEST_F(P2PTransportChannelPingTest, TestForgetLearnedState) { // Wait for conn1 to be selected. conn1->ReceivedPingResponse(LOW_RTT, "id"); - EXPECT_EQ_WAIT(conn1, ch->selected_connection(), kMediumTimeout); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ch->selected_connection(); }, Eq(conn1), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); conn2->ReceivedPingResponse(LOW_RTT, "id"); EXPECT_TRUE(conn2->writable()); @@ -6248,7 +7136,10 @@ TEST_F(P2PTransportChannelPingTest, TestForgetLearnedState) { // We don't have a mock Connection, so verify this by checking that it // is no longer writable. - EXPECT_EQ_WAIT(false, conn2->writable(), kMediumTimeout); + EXPECT_THAT( + webrtc::WaitUntil([&] { return conn2->writable(); }, IsFalse(), + {.timeout = webrtc::TimeDelta::Millis(kMediumTimeout)}), + webrtc::IsRtcOk()); } TEST_F(P2PTransportChannelTest, DisableDnsLookupsWithTransportPolicyRelay) { @@ -6367,9 +7258,15 @@ TEST_P(GatherAfterConnectedTest, GatherAfterConnected) { PauseCandidates(1); // We have gathered host candidates but not relay. - ASSERT_TRUE_SIMULATED_WAIT(ep1->saved_candidates_.size() == 1u && - ep2->saved_candidates_.size() == 1u, - kDefaultTimeout, clock); + ASSERT_THAT(webrtc::WaitUntil( + [&] { + return ep1->saved_candidates_.size() == 1u && + ep2->saved_candidates_.size() == 1u; + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); ResumeCandidates(0); ResumeCandidates(1); @@ -6377,13 +7274,25 @@ TEST_P(GatherAfterConnectedTest, GatherAfterConnected) { PauseCandidates(0); PauseCandidates(1); - ASSERT_TRUE_SIMULATED_WAIT(ep1_ch1()->remote_candidates().size() == 1 && - ep2_ch1()->remote_candidates().size() == 1, - kDefaultTimeout, clock); + ASSERT_THAT(webrtc::WaitUntil( + [&] { + return ep1_ch1()->remote_candidates().size() == 1 && + ep2_ch1()->remote_candidates().size() == 1; + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); - ASSERT_TRUE_SIMULATED_WAIT( - ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection(), - kDefaultTimeout, clock); + ASSERT_THAT(webrtc::WaitUntil( + [&] { + return ep1_ch1()->selected_connection() && + ep2_ch1()->selected_connection(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); clock.AdvanceTime(webrtc::TimeDelta::Millis(10 * delay)); @@ -6429,9 +7338,15 @@ TEST_P(GatherAfterConnectedTest, GatherAfterConnectedMultiHomed) { PauseCandidates(1); // We have gathered host candidates but not relay. - ASSERT_TRUE_SIMULATED_WAIT(ep1->saved_candidates_.size() == 2u && - ep2->saved_candidates_.size() == 1u, - kDefaultTimeout, clock); + ASSERT_THAT(webrtc::WaitUntil( + [&] { + return ep1->saved_candidates_.size() == 2u && + ep2->saved_candidates_.size() == 1u; + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); ResumeCandidates(0); ResumeCandidates(1); @@ -6439,13 +7354,25 @@ TEST_P(GatherAfterConnectedTest, GatherAfterConnectedMultiHomed) { PauseCandidates(0); PauseCandidates(1); - ASSERT_TRUE_SIMULATED_WAIT(ep1_ch1()->remote_candidates().size() == 1 && - ep2_ch1()->remote_candidates().size() == 2, - kDefaultTimeout, clock); + ASSERT_THAT(webrtc::WaitUntil( + [&] { + return ep1_ch1()->remote_candidates().size() == 1 && + ep2_ch1()->remote_candidates().size() == 2; + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); - ASSERT_TRUE_SIMULATED_WAIT( - ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection(), - kDefaultTimeout, clock); + ASSERT_THAT(webrtc::WaitUntil( + [&] { + return ep1_ch1()->selected_connection() && + ep2_ch1()->selected_connection(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); clock.AdvanceTime(webrtc::TimeDelta::Millis(10 * delay)); @@ -6472,16 +7399,24 @@ TEST_F(P2PTransportChannelTest, TestIceNoOldCandidatesAfterIceRestart) { IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY); CreateChannels(config, config); - EXPECT_TRUE_SIMULATED_WAIT(CheckConnected(ep1_ch1(), ep2_ch1()), - kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); PauseCandidates(0); ep1_ch1()->SetIceParameters(kIceParams[3]); ep1_ch1()->MaybeStartGathering(); - EXPECT_TRUE_SIMULATED_WAIT(GetEndpoint(0)->saved_candidates_.size() > 0, - kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return GetEndpoint(0)->saved_candidates_.size(); }, Gt(0), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); for (const auto& cd : GetEndpoint(0)->saved_candidates_) { EXPECT_EQ(cd.candidate.username(), kIceUfrag[3]); diff --git a/p2p/base/port_unittest.cc b/p2p/base/port_unittest.cc index 4238757e80..14786ba545 100644 --- a/p2p/base/port_unittest.cc +++ b/p2p/base/port_unittest.cc @@ -12,6 +12,7 @@ #include +#include #include #include #include @@ -24,12 +25,17 @@ #include "absl/memory/memory.h" #include "absl/strings/string_view.h" #include "api/array_view.h" +#include "api/async_dns_resolver.h" #include "api/candidate.h" #include "api/packet_socket_factory.h" +#include "api/rtc_error.h" +#include "api/test/rtc_error_matchers.h" #include "api/transport/stun.h" #include "api/units/time_delta.h" #include "p2p/base/basic_packet_socket_factory.h" +#include "p2p/base/connection.h" #include "p2p/base/p2p_constants.h" +#include "p2p/base/p2p_transport_channel_ice_field_trials.h" #include "p2p/base/port_allocator.h" #include "p2p/base/port_interface.h" #include "p2p/base/stun_port.h" @@ -66,8 +72,10 @@ #include "rtc_base/thread.h" #include "rtc_base/time_utils.h" #include "rtc_base/virtual_socket_server.h" +#include "test/gmock.h" #include "test/gtest.h" #include "test/scoped_key_value_config.h" +#include "test/wait_until.h" using rtc::AsyncListenSocket; using rtc::AsyncPacketSocket; @@ -81,6 +89,10 @@ using rtc::NATType; using rtc::PacketSocketFactory; using rtc::Socket; using rtc::SocketAddress; +using ::testing::Eq; +using ::testing::IsNull; +using ::testing::IsTrue; +using ::testing::NotNull; using webrtc::IceCandidateType; namespace cricket { @@ -259,13 +271,19 @@ static void SendPingAndReceiveResponse(Connection* lconn, rtc::ScopedFakeClock* clock, int64_t ms) { lconn->Ping(rtc::TimeMillis()); - ASSERT_TRUE_WAIT(lport->last_stun_msg(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return lport->last_stun_msg(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); ASSERT_GT(lport->last_stun_buf().size(), 0u); rconn->OnReadPacket(rtc::ReceivedPacket(lport->last_stun_buf(), rtc::SocketAddress(), std::nullopt)); clock->AdvanceTime(webrtc::TimeDelta::Millis(ms)); - ASSERT_TRUE_WAIT(rport->last_stun_msg(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return rport->last_stun_msg(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); ASSERT_GT(rport->last_stun_buf().size(), 0u); lconn->OnReadPacket(rtc::ReceivedPacket(rport->last_stun_buf(), rtc::SocketAddress(), std::nullopt)); @@ -286,7 +304,7 @@ class TestChannel : public sigslot::has_slots<> { int complete_count() { return complete_count_; } Connection* conn() { return conn_; } const SocketAddress& remote_address() { return remote_address_; } - const std::string remote_fragment() { return remote_frag_; } + std::string remote_fragment() { return remote_frag_; } void Start() { port_->PrepareAddress(); } void CreateConnection(const Candidate& remote_candidate) { @@ -684,16 +702,21 @@ class PortTest : public ::testing::Test, public sigslot::has_slots<> { // TCP reconnecting mechanism before entering this function. void ConnectStartedChannels(TestChannel* ch1, TestChannel* ch2) { ASSERT_TRUE(ch1->conn()); - EXPECT_TRUE_WAIT(ch1->conn()->connected(), - kDefaultTimeout); // for TCP connect + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch1->conn()->connected(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // for TCP connect ch1->Ping(); WAIT(!ch2->remote_address().IsNil(), kShortTimeout); // Send a ping from dst to src. ch2->AcceptConnection(GetCandidate(ch1->port())); ch2->Ping(); - EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch2->conn()->write_state(), - kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch2->conn()->write_state(); }, + Eq(Connection::STATE_WRITABLE), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); } // This connects and disconnects the provided channels in the same sequence as @@ -722,8 +745,14 @@ class PortTest : public ::testing::Test, public sigslot::has_slots<> { tcp_conn2->socket()->GetLocalAddress())); // Wait for both OnClose are delivered. - EXPECT_TRUE_WAIT(!ch1->conn()->connected(), kDefaultTimeout); - EXPECT_TRUE_WAIT(!ch2->conn()->connected(), kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return !ch1->conn()->connected(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return !ch2->conn()->connected(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Ensure redundant SignalClose events on TcpConnection won't break tcp // reconnection. Chromium will fire SignalClose for all outstanding IPC @@ -734,7 +763,10 @@ class PortTest : public ::testing::Test, public sigslot::has_slots<> { // Speed up destroying ch2's connection such that the test is ready to // accept a new connection from ch1 before ch1's connection destroys itself. ch2->Stop(); - EXPECT_TRUE_WAIT(ch2->conn() == NULL, kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch2->conn(); }, IsNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); } void TestTcpReconnect(bool ping_after_disconnected, @@ -755,8 +787,14 @@ class PortTest : public ::testing::Test, public sigslot::has_slots<> { ch1.Start(); ch2.Start(); - ASSERT_EQ_WAIT(1, ch1.complete_count(), kDefaultTimeout); - ASSERT_EQ_WAIT(1, ch2.complete_count(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ch1.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ch2.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Initial connecting the channel, create connection on channel1. ch1.CreateConnection(GetCandidate(ch2.port())); @@ -788,11 +826,18 @@ class PortTest : public ::testing::Test, public sigslot::has_slots<> { } // Wait for channel's outgoing TCPConnection connected. - EXPECT_TRUE_WAIT(ch1.conn()->connected(), kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch1.conn()->connected(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Verify that we could still connect channels. ConnectStartedChannels(&ch1, &ch2); - EXPECT_TRUE_WAIT(ch1.connection_ready_to_send(), kTcpReconnectTimeout); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return ch1.connection_ready_to_send(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTcpReconnectTimeout)}), + webrtc::IsRtcOk()); // Channel2 is the passive one so a new connection is created during // reconnect. This new connection should never have issued ENOTCONN // hence the connection_ready_to_send() should be false. @@ -801,15 +846,25 @@ class PortTest : public ::testing::Test, public sigslot::has_slots<> { EXPECT_EQ(ch1.conn()->write_state(), Connection::STATE_WRITABLE); // Since the reconnection never happens, the connections should have been // destroyed after the timeout. - EXPECT_TRUE_WAIT(!ch1.conn(), kTcpReconnectTimeout + kDefaultTimeout); + EXPECT_THAT( + webrtc::WaitUntil([&] { return !ch1.conn(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis( + kTcpReconnectTimeout + kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_TRUE(!ch2.conn()); } // Tear down and ensure that goes smoothly. ch1.Stop(); ch2.Stop(); - EXPECT_TRUE_WAIT(ch1.conn() == NULL, kDefaultTimeout); - EXPECT_TRUE_WAIT(ch2.conn() == NULL, kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch1.conn(); }, IsNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch2.conn(); }, IsNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); } std::unique_ptr CreateStunMessage(StunMessageType type) { @@ -926,14 +981,25 @@ void PortTest::TestConnectivity(absl::string_view name1, // Acquire addresses. ch1.Start(); ch2.Start(); - ASSERT_EQ_SIMULATED_WAIT(1, ch1.complete_count(), kDefaultTimeout, clock); - ASSERT_EQ_SIMULATED_WAIT(1, ch2.complete_count(), kDefaultTimeout, clock); + ASSERT_THAT( + webrtc::WaitUntil([&] { return ch1.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); + ASSERT_THAT( + webrtc::WaitUntil([&] { return ch2.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Send a ping from src to dst. This may or may not make it. ch1.CreateConnection(GetCandidate(ch2.port())); ASSERT_TRUE(ch1.conn() != NULL); - EXPECT_TRUE_SIMULATED_WAIT(ch1.conn()->connected(), kDefaultTimeout, - clock); // for TCP connect + EXPECT_THAT( + webrtc::WaitUntil([&] { return ch1.conn()->connected(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // for TCP connect ch1.Ping(); SIMULATED_WAIT(!ch2.remote_address().IsNil(), kShortTimeout, clock); @@ -953,8 +1019,12 @@ void PortTest::TestConnectivity(absl::string_view name1, ch2.AcceptConnection(GetCandidate(ch1.port())); ASSERT_TRUE(ch2.conn() != NULL); ch2.Ping(); - EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, - ch2.conn()->write_state(), kDefaultTimeout, clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch2.conn()->write_state(); }, + Eq(Connection::STATE_WRITABLE), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); } else { // We can't send a ping from src to dst, so flip it around. This will happen // when the destination NAT is addr/port restricted or symmetric. @@ -977,9 +1047,12 @@ void PortTest::TestConnectivity(absl::string_view name1, // through. So we will have to do another. if (ch1.conn()->write_state() == Connection::STATE_WRITE_INIT) { ch1.Ping(); - EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, - ch1.conn()->write_state(), kDefaultTimeout, - clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch1.conn()->write_state(); }, + Eq(Connection::STATE_WRITABLE), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); } } else if (!same_addr1 && possible) { // The new ping went to the candidate address, but that address was bad. @@ -990,8 +1063,11 @@ void PortTest::TestConnectivity(absl::string_view name1, // However, since we have now sent a ping to the source IP, we should be // able to get a ping from it. This gives us the real source address. ch1.Ping(); - EXPECT_TRUE_SIMULATED_WAIT(!ch2.remote_address().IsNil(), kDefaultTimeout, - clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return !ch2.remote_address().IsNil(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_FALSE(ch2.conn()->receiving()); EXPECT_TRUE(ch1.remote_address().IsNil()); @@ -999,9 +1075,12 @@ void PortTest::TestConnectivity(absl::string_view name1, ch2.AcceptConnection(GetCandidate(ch1.port())); ASSERT_TRUE(ch2.conn() != NULL); ch2.Ping(); - EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, - ch2.conn()->write_state(), kDefaultTimeout, - clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch2.conn()->write_state(); }, + Eq(Connection::STATE_WRITABLE), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); } else if (!same_addr2 && possible) { // The new ping came in, but from an unexpected address. This will happen // when the destination NAT is symmetric. @@ -1011,9 +1090,12 @@ void PortTest::TestConnectivity(absl::string_view name1, // Update our address and complete the connection. ch1.AcceptConnection(GetCandidate(ch2.port())); ch1.Ping(); - EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, - ch1.conn()->write_state(), kDefaultTimeout, - clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch1.conn()->write_state(); }, + Eq(Connection::STATE_WRITABLE), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); } else { // (!possible) // There should be s no way for the pings to reach each other. Check it. EXPECT_TRUE(ch1.remote_address().IsNil()); @@ -1043,8 +1125,16 @@ void PortTest::TestConnectivity(absl::string_view name1, // Tear down and ensure that goes smoothly. ch1.Stop(); ch2.Stop(); - EXPECT_TRUE_SIMULATED_WAIT(ch1.conn() == NULL, kDefaultTimeout, clock); - EXPECT_TRUE_SIMULATED_WAIT(ch2.conn() == NULL, kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ch1.conn(); }, IsNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ch2.conn(); }, IsNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); } class FakePacketSocketFactory : public rtc::PacketSocketFactory { @@ -1325,7 +1415,10 @@ TEST_F(PortTest, TestTcpNeverConnect) { EXPECT_EQ(0, ch1.complete_count()); ch1.Start(); - ASSERT_EQ_WAIT(1, ch1.complete_count(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ch1.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); std::unique_ptr server( vss()->CreateSocket(kLocalAddr2.family(), SOCK_STREAM)); @@ -1337,7 +1430,10 @@ TEST_F(PortTest, TestTcpNeverConnect) { ch1.CreateConnection(c); EXPECT_TRUE(ch1.conn()); - EXPECT_TRUE_WAIT(!ch1.conn(), kDefaultTimeout); // for TCP connect + EXPECT_THAT(webrtc::WaitUntil( + [&] { return !ch1.conn(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // for TCP connect } /* TODO(?): Enable these once testrelayserver can accept external TCP. @@ -1372,8 +1468,14 @@ TEST_F(PortTest, TestConnectionDead) { // Acquire address. ch1.Start(); ch2.Start(); - ASSERT_EQ_WAIT(1, ch1.complete_count(), kDefaultTimeout); - ASSERT_EQ_WAIT(1, ch2.complete_count(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ch1.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ch2.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Test case that the connection has never received anything. int64_t before_created = rtc::TimeMillis(); @@ -1392,7 +1494,10 @@ TEST_F(PortTest, TestConnectionDead) { EXPECT_TRUE(ch1.conn() != nullptr); // It will be dead after MIN_CONNECTION_LIFETIME and pruned. conn->UpdateState(after_created + MIN_CONNECTION_LIFETIME + 1); - EXPECT_TRUE_WAIT(ch1.conn() == nullptr, kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch1.conn(); }, Eq(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Test case that the connection has received something. // Create a connection again and receive a ping. @@ -1408,7 +1513,10 @@ TEST_F(PortTest, TestConnectionDead) { rtc::Thread::Current()->ProcessMessages(100); EXPECT_TRUE(ch1.conn() != nullptr); conn->UpdateState(after_last_receiving + DEAD_CONNECTION_RECEIVE_TIMEOUT + 1); - EXPECT_TRUE_WAIT(ch1.conn() == nullptr, kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch1.conn(); }, Eq(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); } TEST_F(PortTest, TestConnectionDeadWithDeadConnectionTimeout) { @@ -1417,8 +1525,14 @@ TEST_F(PortTest, TestConnectionDeadWithDeadConnectionTimeout) { // Acquire address. ch1.Start(); ch2.Start(); - ASSERT_EQ_WAIT(1, ch1.complete_count(), kDefaultTimeout); - ASSERT_EQ_WAIT(1, ch2.complete_count(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ch1.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ch2.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Note: set field trials manually since they are parsed by // P2PTransportChannel but P2PTransportChannel is not used in this test. @@ -1439,7 +1553,10 @@ TEST_F(PortTest, TestConnectionDeadWithDeadConnectionTimeout) { rtc::Thread::Current()->ProcessMessages(100); EXPECT_TRUE(ch1.conn() != nullptr); conn->UpdateState(after_last_receiving + 90000 + 1); - EXPECT_TRUE_WAIT(ch1.conn() == nullptr, kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch1.conn(); }, Eq(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); } TEST_F(PortTest, TestConnectionDeadOutstandingPing) { @@ -1455,8 +1572,14 @@ TEST_F(PortTest, TestConnectionDeadOutstandingPing) { // Acquire address. ch1.Start(); ch2.Start(); - ASSERT_EQ_WAIT(1, ch1.complete_count(), kDefaultTimeout); - ASSERT_EQ_WAIT(1, ch2.complete_count(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ch1.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ch2.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Note: set field trials manually since they are parsed by // P2PTransportChannel but P2PTransportChannel is not used in this test. @@ -1479,7 +1602,10 @@ TEST_F(PortTest, TestConnectionDeadOutstandingPing) { rtc::Thread::Current()->ProcessMessages(100); EXPECT_TRUE(ch1.conn() != nullptr); conn->UpdateState(send_ping_timestamp + DEAD_CONNECTION_RECEIVE_TIMEOUT + 1); - EXPECT_TRUE_WAIT(ch1.conn() == nullptr, kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch1.conn(); }, Eq(nullptr), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); } // This test case verifies standard ICE features in STUN messages. Currently it @@ -1511,12 +1637,18 @@ TEST_F(PortTest, TestLoopbackCall) { lport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE); conn->Ping(0); - ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return lport->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); IceMessage* msg = lport->last_stun_msg(); EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); conn->OnReadPacket(rtc::ReceivedPacket(lport->last_stun_buf(), rtc::SocketAddress(), std::nullopt)); - ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return lport->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); msg = lport->last_stun_msg(); EXPECT_EQ(STUN_BINDING_RESPONSE, msg->type()); @@ -1529,7 +1661,10 @@ TEST_F(PortTest, TestLoopbackCall) { lport->CreateConnection(lport->Candidates()[1], Port::ORIGIN_MESSAGE); conn1->Ping(0); - ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return lport->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); msg = lport->last_stun_msg(); EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); std::unique_ptr modified_req( @@ -1551,7 +1686,10 @@ TEST_F(PortTest, TestLoopbackCall) { conn1->OnReadPacket(rtc::ReceivedPacket::CreateFromLegacy( reinterpret_cast(buf->Data()), buf->Length(), /*packet_time_us=*/-1)); - ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return lport->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); msg = lport->last_stun_msg(); EXPECT_EQ(STUN_BINDING_ERROR_RESPONSE, msg->type()); } @@ -1579,14 +1717,20 @@ TEST_F(PortTest, TestIceRoleConflict) { rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE); rconn->Ping(0); - ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return rport->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); IceMessage* msg = rport->last_stun_msg(); EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); // Send rport binding request to lport. lconn->OnReadPacket(rtc::ReceivedPacket(rport->last_stun_buf(), rtc::SocketAddress(), std::nullopt)); - ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return lport->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_EQ(STUN_BINDING_RESPONSE, lport->last_stun_msg()->type()); EXPECT_TRUE(role_conflict()); } @@ -1610,13 +1754,24 @@ TEST_F(PortTest, TestTcpNoDelay) { // Acquire addresses. ch1.Start(); ch2.Start(); - ASSERT_EQ_SIMULATED_WAIT(1, ch1.complete_count(), kDefaultTimeout, clock); - ASSERT_EQ_SIMULATED_WAIT(1, ch2.complete_count(), kDefaultTimeout, clock); + ASSERT_THAT( + webrtc::WaitUntil([&] { return ch1.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); + ASSERT_THAT( + webrtc::WaitUntil([&] { return ch2.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Connect and send a ping from src to dst. ch1.CreateConnection(GetCandidate(ch2.port())); ASSERT_TRUE(ch1.conn() != NULL); - EXPECT_TRUE_SIMULATED_WAIT(ch1.conn()->connected(), kDefaultTimeout, - clock); // for TCP connect + EXPECT_THAT( + webrtc::WaitUntil([&] { return ch1.conn()->connected(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // for TCP connect ch1.Ping(); SIMULATED_WAIT(!ch2.remote_address().IsNil(), kShortTimeout, clock); @@ -1884,7 +2039,10 @@ TEST_F(PortTest, TestSendStunMessage) { lconn->Ping(0); // Check that it's a proper BINDING-REQUEST. - ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return lport->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); IceMessage* msg = lport->last_stun_msg(); EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); EXPECT_FALSE(msg->IsLegacy()); @@ -1986,7 +2144,10 @@ TEST_F(PortTest, TestSendStunMessage) { rconn->Ping(0); rconn->Ping(0); rconn->Ping(0); - ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return rport->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); msg = rport->last_stun_msg(); EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); const StunUInt64Attribute* ice_controlled_attr = @@ -2057,7 +2218,10 @@ TEST_F(PortTest, TestNomination) { // Send ping (including the nomination value) from `lconn` to `rconn`. This // should set the remote nomination of `rconn`. lconn->Ping(0); - ASSERT_TRUE_WAIT(lport->last_stun_msg(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return lport->last_stun_msg(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); ASSERT_GT(lport->last_stun_buf().size(), 0u); rconn->OnReadPacket(rtc::ReceivedPacket(lport->last_stun_buf(), rtc::SocketAddress(), std::nullopt)); @@ -2070,7 +2234,10 @@ TEST_F(PortTest, TestNomination) { // This should result in an acknowledgment sent back from `rconn` to `lconn`, // updating the acknowledged nomination of `lconn`. - ASSERT_TRUE_WAIT(rport->last_stun_msg(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return rport->last_stun_msg(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); ASSERT_GT(rport->last_stun_buf().size(), 0u); lconn->OnReadPacket(rtc::ReceivedPacket(rport->last_stun_buf(), rtc::SocketAddress(), std::nullopt)); @@ -2138,7 +2305,10 @@ TEST_F(PortTest, TestUseCandidateAttribute) { Connection* lconn = lport->CreateConnection(rport->Candidates()[0], Port::ORIGIN_MESSAGE); lconn->Ping(0); - ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return lport->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); IceMessage* msg = lport->last_stun_msg(); const StunUInt64Attribute* ice_controlling_attr = msg->GetUInt64(STUN_ATTR_ICE_CONTROLLING); @@ -2196,7 +2366,10 @@ TEST_F(PortTest, TestNetworkCostChange) { // message is handled in rconn, The rconn's remote candidate will have cost // rtc::kNetworkCostHigh; EXPECT_EQ(rtc::kNetworkCostLow, rconn->remote_candidate().network_cost()); - ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return lport->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); IceMessage* msg = lport->last_stun_msg(); EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); // Pass the binding request to rport. @@ -2204,7 +2377,10 @@ TEST_F(PortTest, TestNetworkCostChange) { rtc::SocketAddress(), std::nullopt)); // Wait until rport sends the response and then check the remote network cost. - ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return rport->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_EQ(rtc::kNetworkCostHigh, rconn->remote_candidate().network_cost()); } @@ -2225,7 +2401,10 @@ TEST_F(PortTest, TestNetworkInfoAttribute) { Connection* lconn = lport->CreateConnection(rport->Candidates()[0], Port::ORIGIN_MESSAGE); lconn->Ping(0); - ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return lport->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); IceMessage* msg = lport->last_stun_msg(); const StunUInt32Attribute* network_info_attr = msg->GetUInt32(STUN_ATTR_GOOG_NETWORK_INFO); @@ -2243,7 +2422,10 @@ TEST_F(PortTest, TestNetworkInfoAttribute) { Connection* rconn = rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE); rconn->Ping(0); - ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return rport->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); msg = rport->last_stun_msg(); network_info_attr = msg->GetUInt32(STUN_ATTR_GOOG_NETWORK_INFO); ASSERT_TRUE(network_info_attr != NULL); @@ -2530,12 +2712,18 @@ TEST_F(PortTest, // Send request. lconn->Ping(0); - ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return lport->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); rconn->OnReadPacket(rtc::ReceivedPacket(lport->last_stun_buf(), rtc::SocketAddress(), std::nullopt)); // Intercept request and add comprehension required attribute. - ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return rport->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); auto modified_response = rport->last_stun_msg()->Clone(); modified_response->AddAttribute(StunAttribute::CreateUInt32(0x7777)); modified_response->RemoveAttribute(STUN_ATTR_FINGERPRINT); @@ -2615,14 +2803,20 @@ TEST_F(PortTest, TestHandleStunBindingIndication) { rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE); rconn->Ping(0); - ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return rport->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); IceMessage* msg = rport->last_stun_msg(); EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); // Send rport binding request to lport. lconn->OnReadPacket(rtc::ReceivedPacket(rport->last_stun_buf(), rtc::SocketAddress(), std::nullopt)); - ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return lport->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_EQ(STUN_BINDING_RESPONSE, lport->last_stun_msg()->type()); int64_t last_ping_received1 = lconn->last_ping_received(); @@ -2742,7 +2936,10 @@ TEST_F(PortTest, TestCandidateFoundation) { tcpport2->Candidates()[0].foundation()); auto stunport = CreateStunPort(kLocalAddr1, nat_socket_factory1()); stunport->PrepareAddress(); - ASSERT_EQ_WAIT(1U, stunport->Candidates().size(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return stunport->Candidates().size(); }, Eq(1U), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_NE(tcpport1->Candidates()[0].foundation(), stunport->Candidates()[0].foundation()); EXPECT_NE(tcpport2->Candidates()[0].foundation(), @@ -2755,7 +2952,10 @@ TEST_F(PortTest, TestCandidateFoundation) { auto turnport1 = CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP); turnport1->PrepareAddress(); - ASSERT_EQ_WAIT(1U, turnport1->Candidates().size(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return turnport1->Candidates().size(); }, Eq(1U), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_NE(udpport1->Candidates()[0].foundation(), turnport1->Candidates()[0].foundation()); EXPECT_NE(udpport2->Candidates()[0].foundation(), @@ -2765,7 +2965,10 @@ TEST_F(PortTest, TestCandidateFoundation) { auto turnport2 = CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP); turnport2->PrepareAddress(); - ASSERT_EQ_WAIT(1U, turnport2->Candidates().size(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return turnport2->Candidates().size(); }, Eq(1U), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_EQ(turnport1->Candidates()[0].foundation(), turnport2->Candidates()[0].foundation()); @@ -2777,7 +2980,10 @@ TEST_F(PortTest, TestCandidateFoundation) { auto turnport3 = CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP, kTurnUdpIntAddr2); turnport3->PrepareAddress(); - ASSERT_EQ_WAIT(1U, turnport3->Candidates().size(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return turnport3->Candidates().size(); }, Eq(1U), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_NE(turnport3->Candidates()[0].foundation(), turnport2->Candidates()[0].foundation()); @@ -2788,7 +2994,10 @@ TEST_F(PortTest, TestCandidateFoundation) { auto turnport4 = CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_TCP, PROTO_UDP); turnport4->PrepareAddress(); - ASSERT_EQ_WAIT(1U, turnport4->Candidates().size(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return turnport4->Candidates().size(); }, Eq(1U), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_NE(turnport2->Candidates()[0].foundation(), turnport4->Candidates()[0].foundation()); } @@ -2806,7 +3015,10 @@ TEST_F(PortTest, TestCandidateRelatedAddress) { // socket address. auto stunport = CreateStunPort(kLocalAddr1, nat_socket_factory1()); stunport->PrepareAddress(); - ASSERT_EQ_WAIT(1U, stunport->Candidates().size(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return stunport->Candidates().size(); }, Eq(1U), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Check STUN candidate address. EXPECT_EQ(stunport->Candidates()[0].address().ipaddr(), kNatAddr1.ipaddr()); // Check STUN candidate related address. @@ -2817,7 +3029,10 @@ TEST_F(PortTest, TestCandidateRelatedAddress) { auto turnport = CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP); turnport->PrepareAddress(); - ASSERT_EQ_WAIT(1U, turnport->Candidates().size(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return turnport->Candidates().size(); }, Eq(1U), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); EXPECT_EQ(kTurnUdpExtAddr.ipaddr(), turnport->Candidates()[0].address().ipaddr()); EXPECT_EQ(kNatAddr1.ipaddr(), @@ -2938,15 +3153,27 @@ TEST_F(PortTest, TestWritableState) { // Acquire addresses. ch1.Start(); ch2.Start(); - ASSERT_EQ_SIMULATED_WAIT(1, ch1.complete_count(), kDefaultTimeout, clock); - ASSERT_EQ_SIMULATED_WAIT(1, ch2.complete_count(), kDefaultTimeout, clock); + ASSERT_THAT( + webrtc::WaitUntil([&] { return ch1.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); + ASSERT_THAT( + webrtc::WaitUntil([&] { return ch2.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Send a ping from src to dst. ch1.CreateConnection(GetCandidate(ch2.port())); ASSERT_TRUE(ch1.conn() != NULL); EXPECT_EQ(Connection::STATE_WRITE_INIT, ch1.conn()->write_state()); // for TCP connect - EXPECT_TRUE_SIMULATED_WAIT(ch1.conn()->connected(), kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ch1.conn()->connected(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); ch1.Ping(); SIMULATED_WAIT(!ch2.remote_address().IsNil(), kShortTimeout, clock); @@ -2959,8 +3186,12 @@ TEST_F(PortTest, TestWritableState) { // Accept the connection to return the binding response, transition to // writable, and allow data to be sent. ch2.AcceptConnection(GetCandidate(ch1.port())); - EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, - ch1.conn()->write_state(), kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ch1.conn()->write_state(); }, + Eq(Connection::STATE_WRITABLE), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); EXPECT_EQ(data_size, ch1.conn()->Send(data, data_size, options)); // Ask the connection to update state as if enough time has passed to lose @@ -2979,8 +3210,12 @@ TEST_F(PortTest, TestWritableState) { // And now allow the other side to process the pings and send binding // responses. - EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, - ch1.conn()->write_state(), kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ch1.conn()->write_state(); }, + Eq(Connection::STATE_WRITABLE), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Wait long enough for a full timeout (past however long we've already // waited). for (uint32_t i = 1; i <= CONNECTION_WRITE_CONNECT_FAILURES; ++i) { @@ -3015,8 +3250,16 @@ TEST_F(PortTest, TestWritableStateWithConfiguredThreshold) { // Acquire addresses. ch1.Start(); ch2.Start(); - ASSERT_EQ_SIMULATED_WAIT(1, ch1.complete_count(), kDefaultTimeout, clock); - ASSERT_EQ_SIMULATED_WAIT(1, ch2.complete_count(), kDefaultTimeout, clock); + ASSERT_THAT( + webrtc::WaitUntil([&] { return ch1.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); + ASSERT_THAT( + webrtc::WaitUntil([&] { return ch2.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); // Send a ping from src to dst. ch1.CreateConnection(GetCandidate(ch2.port())); @@ -3027,8 +3270,12 @@ TEST_F(PortTest, TestWritableStateWithConfiguredThreshold) { // Accept the connection to return the binding response, transition to // writable, and allow data to be sent. ch2.AcceptConnection(GetCandidate(ch1.port())); - EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, - ch1.conn()->write_state(), kDefaultTimeout, clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return ch1.conn()->write_state(); }, + Eq(Connection::STATE_WRITABLE), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout), + .clock = &clock}), + webrtc::IsRtcOk()); ch1.conn()->set_unwritable_timeout(1000); ch1.conn()->set_unwritable_min_checks(3); @@ -3102,7 +3349,10 @@ TEST_F(PortTest, TestIceLiteConnectivity) { ch1.Start(); ice_lite_port->PrepareAddress(); - ASSERT_EQ_WAIT(1, ch1.complete_count(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ch1.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); ASSERT_FALSE(ice_lite_port->Candidates().empty()); ch1.CreateConnection(GetCandidate(ice_lite_port.get())); @@ -3115,7 +3365,10 @@ TEST_F(PortTest, TestIceLiteConnectivity) { // Verify stun ping is without USE_CANDIDATE_ATTR. Getting message directly // from port. - ASSERT_TRUE_WAIT(ice_full_port_ptr->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ice_full_port_ptr->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); IceMessage* msg = ice_full_port_ptr->last_stun_msg(); EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) == NULL); @@ -3133,16 +3386,25 @@ TEST_F(PortTest, TestIceLiteConnectivity) { ice_lite_port->last_stun_buf(), rtc::SocketAddress(), std::nullopt)); // Verifying full mode connection becomes writable from the response. - EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(), - kDefaultTimeout); - EXPECT_TRUE_WAIT(ch1.nominated(), kDefaultTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch1.conn()->write_state(); }, + Eq(Connection::STATE_WRITABLE), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return ch1.nominated(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // Clear existing stun messsages. Otherwise we will process old stun // message right after we send ping. ice_full_port_ptr->Reset(); // Send ping. This must have USE_CANDIDATE_ATTR. ch1.Ping(); - ASSERT_TRUE_WAIT(ice_full_port_ptr->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ice_full_port_ptr->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); msg = ice_full_port_ptr->last_stun_msg(); EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) != NULL); ch1.Stop(); @@ -3215,7 +3477,10 @@ TEST_P(GoogPingTest, TestGoogPingAnnounceEnable) { ch1.Start(); port2->PrepareAddress(); - ASSERT_EQ_WAIT(1, ch1.complete_count(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ch1.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); ASSERT_FALSE(port2->Candidates().empty()); ch1.CreateConnection(GetCandidate(port2.get())); @@ -3226,7 +3491,10 @@ TEST_P(GoogPingTest, TestGoogPingAnnounceEnable) { // Send ping. ch1.Ping(); - ASSERT_TRUE_WAIT(port1->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return port1->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); const IceMessage* request1 = port1->last_stun_msg(); ASSERT_EQ(trials.enable_goog_ping, @@ -3254,7 +3522,10 @@ TEST_P(GoogPingTest, TestGoogPingAnnounceEnable) { port2->Reset(); ch1.Ping(); - ASSERT_TRUE_WAIT(port1->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return port1->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); const IceMessage* request2 = port1->last_stun_msg(); // It should be a GOOG_PING if both of these are TRUE @@ -3306,7 +3577,10 @@ TEST_F(PortTest, TestGoogPingUnsupportedVersionInStunBinding) { ch1.Start(); port2->PrepareAddress(); - ASSERT_EQ_WAIT(1, ch1.complete_count(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ch1.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); ASSERT_FALSE(port2->Candidates().empty()); ch1.CreateConnection(GetCandidate(port2.get())); @@ -3317,7 +3591,10 @@ TEST_F(PortTest, TestGoogPingUnsupportedVersionInStunBinding) { // Send ping. ch1.Ping(); - ASSERT_TRUE_WAIT(port1->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return port1->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); const IceMessage* request1 = port1->last_stun_msg(); ASSERT_TRUE(GetSupportedGoogPingVersion(request1) && @@ -3377,7 +3654,10 @@ TEST_F(PortTest, TestGoogPingUnsupportedVersionInStunBindingResponse) { ch1.Start(); port2->PrepareAddress(); - ASSERT_EQ_WAIT(1, ch1.complete_count(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ch1.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); ASSERT_FALSE(port2->Candidates().empty()); ch1.CreateConnection(GetCandidate(port2.get())); @@ -3388,7 +3668,10 @@ TEST_F(PortTest, TestGoogPingUnsupportedVersionInStunBindingResponse) { // Send ping. ch1.Ping(); - ASSERT_TRUE_WAIT(port1->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return port1->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); const IceMessage* request1 = port1->last_stun_msg(); ASSERT_TRUE(GetSupportedGoogPingVersion(request1) && @@ -3438,7 +3721,10 @@ TEST_F(PortTest, TestGoogPingUnsupportedVersionInStunBindingResponse) { port2->Reset(); ch1.Ping(); - ASSERT_TRUE_WAIT(port1->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return port1->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); // This should now be a STUN_BINDING...without a kGoogPingVersion const IceMessage* request2 = port1->last_stun_msg(); @@ -3478,7 +3764,10 @@ TEST_F(PortTest, TestChangeInAttributeMakesGoogPingFallsbackToStunBinding) { ch1.Start(); port2->PrepareAddress(); - ASSERT_EQ_WAIT(1, ch1.complete_count(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ch1.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); ASSERT_FALSE(port2->Candidates().empty()); ch1.CreateConnection(GetCandidate(port2.get())); @@ -3489,7 +3778,10 @@ TEST_F(PortTest, TestChangeInAttributeMakesGoogPingFallsbackToStunBinding) { // Send ping. ch1.Ping(); - ASSERT_TRUE_WAIT(port1->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return port1->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); const IceMessage* msg = port1->last_stun_msg(); auto* con = port2->CreateConnection(port1->Candidates()[0], cricket::Port::ORIGIN_MESSAGE); @@ -3511,7 +3803,10 @@ TEST_F(PortTest, TestChangeInAttributeMakesGoogPingFallsbackToStunBinding) { port2->Reset(); ch1.Ping(); - ASSERT_TRUE_WAIT(port1->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return port1->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); const IceMessage* msg2 = port1->last_stun_msg(); // It should be a GOOG_PING if both of these are TRUE @@ -3532,7 +3827,10 @@ TEST_F(PortTest, TestChangeInAttributeMakesGoogPingFallsbackToStunBinding) { ch1.conn()->set_use_candidate_attr(!ch1.conn()->use_candidate_attr()); ch1.Ping(); - ASSERT_TRUE_WAIT(port1->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return port1->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); const IceMessage* msg3 = port1->last_stun_msg(); // It should be a STUN_BINDING_REQUEST @@ -3563,7 +3861,10 @@ TEST_F(PortTest, TestErrorResponseMakesGoogPingFallBackToStunBinding) { ch1.Start(); port2->PrepareAddress(); - ASSERT_EQ_WAIT(1, ch1.complete_count(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return ch1.complete_count(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); ASSERT_FALSE(port2->Candidates().empty()); ch1.CreateConnection(GetCandidate(port2.get())); @@ -3574,7 +3875,10 @@ TEST_F(PortTest, TestErrorResponseMakesGoogPingFallBackToStunBinding) { // Send ping. ch1.Ping(); - ASSERT_TRUE_WAIT(port1->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return port1->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); const IceMessage* msg = port1->last_stun_msg(); auto* con = port2->CreateConnection(port1->Candidates()[0], cricket::Port::ORIGIN_MESSAGE); @@ -3596,7 +3900,10 @@ TEST_F(PortTest, TestErrorResponseMakesGoogPingFallBackToStunBinding) { port2->Reset(); ch1.Ping(); - ASSERT_TRUE_WAIT(port1->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return port1->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); const IceMessage* msg2 = port1->last_stun_msg(); // It should be a GOOG_PING. @@ -3624,7 +3931,10 @@ TEST_F(PortTest, TestErrorResponseMakesGoogPingFallBackToStunBinding) { port2->Reset(); ch1.Ping(); - ASSERT_TRUE_WAIT(port1->last_stun_msg() != NULL, kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return port1->last_stun_msg(); }, NotNull(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); const IceMessage* msg3 = port1->last_stun_msg(); // It should be a STUN_BINDING_REQUEST @@ -3659,7 +3969,9 @@ TEST_F(PortTest, TestPortTimeoutIfNotKeptAlive) { StartConnectAndStopChannels(&ch1, &ch2); // After the connection is destroyed, the port will be destroyed because // none of them is marked as "keep alive until pruned. - EXPECT_EQ_SIMULATED_WAIT(2, ports_destroyed(), 110, clock); + EXPECT_THAT(webrtc::WaitUntil([&] { return ports_destroyed(); }, Eq(2), + {.clock = &clock}), + webrtc::IsRtcOk()); } // Test that if after all connection are destroyed, new connections are created @@ -3700,7 +4012,9 @@ TEST_F(PortTest, TestPortTimeoutAfterNewConnectionCreatedAndDestroyed) { EXPECT_EQ(0, ports_destroyed()); // The ports on both sides should be destroyed after timeout. - EXPECT_TRUE_SIMULATED_WAIT(ports_destroyed() == 2, 30, clock); + EXPECT_THAT(webrtc::WaitUntil([&] { return ports_destroyed(); }, Eq(2), + {.clock = &clock}), + webrtc::IsRtcOk()); } // This test case verifies that neither the controlling port nor the controlled @@ -3741,7 +4055,9 @@ TEST_F(PortTest, TestPortNotTimeoutUntilPruned) { ch1.port()->Prune(); ch2.port()->Prune(); // The ports on both sides should be destroyed after timeout. - EXPECT_TRUE_SIMULATED_WAIT(ports_destroyed() == 2, 1, clock); + EXPECT_THAT(webrtc::WaitUntil([&] { return ports_destroyed(); }, Eq(2), + {.clock = &clock}), + webrtc::IsRtcOk()); } TEST_F(PortTest, TestSupportsProtocol) { @@ -3853,13 +4169,19 @@ class ConnectionTest : public PortTest { TestPort* rport = rconn->PortForTest() == rport_.get() ? rport_.get() : lport_.get(); lconn->Ping(rtc::TimeMillis()); - ASSERT_TRUE_WAIT(lport->last_stun_msg(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return lport->last_stun_msg(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); ASSERT_GT(lport->last_stun_buf().size(), 0u); rconn->OnReadPacket(rtc::ReceivedPacket( lport->last_stun_buf(), rtc::SocketAddress(), std::nullopt)); clock_.AdvanceTime(webrtc::TimeDelta::Millis(ms)); - ASSERT_TRUE_WAIT(rport->last_stun_msg(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return rport->last_stun_msg(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); ASSERT_GT(rport->last_stun_buf().size(), 0u); reply->SetData(rport->last_stun_buf()); } @@ -4003,14 +4325,20 @@ TEST_F(ConnectionTest, SendReceiveGoogDelta) { [](webrtc::RTCErrorOr error_or__ack) {}); lconn->Ping(rtc::TimeMillis(), std::move(delta)); - ASSERT_TRUE_WAIT(lport_->last_stun_msg(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return lport_->last_stun_msg(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); ASSERT_GT(lport_->last_stun_buf().size(), 0u); rconn->OnReadPacket(rtc::ReceivedPacket(lport_->last_stun_buf(), rtc::SocketAddress(), std::nullopt)); EXPECT_TRUE(received_goog_delta); clock_.AdvanceTime(webrtc::TimeDelta::Millis(ms)); - ASSERT_TRUE_WAIT(rport_->last_stun_msg(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return rport_->last_stun_msg(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); ASSERT_GT(rport_->last_stun_buf().size(), 0u); lconn->OnReadPacket(rtc::ReceivedPacket(rport_->last_stun_buf(), rtc::SocketAddress(), std::nullopt)); @@ -4041,13 +4369,19 @@ TEST_F(ConnectionTest, SendGoogDeltaNoReply) { }); lconn->Ping(rtc::TimeMillis(), std::move(delta)); - ASSERT_TRUE_WAIT(lport_->last_stun_msg(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return lport_->last_stun_msg(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); ASSERT_GT(lport_->last_stun_buf().size(), 0u); rconn->OnReadPacket(rtc::ReceivedPacket(lport_->last_stun_buf(), rtc::SocketAddress(), std::nullopt)); clock_.AdvanceTime(webrtc::TimeDelta::Millis(ms)); - ASSERT_TRUE_WAIT(rport_->last_stun_msg(), kDefaultTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return rport_->last_stun_msg(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}), + webrtc::IsRtcOk()); ASSERT_GT(rport_->last_stun_buf().size(), 0u); lconn->OnReadPacket(rtc::ReceivedPacket(rport_->last_stun_buf(), rtc::SocketAddress(), std::nullopt)); diff --git a/p2p/base/pseudo_tcp_unittest.cc b/p2p/base/pseudo_tcp_unittest.cc index 4057e84ca4..fd12410f23 100644 --- a/p2p/base/pseudo_tcp_unittest.cc +++ b/p2p/base/pseudo_tcp_unittest.cc @@ -14,21 +14,28 @@ #include #include +#include #include #include #include +#include "api/array_view.h" #include "api/task_queue/pending_task_safety_flag.h" #include "api/task_queue/task_queue_base.h" +#include "api/test/rtc_error_matchers.h" #include "api/units/time_delta.h" #include "rtc_base/crypto_random.h" -#include "rtc_base/gunit.h" #include "rtc_base/logging.h" #include "rtc_base/memory_stream.h" +#include "rtc_base/stream.h" +#include "rtc_base/thread.h" #include "rtc_base/time_utils.h" +#include "test/gmock.h" #include "test/gtest.h" +#include "test/wait_until.h" using ::cricket::PseudoTcp; +using ::testing::IsTrue; using ::webrtc::ScopedTaskSafety; using ::webrtc::TaskQueueBase; using ::webrtc::TimeDelta; @@ -243,10 +250,16 @@ class PseudoTcpTest : public PseudoTcpTestBase { // Connect and wait until connected. start = rtc::Time32(); EXPECT_EQ(0, Connect()); - EXPECT_TRUE_WAIT(have_connected_, kConnectTimeoutMs); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return have_connected_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kConnectTimeoutMs)}), + webrtc::IsRtcOk()); // Sending will start from OnTcpWriteable and complete when all data has // been received. - EXPECT_TRUE_WAIT(have_disconnected_, kTransferTimeoutMs); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return have_disconnected_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTransferTimeoutMs)}), + webrtc::IsRtcOk()); elapsed = rtc::Time32() - start; recv_stream_.GetSize(&received); // Ensure we closed down OK and we got the right data. @@ -366,10 +379,16 @@ class PseudoTcpTestPingPong : public PseudoTcpTestBase { // Connect and wait until connected. start = rtc::Time32(); EXPECT_EQ(0, Connect()); - EXPECT_TRUE_WAIT(have_connected_, kConnectTimeoutMs); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return have_connected_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kConnectTimeoutMs)}), + webrtc::IsRtcOk()); // Sending will start from OnTcpWriteable and stop when the required // number of iterations have completed. - EXPECT_TRUE_WAIT(have_disconnected_, kTransferTimeoutMs); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return have_disconnected_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTransferTimeoutMs)}), + webrtc::IsRtcOk()); elapsed = rtc::TimeSince(start); RTC_LOG(LS_INFO) << "Performed " << iterations << " pings in " << elapsed << " ms"; @@ -488,10 +507,16 @@ class PseudoTcpTestReceiveWindow : public PseudoTcpTestBase { // Connect and wait until connected. EXPECT_EQ(0, Connect()); - EXPECT_TRUE_WAIT(have_connected_, kConnectTimeoutMs); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return have_connected_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kConnectTimeoutMs)}), + webrtc::IsRtcOk()); TaskQueueBase::Current()->PostTask([this] { WriteData(); }); - EXPECT_TRUE_WAIT(have_disconnected_, kTransferTimeoutMs); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return have_disconnected_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTransferTimeoutMs)}), + webrtc::IsRtcOk()); ASSERT_EQ(2u, send_position_.size()); ASSERT_EQ(2u, recv_position_.size()); diff --git a/p2p/base/stun_port_unittest.cc b/p2p/base/stun_port_unittest.cc index 2c50784a7a..ac812da8e1 100644 --- a/p2p/base/stun_port_unittest.cc +++ b/p2p/base/stun_port_unittest.cc @@ -10,21 +10,45 @@ #include "p2p/base/stun_port.h" +#include +#include #include +#include +#include +#include "absl/functional/any_invocable.h" +#include "api/candidate.h" +#include "api/field_trials_view.h" +#include "api/packet_socket_factory.h" #include "api/test/mock_async_dns_resolver.h" +#include "api/test/rtc_error_matchers.h" +#include "api/transport/stun.h" +#include "api/units/time_delta.h" #include "p2p/base/basic_packet_socket_factory.h" #include "p2p/base/mock_dns_resolving_packet_socket_factory.h" +#include "p2p/base/port.h" +#include "p2p/base/stun_request.h" #include "p2p/base/test_stun_server.h" #include "rtc_base/async_packet_socket.h" #include "rtc_base/crypto_random.h" +#include "rtc_base/dscp.h" +#include "rtc_base/fake_clock.h" #include "rtc_base/gunit.h" +#include "rtc_base/ip_address.h" +#include "rtc_base/mdns_responder_interface.h" +#include "rtc_base/net_helpers.h" +#include "rtc_base/network.h" #include "rtc_base/network/received_packet.h" +#include "rtc_base/network_constants.h" +#include "rtc_base/socket.h" #include "rtc_base/socket_address.h" -#include "rtc_base/ssl_adapter.h" +#include "rtc_base/third_party/sigslot/sigslot.h" +#include "rtc_base/thread.h" #include "rtc_base/virtual_socket_server.h" #include "test/gmock.h" +#include "test/gtest.h" #include "test/scoped_key_value_config.h" +#include "test/wait_until.h" namespace { @@ -32,6 +56,8 @@ using cricket::ServerAddresses; using rtc::SocketAddress; using ::testing::_; using ::testing::DoAll; +using ::testing::Eq; +using ::testing::IsTrue; using ::testing::Return; using ::testing::ReturnPointee; using ::testing::SetArgPointee; @@ -286,7 +312,11 @@ TEST_F(StunPortTest, TestCreateUdpPort) { TEST_F(StunPortTest, TestPrepareAddress) { CreateStunPort(kStunAddr1); PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); ASSERT_EQ(1U, port()->Candidates().size()); EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address())); std::string expected_server_url = "stun:127.0.0.1:5000"; @@ -297,12 +327,19 @@ TEST_F(StunPortTest, TestPrepareAddress) { TEST_F(StunPortTest, TestPrepareAddressFail) { CreateStunPort(kBadAddr); PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(error()); EXPECT_EQ(0U, port()->Candidates().size()); - EXPECT_EQ_SIMULATED_WAIT(error_event_.error_code, - cricket::STUN_ERROR_SERVER_NOT_REACHABLE, kTimeoutMs, - fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return error_event_.error_code; }, + Eq(cricket::STUN_ERROR_SERVER_NOT_REACHABLE), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_NE(error_event_.error_text.find('.'), std::string::npos); EXPECT_NE(error_event_.address.find(kLocalAddr.HostAsSensitiveURIString()), std::string::npos); @@ -315,7 +352,11 @@ TEST_F(StunPortTest, TestPrepareAddressFail) { TEST_F(StunPortTest, TestServerAddressFamilyMismatch) { CreateStunPort(kIPv6StunAddr1); PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(error()); EXPECT_EQ(0U, port()->Candidates().size()); EXPECT_EQ(0, error_event_.error_code); @@ -356,7 +397,11 @@ TEST_F(StunPortWithMockDnsResolverTest, TestPrepareAddressHostname) { }); CreateStunPort(kValidHostnameAddr); PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); ASSERT_EQ(1U, port()->Candidates().size()); EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address())); EXPECT_EQ(kStunCandidatePriority, port()->Candidates()[0].priority()); @@ -381,7 +426,11 @@ TEST_F(StunPortWithMockDnsResolverTest, }); CreateStunPort(kValidHostnameAddr); PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); ASSERT_EQ(1U, port()->Candidates().size()); EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address())); EXPECT_EQ(kStunCandidatePriority + (cricket::kMaxTurnServers << 8), @@ -392,11 +441,17 @@ TEST_F(StunPortWithMockDnsResolverTest, TEST_F(StunPortTestWithRealClock, TestPrepareAddressHostnameFail) { CreateStunPort(kBadHostnameAddr); PrepareAddress(); - EXPECT_TRUE_WAIT(done(), kTimeoutMs); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs)}), + webrtc::IsRtcOk()); EXPECT_TRUE(error()); EXPECT_EQ(0U, port()->Candidates().size()); - EXPECT_EQ_WAIT(error_event_.error_code, - cricket::STUN_ERROR_SERVER_NOT_REACHABLE, kTimeoutMs); + EXPECT_THAT( + webrtc::WaitUntil([&] { return error_event_.error_code; }, + Eq(cricket::STUN_ERROR_SERVER_NOT_REACHABLE), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs)}), + webrtc::IsRtcOk()); } // This test verifies keepalive response messages don't result in @@ -405,7 +460,11 @@ TEST_F(StunPortTest, TestKeepAliveResponse) { SetKeepaliveDelay(500); // 500ms of keepalive delay. CreateStunPort(kStunAddr1); PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); ASSERT_EQ(1U, port()->Candidates().size()); EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address())); SIMULATED_WAIT(false, 1000, fake_clock); @@ -416,7 +475,11 @@ TEST_F(StunPortTest, TestKeepAliveResponse) { TEST_F(StunPortTest, TestSharedSocketPrepareAddress) { CreateSharedUdpPort(kStunAddr1, nullptr); PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); ASSERT_EQ(1U, port()->Candidates().size()); EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address())); } @@ -428,7 +491,10 @@ TEST_F(StunPortTestWithRealClock, TestSharedSocketPrepareAddressInvalidHostname) { CreateSharedUdpPort(kBadHostnameAddr, nullptr); PrepareAddress(); - EXPECT_TRUE_WAIT(done(), kTimeoutMs); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs)}), + webrtc::IsRtcOk()); ASSERT_EQ(1U, port()->Candidates().size()); EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address())); @@ -444,7 +510,11 @@ TEST_F(StunPortTestWithRealClock, TEST_F(StunPortTest, TestStunCandidateDiscardedWithMdnsObfuscationNotEnabled) { CreateSharedUdpPort(kStunAddr1, nullptr); PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); ASSERT_EQ(1U, port()->Candidates().size()); EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address())); EXPECT_TRUE(port()->Candidates()[0].is_local()); @@ -456,7 +526,11 @@ TEST_F(StunPortTest, TestStunCandidateGeneratedWithMdnsObfuscationEnabled) { EnableMdnsObfuscation(); CreateSharedUdpPort(kStunAddr1, nullptr); PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); ASSERT_EQ(2U, port()->Candidates().size()); // The addresses of the candidates are both equal to kLocalAddr. @@ -483,7 +557,11 @@ TEST_F(StunPortTest, TestNoDuplicatedAddressWithTwoStunServers) { CreateStunPort(stun_servers); EXPECT_EQ(IceCandidateType::kSrflx, port()->Type()); PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(1U, port()->Candidates().size()); EXPECT_EQ(port()->Candidates()[0].relay_protocol(), ""); } @@ -497,11 +575,18 @@ TEST_F(StunPortTest, TestMultipleStunServersWithBadServer) { CreateStunPort(stun_servers); EXPECT_EQ(IceCandidateType::kSrflx, port()->Type()); PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(1U, port()->Candidates().size()); std::string server_url = "stun:" + kBadAddr.ToString(); - ASSERT_EQ_SIMULATED_WAIT(error_event_.url, server_url, kTimeoutMs, - fake_clock); + ASSERT_THAT( + webrtc::WaitUntil([&] { return error_event_.url; }, Eq(server_url), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); } // Test that two candidates are allocated if the two STUN servers return @@ -518,7 +603,11 @@ TEST_F(StunPortTest, TestTwoCandidatesWithTwoStunServersAcrossNat) { CreateStunPort(stun_servers); EXPECT_EQ(IceCandidateType::kSrflx, port()->Type()); PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(2U, port()->Candidates().size()); EXPECT_EQ(port()->Candidates()[0].relay_protocol(), ""); EXPECT_EQ(port()->Candidates()[1].relay_protocol(), ""); @@ -567,9 +656,16 @@ TEST_F(StunPortTest, TestStunBindingRequestShortLifetime) { SetKeepaliveLifetime(100); CreateStunPort(kStunAddr1); PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); - EXPECT_TRUE_SIMULATED_WAIT(!HasPendingRequest(cricket::STUN_BINDING_REQUEST), - 2000, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return !HasPendingRequest(cricket::STUN_BINDING_REQUEST); }, + IsTrue(), {.clock = &fake_clock}), + webrtc::IsRtcOk()); } // Test that by default, the STUN binding requests will last for a long time. @@ -577,9 +673,16 @@ TEST_F(StunPortTest, TestStunBindingRequestLongLifetime) { SetKeepaliveDelay(101); CreateStunPort(kStunAddr1); PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); - EXPECT_TRUE_SIMULATED_WAIT(HasPendingRequest(cricket::STUN_BINDING_REQUEST), - 1000, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return HasPendingRequest(cricket::STUN_BINDING_REQUEST); }, + IsTrue(), {.clock = &fake_clock}), + webrtc::IsRtcOk()); } class MockAsyncPacketSocket : public rtc::AsyncPacketSocket { @@ -621,10 +724,9 @@ TEST_F(StunPortTest, TestStunPacketsHaveDscpPacketOption) { EXPECT_CALL(*socket, SetOption(_, _)).WillRepeatedly(Return(0)); // If DSCP is not set on the socket, stun packets should have no value. - EXPECT_CALL(*socket, - SendTo(_, _, _, - ::testing::Field(&rtc::PacketOptions::dscp, - ::testing::Eq(rtc::DSCP_NO_CHANGE)))) + EXPECT_CALL(*socket, SendTo(_, _, _, + ::testing::Field(&rtc::PacketOptions::dscp, + Eq(rtc::DSCP_NO_CHANGE)))) .WillOnce(Return(100)); PrepareAddress(); @@ -632,9 +734,13 @@ TEST_F(StunPortTest, TestStunPacketsHaveDscpPacketOption) { port()->SetOption(rtc::Socket::OPT_DSCP, rtc::DSCP_AF41); EXPECT_CALL(*socket, SendTo(_, _, _, ::testing::Field(&rtc::PacketOptions::dscp, - ::testing::Eq(rtc::DSCP_AF41)))) + Eq(rtc::DSCP_AF41)))) .WillRepeatedly(Return(100)); - EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); } class StunIPv6PortTestBase : public StunPortTestBase { @@ -661,7 +767,11 @@ class StunIPv6PortTest : public FakeClockBase, public StunIPv6PortTestBase {}; TEST_F(StunIPv6PortTest, TestPrepareAddress) { CreateStunPort(kIPv6StunAddr1); PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); ASSERT_EQ(1U, port()->Candidates().size()); EXPECT_TRUE(kIPv6LocalAddr.EqualIPs(port()->Candidates()[0].address())); std::string expected_server_url = "stun:::1:5000"; @@ -672,12 +782,19 @@ TEST_F(StunIPv6PortTest, TestPrepareAddress) { TEST_F(StunIPv6PortTest, TestPrepareAddressFail) { CreateStunPort(kIPv6BadAddr); PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(error()); EXPECT_EQ(0U, port()->Candidates().size()); - EXPECT_EQ_SIMULATED_WAIT(error_event_.error_code, - cricket::STUN_ERROR_SERVER_NOT_REACHABLE, kTimeoutMs, - fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return error_event_.error_code; }, + Eq(cricket::STUN_ERROR_SERVER_NOT_REACHABLE), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_NE(error_event_.error_text.find('.'), std::string::npos); EXPECT_NE( error_event_.address.find(kIPv6LocalAddr.HostAsSensitiveURIString()), @@ -691,7 +808,11 @@ TEST_F(StunIPv6PortTest, TestPrepareAddressFail) { TEST_F(StunIPv6PortTest, TestServerAddressFamilyMismatch) { CreateStunPort(kStunAddr1); PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(error()); EXPECT_EQ(0U, port()->Candidates().size()); EXPECT_EQ(0, error_event_.error_code); @@ -701,11 +822,17 @@ TEST_F(StunIPv6PortTest, TestServerAddressFamilyMismatch) { TEST_F(StunIPv6PortTestWithRealClock, TestPrepareAddressHostnameFail) { CreateStunPort(kBadHostnameAddr); PrepareAddress(); - EXPECT_TRUE_WAIT(done(), kTimeoutMs); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs)}), + webrtc::IsRtcOk()); EXPECT_TRUE(error()); EXPECT_EQ(0U, port()->Candidates().size()); - EXPECT_EQ_WAIT(error_event_.error_code, - cricket::STUN_ERROR_SERVER_NOT_REACHABLE, kTimeoutMs); + EXPECT_THAT( + webrtc::WaitUntil([&] { return error_event_.error_code; }, + Eq(cricket::STUN_ERROR_SERVER_NOT_REACHABLE), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs)}), + webrtc::IsRtcOk()); } class StunIPv6PortTestWithMockDnsResolver : public StunIPv6PortTest { @@ -745,7 +872,11 @@ TEST_F(StunIPv6PortTestWithMockDnsResolver, TestPrepareAddressHostname) { }); CreateStunPort(kValidHostnameAddr); PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); ASSERT_EQ(1U, port()->Candidates().size()); EXPECT_TRUE(kIPv6LocalAddr.EqualIPs(port()->Candidates()[0].address())); EXPECT_EQ(kIPv6StunCandidatePriority, port()->Candidates()[0].priority()); @@ -772,7 +903,11 @@ TEST_F(StunIPv6PortTestWithMockDnsResolver, }); CreateStunPort(kValidHostnameAddr, &field_trials); PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return done(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); ASSERT_EQ(1U, port()->Candidates().size()); EXPECT_TRUE(kIPv6LocalAddr.EqualIPs(port()->Candidates()[0].address())); EXPECT_EQ(kIPv6StunCandidatePriority + (cricket::kMaxTurnServers << 8), diff --git a/p2p/base/stun_request_unittest.cc b/p2p/base/stun_request_unittest.cc index 188ffbfdd5..8cb8bbe8d0 100644 --- a/p2p/base/stun_request_unittest.cc +++ b/p2p/base/stun_request_unittest.cc @@ -10,18 +10,28 @@ #include "p2p/base/stun_request.h" -#include +#include +#include +#include #include -#include "rtc_base/crypto_random.h" +#include "api/test/rtc_error_matchers.h" +#include "api/transport/stun.h" +#include "api/units/time_delta.h" #include "rtc_base/fake_clock.h" #include "rtc_base/gunit.h" #include "rtc_base/logging.h" +#include "rtc_base/thread.h" #include "rtc_base/time_utils.h" +#include "test/gmock.h" #include "test/gtest.h" +#include "test/wait_until.h" namespace cricket { namespace { + +using ::testing::Ne; + std::unique_ptr CreateStunMessage( StunMessageType type, const StunMessage* req = nullptr) { @@ -149,8 +159,11 @@ TEST_F(StunRequestTest, TestBackoff) { int64_t start = rtc::TimeMillis(); manager_.Send(request); for (int i = 0; i < 9; ++i) { - EXPECT_TRUE_SIMULATED_WAIT(request_count_ != i, STUN_TOTAL_TIMEOUT, - fake_clock); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return request_count_; }, Ne(i), + {.timeout = webrtc::TimeDelta::Millis(STUN_TOTAL_TIMEOUT), + .clock = &fake_clock}), + webrtc::IsRtcOk()); int64_t elapsed = rtc::TimeMillis() - start; RTC_DLOG(LS_INFO) << "STUN request #" << (i + 1) << " sent at " << elapsed << " ms"; diff --git a/p2p/base/tcp_port_unittest.cc b/p2p/base/tcp_port_unittest.cc index 9adda3b6c9..81d6e89572 100644 --- a/p2p/base/tcp_port_unittest.cc +++ b/p2p/base/tcp_port_unittest.cc @@ -10,23 +10,36 @@ #include "p2p/base/tcp_port.h" +#include #include #include +#include #include +#include "api/candidate.h" +#include "api/test/rtc_error_matchers.h" +#include "api/units/time_delta.h" #include "p2p/base/basic_packet_socket_factory.h" +#include "p2p/base/connection.h" #include "p2p/base/p2p_constants.h" +#include "p2p/base/port.h" #include "p2p/base/transport_description.h" +#include "rtc_base/async_packet_socket.h" +#include "rtc_base/checks.h" #include "rtc_base/crypto_random.h" -#include "rtc_base/gunit.h" #include "rtc_base/ip_address.h" +#include "rtc_base/network.h" +#include "rtc_base/network/sent_packet.h" +#include "rtc_base/socket.h" #include "rtc_base/socket_address.h" #include "rtc_base/third_party/sigslot/sigslot.h" #include "rtc_base/thread.h" #include "rtc_base/time_utils.h" #include "rtc_base/virtual_socket_server.h" +#include "test/gmock.h" #include "test/gtest.h" #include "test/scoped_key_value_config.h" +#include "test/wait_until.h" using cricket::Connection; using cricket::ICE_PWD_LENGTH; @@ -34,6 +47,8 @@ using cricket::ICE_UFRAG_LENGTH; using cricket::Port; using cricket::TCPPort; using rtc::SocketAddress; +using ::testing::Eq; +using ::testing::IsTrue; static int kTimeout = 1000; static const SocketAddress kLocalAddr("11.11.11.11", 0); @@ -135,7 +150,10 @@ TEST_F(TCPPortTest, TestTCPPortWithLocalhostAddress) { remote_port->PrepareAddress(); Connection* conn = local_port->CreateConnection(remote_port->Candidates()[0], Port::ORIGIN_MESSAGE); - EXPECT_TRUE_WAIT(conn->connected(), kTimeout); + EXPECT_THAT( + webrtc::WaitUntil([&] { return conn->connected(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeout)}), + webrtc::IsRtcOk()); // Verify that the socket actually used localhost, otherwise this test isn't // doing what it meant to. ASSERT_EQ(local_address.ipaddr(), @@ -164,7 +182,10 @@ TEST_F(TCPPortTest, TCPPortDiscardedIfBoundAddressDoesNotMatchNetwork) { Connection* conn = local_port->CreateConnection(remote_port->Candidates()[0], Port::ORIGIN_MESSAGE); ConnectionObserver observer(conn); - EXPECT_TRUE_WAIT(observer.connection_destroyed(), kTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return observer.connection_destroyed(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeout)}), + webrtc::IsRtcOk()); } // A caveat for the above logic: if the socket ends up bound to one of the IPs @@ -189,7 +210,10 @@ TEST_F(TCPPortTest, TCPPortNotDiscardedIfNotBoundToBestIP) { // Expect connection to succeed. Connection* conn = local_port->CreateConnection(remote_port->Candidates()[0], Port::ORIGIN_MESSAGE); - EXPECT_TRUE_WAIT(conn->connected(), kTimeout); + EXPECT_THAT( + webrtc::WaitUntil([&] { return conn->connected(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeout)}), + webrtc::IsRtcOk()); // Verify that the socket actually used the alternate address, otherwise this // test isn't doing what it meant to. @@ -213,7 +237,10 @@ TEST_F(TCPPortTest, TCPPortNotDiscardedIfBoundToTemporaryIP) { Connection* conn = local_port->CreateConnection(remote_port->Candidates()[0], Port::ORIGIN_MESSAGE); ASSERT_NE(nullptr, conn); - EXPECT_TRUE_WAIT(conn->connected(), kTimeout); + EXPECT_THAT( + webrtc::WaitUntil([&] { return conn->connected(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeout)}), + webrtc::IsRtcOk()); } class SentPacketCounter : public sigslot::has_slots<> { @@ -243,7 +270,10 @@ TEST_F(TCPPortTest, SignalSentPacket) { Connection* client_conn = client->CreateConnection(server->Candidates()[0], Port::ORIGIN_MESSAGE); ASSERT_NE(nullptr, client_conn); - ASSERT_TRUE_WAIT(client_conn->connected(), kTimeout); + ASSERT_THAT( + webrtc::WaitUntil([&] { return client_conn->connected(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeout)}), + webrtc::IsRtcOk()); // Need to get the port of the actual outgoing socket, not the server socket.. cricket::Candidate client_candidate = client->Candidates()[0]; @@ -253,12 +283,21 @@ TEST_F(TCPPortTest, SignalSentPacket) { Connection* server_conn = server->CreateConnection(client_candidate, Port::ORIGIN_THIS_PORT); ASSERT_NE(nullptr, server_conn); - ASSERT_TRUE_WAIT(server_conn->connected(), kTimeout); + ASSERT_THAT( + webrtc::WaitUntil([&] { return server_conn->connected(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeout)}), + webrtc::IsRtcOk()); client_conn->Ping(rtc::TimeMillis()); server_conn->Ping(rtc::TimeMillis()); - ASSERT_TRUE_WAIT(client_conn->writable(), kTimeout); - ASSERT_TRUE_WAIT(server_conn->writable(), kTimeout); + ASSERT_THAT( + webrtc::WaitUntil([&] { return client_conn->writable(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeout)}), + webrtc::IsRtcOk()); + ASSERT_THAT( + webrtc::WaitUntil([&] { return server_conn->writable(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeout)}), + webrtc::IsRtcOk()); SentPacketCounter client_counter(client.get()); SentPacketCounter server_counter(server.get()); @@ -267,8 +306,14 @@ TEST_F(TCPPortTest, SignalSentPacket) { client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions()); server_conn->Send(&kData, sizeof(kData), rtc::PacketOptions()); } - EXPECT_EQ_WAIT(10, client_counter.sent_packets(), kTimeout); - EXPECT_EQ_WAIT(10, server_counter.sent_packets(), kTimeout); + EXPECT_THAT( + webrtc::WaitUntil([&] { return client_counter.sent_packets(); }, Eq(10), + {.timeout = webrtc::TimeDelta::Millis(kTimeout)}), + webrtc::IsRtcOk()); + EXPECT_THAT( + webrtc::WaitUntil([&] { return server_counter.sent_packets(); }, Eq(10), + {.timeout = webrtc::TimeDelta::Millis(kTimeout)}), + webrtc::IsRtcOk()); } // Test that SignalSentPacket is fired when a packet is successfully sent, even @@ -287,7 +332,10 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) { Connection* client_conn = client->CreateConnection(server->Candidates()[0], Port::ORIGIN_MESSAGE); ASSERT_NE(nullptr, client_conn); - ASSERT_TRUE_WAIT(client_conn->connected(), kTimeout); + ASSERT_THAT( + webrtc::WaitUntil([&] { return client_conn->connected(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeout)}), + webrtc::IsRtcOk()); // Need to get the port of the actual outgoing socket. cricket::Candidate client_candidate = client->Candidates()[0]; @@ -297,10 +345,16 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) { client_candidate.set_tcptype(""); Connection* server_conn = server->CreateConnection(client_candidate, Port::ORIGIN_THIS_PORT); - ASSERT_TRUE_WAIT(server_conn->connected(), kTimeout); + ASSERT_THAT( + webrtc::WaitUntil([&] { return server_conn->connected(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeout)}), + webrtc::IsRtcOk()); EXPECT_FALSE(client_conn->writable()); client_conn->Ping(rtc::TimeMillis()); - ASSERT_TRUE_WAIT(client_conn->writable(), kTimeout); + ASSERT_THAT( + webrtc::WaitUntil([&] { return client_conn->writable(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeout)}), + webrtc::IsRtcOk()); SentPacketCounter client_counter(client.get()); static const char kData[] = "hello"; @@ -310,7 +364,10 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) { // Deleting the server port should break the current connection. server = nullptr; server_conn = nullptr; - ASSERT_TRUE_WAIT(!client_conn->connected(), kTimeout); + ASSERT_THAT( + webrtc::WaitUntil([&] { return !client_conn->connected(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeout)}), + webrtc::IsRtcOk()); // Recreate the server port with the same port number. server = CreateTCPPort(kRemoteAddr, /*allow_listen=*/true, kServerPort); @@ -321,7 +378,10 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) { // packet will be discarded. result = client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions()); EXPECT_EQ(result, SOCKET_ERROR); - ASSERT_TRUE_WAIT(client_conn->connected(), kTimeout); + ASSERT_THAT( + webrtc::WaitUntil([&] { return client_conn->connected(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeout)}), + webrtc::IsRtcOk()); // For unknown reasons, connection is still supposed to be writable.... EXPECT_TRUE(client_conn->writable()); for (int i = 0; i < 10; ++i) { @@ -330,7 +390,10 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) { SOCKET_ERROR); } // And are not reported as sent. - EXPECT_EQ_WAIT(client_counter.sent_packets(), 1, kTimeout); + EXPECT_THAT( + webrtc::WaitUntil([&] { return client_counter.sent_packets(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kTimeout)}), + webrtc::IsRtcOk()); // Create the server connection again so server can reply to STUN pings. // Client outgoing socket port will have changed since the client create a new @@ -342,13 +405,22 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) { client_candidate.set_tcptype(""); server_conn = server->CreateConnection(client_candidate, Port::ORIGIN_THIS_PORT); - ASSERT_TRUE_WAIT(server_conn->connected(), kTimeout); - EXPECT_EQ_WAIT(client_counter.sent_packets(), 1, kTimeout); + ASSERT_THAT( + webrtc::WaitUntil([&] { return server_conn->connected(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeout)}), + webrtc::IsRtcOk()); + EXPECT_THAT( + webrtc::WaitUntil([&] { return client_counter.sent_packets(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kTimeout)}), + webrtc::IsRtcOk()); // Send Stun Binding request. client_conn->Ping(rtc::TimeMillis()); // The Stun Binding request is reported as sent. - EXPECT_EQ_WAIT(client_counter.sent_packets(), 2, kTimeout); + EXPECT_THAT( + webrtc::WaitUntil([&] { return client_counter.sent_packets(); }, Eq(2), + {.timeout = webrtc::TimeDelta::Millis(kTimeout)}), + webrtc::IsRtcOk()); // Wait a bit for the Stun response to be received. rtc::Thread::Current()->ProcessMessages(100); @@ -358,5 +430,8 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) { EXPECT_EQ(client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions()), 6); } - EXPECT_EQ_WAIT(client_counter.sent_packets(), 2 + 5, kTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return client_counter.sent_packets(); }, Eq(2 + 5), + {.timeout = webrtc::TimeDelta::Millis(kTimeout)}), + webrtc::IsRtcOk()); } diff --git a/p2p/base/turn_port_unittest.cc b/p2p/base/turn_port_unittest.cc index d1f97099a8..f081529281 100644 --- a/p2p/base/turn_port_unittest.cc +++ b/p2p/base/turn_port_unittest.cc @@ -7,10 +7,29 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ +#include #include +#include +#include "absl/functional/any_invocable.h" #include "api/array_view.h" +#include "api/candidate.h" +#include "api/test/mock_async_dns_resolver.h" +#include "api/test/rtc_error_matchers.h" +#include "api/transport/stun.h" +#include "p2p/base/connection_info.h" +#include "p2p/base/port.h" +#include "p2p/base/port_interface.h" +#include "p2p/base/stun_request.h" +#include "p2p/client/relay_port_factory_interface.h" +#include "rtc_base/async_packet_socket.h" +#include "rtc_base/ip_address.h" +#include "rtc_base/net_helpers.h" +#include "rtc_base/network.h" #include "rtc_base/network/received_packet.h" +#include "rtc_base/third_party/sigslot/sigslot.h" +#include "test/gmock.h" +#include "test/wait_until.h" #if defined(WEBRTC_POSIX) #include @@ -54,6 +73,9 @@ using rtc::SocketAddress; using ::testing::_; using ::testing::DoAll; +using ::testing::Eq; +using ::testing::IsTrue; +using ::testing::Ne; using ::testing::Return; using ::testing::ReturnPointee; using ::testing::SetArgPointee; @@ -384,12 +406,19 @@ class TurnPortTest : public ::testing::Test, // turn_port_ should have been created. ASSERT_TRUE(turn_port_ != nullptr); turn_port_->PrepareAddress(); - ASSERT_TRUE_SIMULATED_WAIT( - turn_ready_, TimeToGetTurnCandidate(protocol_type), fake_clock_); + ASSERT_THAT(webrtc::WaitUntil([&] { return turn_ready_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis( + TimeToGetTurnCandidate(protocol_type)), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); CreateUdpPort(); udp_port_->PrepareAddress(); - ASSERT_TRUE_SIMULATED_WAIT(udp_ready_, kSimulatedRtt, fake_clock_); + ASSERT_THAT( + webrtc::WaitUntil([&] { return udp_ready_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); } // Returns the fake clock time to establish a connection over the given @@ -453,7 +482,11 @@ class TurnPortTest : public ::testing::Test, void TestTurnAllocateSucceeds(unsigned int timeout) { ASSERT_TRUE(turn_port_); turn_port_->PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, timeout, fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil([&] { return turn_ready_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(timeout), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); ASSERT_EQ(1U, turn_port_->Candidates().size()); EXPECT_EQ(kTurnUdpExtAddr.ipaddr(), turn_port_->Candidates()[0].address().ipaddr()); @@ -464,8 +497,11 @@ class TurnPortTest : public ::testing::Test, absl::string_view expected_url) { ASSERT_TRUE(turn_port_); turn_port_->PrepareAddress(); - ASSERT_TRUE_SIMULATED_WAIT( - turn_ready_, TimeToGetTurnCandidate(protocol_type), fake_clock_); + ASSERT_THAT(webrtc::WaitUntil([&] { return turn_ready_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis( + TimeToGetTurnCandidate(protocol_type)), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); ASSERT_EQ(1U, turn_port_->Candidates().size()); EXPECT_EQ(turn_port_->Candidates()[0].url(), expected_url); } @@ -486,9 +522,12 @@ class TurnPortTest : public ::testing::Test, const SocketAddress old_addr = turn_port_->server_address().address; turn_port_->PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, - TimeToGetAlternateTurnCandidate(protocol_type), - fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil([&] { return turn_ready_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis( + TimeToGetAlternateTurnCandidate(protocol_type)), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); // Retrieve the address again, the turn port's address should be // changed. const SocketAddress new_addr = turn_port_->server_address().address; @@ -511,8 +550,12 @@ class TurnPortTest : public ::testing::Test, turn_port_->PrepareAddress(); // Need time to connect to TURN server, send Allocate request and receive // redirect notice. - EXPECT_TRUE_SIMULATED_WAIT( - turn_error_, kSimulatedRtt + TimeToConnect(protocol_type), fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil([&] { return turn_error_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis( + kSimulatedRtt + TimeToConnect(protocol_type)), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); } void TestTurnAlternateServerPingPong(ProtocolType protocol_type) { @@ -529,9 +572,12 @@ class TurnPortTest : public ::testing::Test, ProtocolAddress(kTurnIntAddr, protocol_type)); turn_port_->PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(turn_error_, - TimeToGetAlternateTurnCandidate(protocol_type), - fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil([&] { return turn_error_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis( + TimeToGetAlternateTurnCandidate(protocol_type)), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); ASSERT_EQ(0U, turn_port_->Candidates().size()); rtc::SocketAddress address; // Verify that we have exhausted all alternate servers instead of @@ -553,9 +599,12 @@ class TurnPortTest : public ::testing::Test, ProtocolAddress(kTurnIntAddr, protocol_type)); turn_port_->PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(turn_error_, - TimeToGetAlternateTurnCandidate(protocol_type), - fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil([&] { return turn_error_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis( + TimeToGetAlternateTurnCandidate(protocol_type)), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); ASSERT_EQ(0U, turn_port_->Candidates().size()); } @@ -593,8 +642,11 @@ class TurnPortTest : public ::testing::Test, ProtocolAddress(server_address, protocol_type)); turn_port_->PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT( - turn_error_, TimeToGetTurnCandidate(protocol_type), fake_clock_); + EXPECT_THAT(webrtc::WaitUntil([&] { return turn_error_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis( + TimeToGetTurnCandidate(protocol_type)), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); // Wait for some extra time, and make sure no packets were received on the // loopback port we created (or in the case of TCP, no connection attempt @@ -629,21 +681,32 @@ class TurnPortTest : public ::testing::Test, Connection* conn2 = turn_port_->CreateConnection(udp_port_->Candidates()[0], Port::ORIGIN_MESSAGE); ASSERT_TRUE(conn2 != NULL); - ASSERT_TRUE_SIMULATED_WAIT(turn_create_permission_success_, kSimulatedRtt, - fake_clock_); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return turn_create_permission_success_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); conn2->Ping(0); // Two hops from TURN port to UDP port through TURN server, thus two RTTs. - EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn2->write_state(), - kSimulatedRtt * 2, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return conn2->write_state(); }, + Eq(Connection::STATE_WRITABLE), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); EXPECT_TRUE(conn1->receiving()); EXPECT_TRUE(conn2->receiving()); EXPECT_EQ(Connection::STATE_WRITE_INIT, conn1->write_state()); // Send another ping from UDP to TURN. conn1->Ping(0); - EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn1->write_state(), - kSimulatedRtt * 2, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return conn1->write_state(); }, + Eq(Connection::STATE_WRITABLE), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); EXPECT_TRUE(conn2->receiving()); } @@ -661,12 +724,19 @@ class TurnPortTest : public ::testing::Test, turn_port_->set_timeout_delay(10 * 60 * 1000); ASSERT_TRUE(conn2 != NULL); - ASSERT_TRUE_SIMULATED_WAIT(turn_create_permission_success_, kSimulatedRtt, - fake_clock_); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return turn_create_permission_success_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); // Make sure turn connection can receive. conn1->Ping(0); - EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn1->write_state(), - kSimulatedRtt * 2, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return conn1->write_state(); }, + Eq(Connection::STATE_WRITABLE), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); EXPECT_FALSE(turn_unknown_address_); // Destroy the connection on the TURN port. The TurnEntry still exists, so @@ -674,8 +744,11 @@ class TurnPortTest : public ::testing::Test, turn_port_->DestroyConnection(conn2); conn1->Ping(0); - EXPECT_TRUE_SIMULATED_WAIT(turn_unknown_address_, kSimulatedRtt, - fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil([&] { return turn_unknown_address_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); // Wait for TurnEntry to expire. Timeout is 5 minutes. // Expect that it still processes an incoming ping and signals the @@ -707,14 +780,21 @@ class TurnPortTest : public ::testing::Test, conn1->set_remote_password_for_test(pwd); conn1->Ping(0); - EXPECT_TRUE_SIMULATED_WAIT(turn_unknown_address_, kSimulatedRtt, - fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil([&] { return turn_unknown_address_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); // If the connection is created again, it will start to receive pings. conn2 = turn_port_->CreateConnection(udp_port_->Candidates()[0], Port::ORIGIN_MESSAGE); conn1->Ping(0); - EXPECT_TRUE_SIMULATED_WAIT(conn2->receiving(), kSimulatedRtt, fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil([&] { return conn2->receiving(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); } void TestTurnSendData(ProtocolType protocol_type) { @@ -742,11 +822,19 @@ class TurnPortTest : public ::testing::Test, conn2->SignalDestroyed.connect(this, &TurnPortTest::OnConnectionSignalDestroyed); conn1->Ping(0); - EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn1->write_state(), - kSimulatedRtt * 2, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return conn1->write_state(); }, + Eq(Connection::STATE_WRITABLE), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); conn2->Ping(0); - EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn2->write_state(), - kSimulatedRtt * 2, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return conn2->write_state(); }, + Eq(Connection::STATE_WRITABLE), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); // Send some data. size_t num_packets = 256; @@ -774,8 +862,12 @@ class TurnPortTest : public ::testing::Test, void TestTurnReleaseAllocation(ProtocolType protocol_type) { PrepareTurnAndUdpPorts(protocol_type); turn_port_.reset(); - EXPECT_EQ_SIMULATED_WAIT(0U, turn_server_.server()->allocations().size(), - kSimulatedRtt, fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return turn_server_.server()->allocations().size(); }, Eq(0U), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); } // Test that the TURN allocation is released by sending a refresh request @@ -806,11 +898,19 @@ class TurnPortTest : public ::testing::Test, &TurnPortTest::OnConnectionSignalDestroyed); conn1->Ping(0); - EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn1->write_state(), - kSimulatedRtt * 2, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return conn1->write_state(); }, + Eq(Connection::STATE_WRITABLE), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); conn2->Ping(0); - EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn2->write_state(), - kSimulatedRtt * 2, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return conn2->write_state(); }, + Eq(Connection::STATE_WRITABLE), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); // Send some data from Udp to TurnPort. unsigned char buf[256] = {0}; @@ -821,7 +921,11 @@ class TurnPortTest : public ::testing::Test, turn_port_->Release(); // Wait for the TurnPort to signal closed. - ASSERT_TRUE_SIMULATED_WAIT(turn_port_closed_, kSimulatedRtt, fake_clock_); + ASSERT_THAT( + webrtc::WaitUntil([&] { return turn_port_closed_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); // But the data should have arrived first. ASSERT_EQ(1ul, turn_packets_.size()); @@ -908,7 +1012,10 @@ TEST_F(TurnPortTest, TestReconstructedServerUrlForHostname) { // As VSS doesn't provide DNS resolution, name resolve will fail, // the error will be set and contain the url. turn_port_->PrepareAddress(); - EXPECT_TRUE_WAIT(turn_error_, kResolverTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_error_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kResolverTimeout)}), + webrtc::IsRtcOk()); std::string server_url = "turn:" + kTurnInvalidAddr.ToString() + "?transport=udp"; ASSERT_EQ(error_event_.url, server_url); @@ -963,10 +1070,18 @@ TEST_F(TurnPortTest, TestTurnAllocateWithoutLoggingId) { TEST_F(TurnPortTest, TestTurnBadCredentials) { CreateTurnPort(kTurnUsername, "bad", kTurnUdpProtoAddr); turn_port_->PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(turn_error_, kSimulatedRtt * 3, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_error_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 3), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); ASSERT_EQ(0U, turn_port_->Candidates().size()); - EXPECT_EQ_SIMULATED_WAIT(error_event_.error_code, STUN_ERROR_UNAUTHORIZED, - kSimulatedRtt * 3, fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return error_event_.error_code; }, Eq(STUN_ERROR_UNAUTHORIZED), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 3), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); EXPECT_EQ(error_event_.error_text, "Unauthorized"); } @@ -975,7 +1090,11 @@ TEST_F(TurnPortTest, TestTurnBadCredentials) { TEST_F(TurnPortTest, TestServerAddressFamilyMismatch) { CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpIPv6ProtoAddr); turn_port_->PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(turn_error_, kSimulatedRtt * 3, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_error_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 3), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); ASSERT_EQ(0U, turn_port_->Candidates().size()); EXPECT_EQ(0, error_event_.error_code); } @@ -986,7 +1105,11 @@ TEST_F(TurnPortTest, TestServerAddressFamilyMismatch6) { CreateTurnPort(kLocalIPv6Addr, kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); turn_port_->PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(turn_error_, kSimulatedRtt * 3, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_error_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 3), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); ASSERT_EQ(0U, turn_port_->Candidates().size()); EXPECT_EQ(0, error_event_.error_code); } @@ -1039,10 +1162,17 @@ TEST_F(TurnPortTest, // Shouldn't take more than 1 RTT to realize the bound address isn't the one // expected. - EXPECT_TRUE_SIMULATED_WAIT(turn_error_, kSimulatedRtt, fake_clock_); - EXPECT_EQ_SIMULATED_WAIT(error_event_.error_code, - STUN_ERROR_SERVER_NOT_REACHABLE, kSimulatedRtt, - fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil([&] { return turn_error_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); + EXPECT_THAT( + webrtc::WaitUntil([&] { return error_event_.error_code; }, + Eq(STUN_ERROR_SERVER_NOT_REACHABLE), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); EXPECT_NE(error_event_.error_text.find('.'), std::string::npos); EXPECT_NE(error_event_.address.find(kLocalAddr2.HostAsSensitiveURIString()), std::string::npos); @@ -1074,7 +1204,11 @@ TEST_F(TurnPortTest, TurnTcpAllocationNotDiscardedIfNotBoundToBestIP) { turn_port_->PrepareAddress(); // Candidate should be gathered as normally. - EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 3, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_ready_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 3), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); ASSERT_EQ(1U, turn_port_->Candidates().size()); // Verify that the socket actually used the alternate address, otherwise this @@ -1101,7 +1235,11 @@ TEST_F(TurnPortTest, TCPPortNotDiscardedIfBoundToTemporaryIP) { turn_port_->PrepareAddress(); // Candidate should be gathered as normally. - EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 3, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_ready_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 3), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); ASSERT_EQ(1U, turn_port_->Candidates().size()); } @@ -1112,14 +1250,20 @@ TEST_F(TurnPortTest, TestTurnTcpOnAddressResolveFailure) { CreateTurnPort(kTurnUsername, kTurnPassword, ProtocolAddress(kTurnInvalidAddr, PROTO_TCP)); turn_port_->PrepareAddress(); - EXPECT_TRUE_WAIT(turn_error_, kResolverTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_error_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kResolverTimeout)}), + webrtc::IsRtcOk()); // As VSS doesn't provide DNS resolution, name resolve will fail. TurnPort // will proceed in creating a TCP socket which will fail as there is no // server on the above domain and error will be set to SOCKET_ERROR. EXPECT_EQ(SOCKET_ERROR, turn_port_->error()); - EXPECT_EQ_SIMULATED_WAIT(error_event_.error_code, - STUN_ERROR_SERVER_NOT_REACHABLE, kSimulatedRtt, - fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil([&] { return error_event_.error_code; }, + Eq(STUN_ERROR_SERVER_NOT_REACHABLE), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); std::string server_url = "turn:" + kTurnInvalidAddr.ToString() + "?transport=tcp"; ASSERT_EQ(error_event_.url, server_url); @@ -1132,7 +1276,10 @@ TEST_F(TurnPortTest, TestTurnTlsOnAddressResolveFailure) { CreateTurnPort(kTurnUsername, kTurnPassword, ProtocolAddress(kTurnInvalidAddr, PROTO_TLS)); turn_port_->PrepareAddress(); - EXPECT_TRUE_WAIT(turn_error_, kResolverTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_error_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kResolverTimeout)}), + webrtc::IsRtcOk()); EXPECT_EQ(SOCKET_ERROR, turn_port_->error()); } @@ -1142,7 +1289,10 @@ TEST_F(TurnPortTest, TestTurnUdpOnAddressResolveFailure) { CreateTurnPort(kTurnUsername, kTurnPassword, ProtocolAddress(kTurnInvalidAddr, PROTO_UDP)); turn_port_->PrepareAddress(); - EXPECT_TRUE_WAIT(turn_error_, kResolverTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_error_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kResolverTimeout)}), + webrtc::IsRtcOk()); // Error from turn port will not be socket error. EXPECT_NE(SOCKET_ERROR, turn_port_->error()); } @@ -1151,7 +1301,11 @@ TEST_F(TurnPortTest, TestTurnUdpOnAddressResolveFailure) { TEST_F(TurnPortTest, TestTurnAllocateBadPassword) { CreateTurnPort(kTurnUsername, "bad", kTurnUdpProtoAddr); turn_port_->PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(turn_error_, kSimulatedRtt * 2, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_error_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); ASSERT_EQ(0U, turn_port_->Candidates().size()); } @@ -1161,7 +1315,11 @@ TEST_F(TurnPortTest, TestTurnAllocateNonceResetAfterAllocateMismatch) { // Do a normal allocation first. CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); turn_port_->PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 2, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_ready_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); rtc::SocketAddress first_addr(turn_port_->socket()->GetLocalAddress()); // Destroy the turnport while keeping the drop probability to 1 to // suppress the release of the allocation at the server. @@ -1187,7 +1345,11 @@ TEST_F(TurnPortTest, TestTurnAllocateNonceResetAfterAllocateMismatch) { // Four round trips; first we'll get "stale nonce", then // "allocate mismatch", then "stale nonce" again, then finally it will // succeed. - EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 4, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_ready_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 4), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); EXPECT_NE(first_nonce, turn_port_->nonce()); } @@ -1197,7 +1359,11 @@ TEST_F(TurnPortTest, TestTurnAllocateMismatch) { // Do a normal allocation first. CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); turn_port_->PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 2, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_ready_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); rtc::SocketAddress first_addr(turn_port_->socket()->GetLocalAddress()); // Clear connected_ flag on turnport to suppress the release of @@ -1217,7 +1383,11 @@ TEST_F(TurnPortTest, TestTurnAllocateMismatch) { // Four round trips; first we'll get "stale nonce", then // "allocate mismatch", then "stale nonce" again, then finally it will // succeed. - EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 4, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_ready_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 4), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); // Verifies that the new port has a different address now. EXPECT_NE(first_addr, turn_port_->socket()->GetLocalAddress()); @@ -1237,7 +1407,11 @@ TEST_F(TurnPortTest, TestSharedSocketAllocateMismatch) { // Do a normal allocation first. CreateSharedTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); turn_port_->PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 2, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_ready_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); rtc::SocketAddress first_addr(turn_port_->socket()->GetLocalAddress()); // Clear connected_ flag on turnport to suppress the release of @@ -1253,7 +1427,11 @@ TEST_F(TurnPortTest, TestSharedSocketAllocateMismatch) { turn_port_->PrepareAddress(); // Extra 2 round trips due to allocate mismatch. - EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 4, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_ready_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 4), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); // Verifies that the new port has a different address now. EXPECT_NE(first_addr, turn_port_->socket()->GetLocalAddress()); @@ -1266,7 +1444,11 @@ TEST_F(TurnPortTest, TestTurnTcpAllocateMismatch) { // Do a normal allocation first. turn_port_->PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 3, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_ready_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 3), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); rtc::SocketAddress first_addr(turn_port_->socket()->GetLocalAddress()); // Clear connected_ flag on turnport to suppress the release of @@ -1284,7 +1466,11 @@ TEST_F(TurnPortTest, TestTurnTcpAllocateMismatch) { EXPECT_EQ(first_addr, turn_port_->socket()->GetLocalAddress()); // Extra 2 round trips due to allocate mismatch. - EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 5, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_ready_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 5), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); // Verifies that the new port has a different address now. EXPECT_NE(first_addr, turn_port_->socket()->GetLocalAddress()); @@ -1303,11 +1489,18 @@ TEST_F(TurnPortTest, TestRefreshRequestGetsErrorResponse) { // When this succeeds, it will schedule a new RefreshRequest with the bad // credential. turn_port_->request_manager().FlushForTest(TURN_REFRESH_REQUEST); - EXPECT_TRUE_SIMULATED_WAIT(turn_refresh_success_, kSimulatedRtt, fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil([&] { return turn_refresh_success_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); // Flush it again, it will receive a bad response. turn_port_->request_manager().FlushForTest(TURN_REFRESH_REQUEST); - EXPECT_TRUE_SIMULATED_WAIT(!turn_refresh_success_, kSimulatedRtt, - fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil([&] { return !turn_refresh_success_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); EXPECT_FALSE(turn_port_->connected()); EXPECT_TRUE(CheckAllConnectionsFailedAndPruned()); EXPECT_FALSE(turn_port_->HasRequests()); @@ -1326,8 +1519,12 @@ TEST_F(TurnPortTest, TestStopProcessingPacketsAfterClosed) { ASSERT_TRUE(conn2 != NULL); // Make sure conn2 is writable. conn2->Ping(0); - EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn2->write_state(), - kSimulatedRtt * 2, fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return conn2->write_state(); }, Eq(Connection::STATE_WRITABLE), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); turn_port_->CloseForTest(); SIMULATED_WAIT(false, kSimulatedRtt, fake_clock_); @@ -1367,8 +1564,12 @@ TEST_F(TurnPortTest, TestSocketCloseWillDestroyConnection) { EXPECT_NE(nullptr, conn); EXPECT_TRUE(!turn_port_->connections().empty()); turn_port_->socket()->NotifyClosedForTest(1); - EXPECT_TRUE_SIMULATED_WAIT(turn_port_->connections().empty(), - kConnectionDestructionDelay, fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return turn_port_->connections().empty(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kConnectionDestructionDelay), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); } // Test try-alternate-server feature. @@ -1511,8 +1712,11 @@ TEST_F(TurnPortTest, TestRefreshCreatePermissionRequest) { Connection* conn = turn_port_->CreateConnection(udp_port_->Candidates()[0], Port::ORIGIN_MESSAGE); ASSERT_TRUE(conn != NULL); - EXPECT_TRUE_SIMULATED_WAIT(turn_create_permission_success_, kSimulatedRtt, - fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_create_permission_success_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); turn_create_permission_success_ = false; // A create-permission-request should be pending. // After the next create-permission-response is received, it will schedule @@ -1520,12 +1724,18 @@ TEST_F(TurnPortTest, TestRefreshCreatePermissionRequest) { RelayCredentials bad_credentials("bad_user", "bad_pwd"); turn_port_->set_credentials(bad_credentials); turn_port_->request_manager().FlushForTest(kAllRequestsForTest); - EXPECT_TRUE_SIMULATED_WAIT(turn_create_permission_success_, kSimulatedRtt, - fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_create_permission_success_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); // Flush the requests again; the create-permission-request will fail. turn_port_->request_manager().FlushForTest(kAllRequestsForTest); - EXPECT_TRUE_SIMULATED_WAIT(!turn_create_permission_success_, kSimulatedRtt, - fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return !turn_create_permission_success_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); EXPECT_TRUE(CheckConnectionFailedAndPruned(conn)); } @@ -1540,7 +1750,11 @@ TEST_F(TurnPortTest, TestChannelBindGetErrorResponse) { ASSERT_TRUE(conn2 != nullptr); conn1->Ping(0); - EXPECT_TRUE_SIMULATED_WAIT(conn1->writable(), kSimulatedRtt * 2, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return conn1->writable(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); // Tell the TURN server to reject all bind requests from now on. turn_server_.server()->set_reject_bind_requests(true); @@ -1548,8 +1762,12 @@ TEST_F(TurnPortTest, TestChannelBindGetErrorResponse) { std::string data = "ABC"; conn1->Send(data.data(), data.length(), options); - EXPECT_TRUE_SIMULATED_WAIT(CheckConnectionFailedAndPruned(conn1), - kSimulatedRtt, fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil([&] { return CheckConnectionFailedAndPruned(conn1); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); // Verify that packets are allowed to be sent after a bind request error. // They'll just use a send indication instead. @@ -1561,7 +1779,11 @@ TEST_F(TurnPortTest, TestChannelBindGetErrorResponse) { rtc::Buffer(packet.payload().data(), packet.payload().size())); }); conn1->Send(data.data(), data.length(), options); - EXPECT_TRUE_SIMULATED_WAIT(!udp_packets_.empty(), kSimulatedRtt, fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil([&] { return !udp_packets_.empty(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); conn2->DeregisterReceivedPacketCallback(); } @@ -1597,7 +1819,11 @@ TEST_F(TurnPortTest, TestTurnLocalIPv6AddressServerIPv4) { CreateTurnPort(kLocalIPv6Addr, kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); turn_port_->PrepareAddress(); - ASSERT_TRUE_SIMULATED_WAIT(turn_error_, kSimulatedRtt, fake_clock_); + ASSERT_THAT( + webrtc::WaitUntil([&] { return turn_error_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); EXPECT_TRUE(turn_port_->Candidates().empty()); } @@ -1621,7 +1847,11 @@ TEST_F(TurnPortTest, TestCandidateAddressFamilyMatch) { CreateTurnPort(kLocalIPv6Addr, kTurnUsername, kTurnPassword, kTurnUdpIPv6ProtoAddr); turn_port_->PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 2, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_ready_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); ASSERT_EQ(1U, turn_port_->Candidates().size()); // Create an IPv4 candidate. It will match the TURN candidate. @@ -1647,11 +1877,19 @@ TEST_F(TurnPortTest, TestConnectionFailedAndPrunedOnCreatePermissionFailure) { turn_server_.server()->set_reject_private_addresses(true); CreateTurnPort(kTurnUsername, kTurnPassword, kTurnTcpProtoAddr); turn_port_->PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 3, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return turn_ready_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 3), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); CreateUdpPort(SocketAddress("10.0.0.10", 0)); udp_port_->PrepareAddress(); - EXPECT_TRUE_SIMULATED_WAIT(udp_ready_, kSimulatedRtt, fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil([&] { return udp_ready_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); // Create a connection. TestConnectionWrapper conn(turn_port_->CreateConnection( udp_port_->Candidates()[0], Port::ORIGIN_MESSAGE)); @@ -1659,10 +1897,18 @@ TEST_F(TurnPortTest, TestConnectionFailedAndPrunedOnCreatePermissionFailure) { // Asynchronously, CreatePermission request should be sent and fail, which // will make the connection pruned and failed. - EXPECT_TRUE_SIMULATED_WAIT(CheckConnectionFailedAndPruned(conn.connection()), - kSimulatedRtt, fake_clock_); - EXPECT_TRUE_SIMULATED_WAIT(!turn_create_permission_success_, kSimulatedRtt, - fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return CheckConnectionFailedAndPruned(conn.connection()); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return !turn_create_permission_success_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); // Check that the connection is not deleted asynchronously. SIMULATED_WAIT(conn.connection() == nullptr, kConnectionDestructionDelay, fake_clock_); @@ -1730,12 +1976,17 @@ TEST_F(TurnPortTest, TestResolverShutdown) { CreateTurnPort(kLocalIPv6Addr, kTurnUsername, kTurnPassword, ProtocolAddress(kTurnInvalidAddr, PROTO_UDP)); turn_port_->PrepareAddress(); - ASSERT_TRUE_WAIT(turn_error_, kResolverTimeout); + ASSERT_THAT(webrtc::WaitUntil( + [&] { return turn_error_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kResolverTimeout)}), + webrtc::IsRtcOk()); EXPECT_TRUE(turn_port_->Candidates().empty()); turn_port_.reset(); rtc::Thread::Current()->PostTask([this] { test_finish_ = true; }); // Waiting for above message to be processed. - ASSERT_TRUE_SIMULATED_WAIT(test_finish_, 1, fake_clock_); + ASSERT_THAT(webrtc::WaitUntil([&] { return test_finish_; }, IsTrue(), + {.clock = &fake_clock_}), + webrtc::IsRtcOk()); EXPECT_EQ(last_fd_count, GetFDCount()); } #endif @@ -1924,9 +2175,12 @@ TEST_F(TurnPortTest, TestTurnDangerousAlternateServer) { turn_port_->PrepareAddress(); // This should result in an error event. - EXPECT_TRUE_SIMULATED_WAIT(error_event_.error_code != 0, - TimeToGetAlternateTurnCandidate(protocol_type), - fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil([&] { return error_event_.error_code; }, Ne(0), + {.timeout = webrtc::TimeDelta::Millis( + TimeToGetAlternateTurnCandidate(protocol_type)), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); // but should NOT result in the port turning ready, and no candidates // should be gathered. EXPECT_FALSE(turn_ready_); diff --git a/p2p/client/basic_port_allocator_unittest.cc b/p2p/client/basic_port_allocator_unittest.cc index e68013e0fe..102612274c 100644 --- a/p2p/client/basic_port_allocator_unittest.cc +++ b/p2p/client/basic_port_allocator_unittest.cc @@ -10,12 +10,24 @@ #include "p2p/client/basic_port_allocator.h" +#include +#include +#include #include +#include +#include #include "absl/algorithm/container.h" #include "absl/strings/string_view.h" +#include "api/candidate.h" +#include "api/test/rtc_error_matchers.h" +#include "api/transport/enums.h" +#include "api/units/time_delta.h" #include "p2p/base/basic_packet_socket_factory.h" #include "p2p/base/p2p_constants.h" +#include "p2p/base/port.h" +#include "p2p/base/port_allocator.h" +#include "p2p/base/port_interface.h" #include "p2p/base/stun_port.h" #include "p2p/base/stun_request.h" #include "p2p/base/stun_server.h" @@ -32,24 +44,26 @@ #include "rtc_base/nat_socket_factory.h" #include "rtc_base/nat_types.h" #include "rtc_base/net_helper.h" -#include "rtc_base/net_helpers.h" #include "rtc_base/net_test_helpers.h" #include "rtc_base/network.h" #include "rtc_base/network_constants.h" #include "rtc_base/network_monitor.h" #include "rtc_base/socket.h" #include "rtc_base/socket_address.h" -#include "rtc_base/socket_address_pair.h" +#include "rtc_base/third_party/sigslot/sigslot.h" #include "rtc_base/thread.h" #include "rtc_base/virtual_socket_server.h" #include "system_wrappers/include/metrics.h" #include "test/gmock.h" #include "test/gtest.h" #include "test/scoped_key_value_config.h" +#include "test/wait_until.h" using rtc::IPAddress; using rtc::SocketAddress; using testing::Contains; +using ::testing::Eq; +using ::testing::IsTrue; using testing::Not; using webrtc::IceCandidateType; @@ -532,8 +546,12 @@ class BasicPortAllocatorTest : public FakeClockBase, PORTALLOCATOR_ENABLE_SHARED_SOCKET); allocator().set_allow_tcp_listen(false); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); uint32_t total_candidates = 0; if (!host_candidate_addr.IsNil()) { @@ -591,8 +609,12 @@ class BasicPortAllocatorTest : public FakeClockBase, ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); // Three ports (one IPv4 STUN, one IPv6 STUN and one TURN) will be ready. EXPECT_EQ(3U, session_->ReadyPorts().size()); EXPECT_EQ(3U, ports_.size()); @@ -635,8 +657,12 @@ class BasicPortAllocatorTest : public FakeClockBase, ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); // Only 2 ports (one STUN and one TURN) are actually being used. EXPECT_EQ(2U, session_->ReadyPorts().size()); // We have verified that each port, when it is added to `ports_`, it is @@ -693,8 +719,12 @@ class BasicPortAllocatorTest : public FakeClockBase, PORTALLOCATOR_ENABLE_IPV6 | PORTALLOCATOR_ENABLE_IPV6_ON_WIFI); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); // 10 ports (4 STUN and 1 TURN ports on each interface) will be ready to // use. EXPECT_EQ(10U, session_->ReadyPorts().size()); @@ -773,8 +803,12 @@ TEST_F(BasicPortAllocatorTest, TestIgnoreOnlyLoopbackNetworkByDefault) { session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | PORTALLOCATOR_DISABLE_TCP); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(4U, candidates_.size()); for (const Candidate& candidate : candidates_) { EXPECT_LT(candidate.address().ip(), 0x12345604U); @@ -795,8 +829,12 @@ TEST_F(BasicPortAllocatorTest, TestIgnoreNetworksAccordingToIgnoreMask) { session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | PORTALLOCATOR_DISABLE_TCP); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(1U, candidates_.size()); EXPECT_EQ(0x12345602U, candidates_[0].address().ip()); } @@ -816,8 +854,12 @@ TEST_F(BasicPortAllocatorTest, cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); ASSERT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); // Should only get one Wi-Fi candidate. EXPECT_EQ(1U, candidates_.size()); EXPECT_TRUE(HasCandidate(candidates_, IceCandidateType::kHost, "udp", wifi)); @@ -842,8 +884,12 @@ TEST_F(BasicPortAllocatorTest, cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); ASSERT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); // Should only get two candidates, none of which is cell. EXPECT_EQ(2U, candidates_.size()); EXPECT_TRUE( @@ -872,8 +918,12 @@ TEST_F(BasicPortAllocatorTest, cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); ASSERT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); // Should only get one Wi-Fi candidate. EXPECT_EQ(1U, candidates_.size()); EXPECT_TRUE(HasCandidate(candidates_, IceCandidateType::kHost, "udp", wifi)); @@ -893,8 +943,12 @@ TEST_F(BasicPortAllocatorTest, cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); ASSERT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); // Make sure we got the cell candidate. EXPECT_EQ(1U, candidates_.size()); EXPECT_TRUE( @@ -917,8 +971,12 @@ TEST_F(BasicPortAllocatorTest, cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); ASSERT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); // Make sure we got both wifi and cell candidates. EXPECT_EQ(2U, candidates_.size()); EXPECT_TRUE(HasCandidate(candidates_, IceCandidateType::kHost, "udp", @@ -946,8 +1004,12 @@ TEST_F(BasicPortAllocatorTest, cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); ASSERT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); // Make sure we got only wifi candidates. EXPECT_EQ(2U, candidates_.size()); EXPECT_TRUE(HasCandidate(candidates_, IceCandidateType::kHost, "udp", wifi)); @@ -968,8 +1030,12 @@ TEST_F(BasicPortAllocatorTest, PORTALLOCATOR_DISABLE_TCP); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); // The VPN tap0 network should be filtered out as a costly network, and we // should have a UDP port and a STUN port from the Ethernet eth0. ASSERT_EQ(2U, ports_.size()); @@ -993,8 +1059,12 @@ TEST_F(BasicPortAllocatorTest, MaxIpv6NetworksLimitEnforced) { ASSERT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(2U, candidates_.size()); // Ensure the expected two interfaces (eth0 and eth1) were used. EXPECT_TRUE(HasCandidate(candidates_, IceCandidateType::kHost, "udp", @@ -1020,8 +1090,12 @@ TEST_F(BasicPortAllocatorTest, MaxIpv6NetworksLimitDoesNotImpactIpv4Networks) { ASSERT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(3U, candidates_.size()); // Ensure that only one IPv6 interface was used, but both IPv4 interfaces // were used. @@ -1041,8 +1115,12 @@ TEST_F(BasicPortAllocatorTest, TestLoopbackNetworkInterface) { session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | PORTALLOCATOR_DISABLE_TCP); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(1U, candidates_.size()); } @@ -1051,8 +1129,12 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithMinimumStepDelay) { AddInterface(kClientAddr); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(3U, candidates_.size()); EXPECT_EQ(3U, ports_.size()); EXPECT_TRUE( @@ -1071,8 +1153,12 @@ TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionNotStopped) { AddInterface(kClientAddr, if_name); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(3U, candidates_.size()); EXPECT_EQ(3U, ports_.size()); candidate_allocation_done_ = false; @@ -1095,8 +1181,12 @@ TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionNotStopped) { fss_->set_tcp_sockets_enabled(true); fss_->set_udp_sockets_enabled(true); AddInterface(kClientAddr, if_name); - ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(3U, candidates_.size()); EXPECT_EQ(3U, ports_.size()); } @@ -1109,8 +1199,12 @@ TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionStopped) { AddInterface(kClientAddr, if_name); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(3U, candidates_.size()); EXPECT_EQ(3U, ports_.size()); session_->StopGettingPorts(); @@ -1147,8 +1241,12 @@ TEST_F(BasicPortAllocatorTest, CandidatesRegatheredAfterBindingFails) { fss_->set_udp_sockets_enabled(false); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); // Make sure we actually prevented candidates from being gathered (other than // a single TCP active candidate, since that doesn't require creating a // socket). @@ -1162,8 +1260,12 @@ TEST_F(BasicPortAllocatorTest, CandidatesRegatheredAfterBindingFails) { fss_->set_tcp_sockets_enabled(true); fss_->set_udp_sockets_enabled(true); AddInterface(kClientAddr, if_name); - ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); // Should get UDP and TCP candidate. ASSERT_EQ(2U, candidates_.size()); EXPECT_TRUE( @@ -1181,12 +1283,18 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) { allocator_->set_step_delay(kDefaultStepDelay); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock); + ASSERT_THAT(webrtc::WaitUntil([&] { return candidates_.size(); }, Eq(2U), + {.clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(2U, ports_.size()); - ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), 2000, fake_clock); + ASSERT_THAT(webrtc::WaitUntil([&] { return candidates_.size(); }, Eq(3U), + {.clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(3U, ports_.size()); - ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), 1500, fake_clock); + ASSERT_THAT(webrtc::WaitUntil([&] { return candidates_.size(); }, Eq(3U), + {.clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_TRUE( HasCandidate(candidates_, IceCandidateType::kHost, "tcp", kClientAddr)); EXPECT_EQ(3U, ports_.size()); @@ -1199,8 +1307,12 @@ TEST_F(BasicPortAllocatorTest, TestSetupVideoRtpPortsWithNormalSendBuffers) { AddInterface(kClientAddr); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP, CN_VIDEO)); session_->StartGettingPorts(); - ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(3U, candidates_.size()); // If we Stop gathering now, we shouldn't get a second "done" callback. session_->StopGettingPorts(); @@ -1215,12 +1327,20 @@ TEST_F(BasicPortAllocatorTest, TestStopGetAllPorts) { AddInterface(kClientAddr); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout, - fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidates_.size(); }, Eq(2U), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(2U, ports_.size()); session_->StopGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); } // Test that we restrict client ports appropriately when a port range is set. @@ -1236,8 +1356,12 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsPortRange) { EXPECT_TRUE(SetPortRange(kMinPort, kMaxPort)); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(3U, candidates_.size()); EXPECT_EQ(3U, ports_.size()); @@ -1263,8 +1387,12 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoAdapters) { AddTurnServers(kTurnUdpIntIPv6Addr, kTurnTcpIntIPv6Addr); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(4U, ports_.size()); EXPECT_EQ(1, CountPorts(ports_, IceCandidateType::kSrflx, PROTO_UDP, kAnyAddr)); @@ -1406,8 +1534,12 @@ TEST_F(BasicPortAllocatorTest, TestDisableUdpTurn) { PORTALLOCATOR_ENABLE_SHARED_SOCKET); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); // Expect to see 2 ports and 2 candidates - TURN/TCP and TCP ports, TCP and // TURN/TCP candidates. @@ -1430,7 +1562,9 @@ TEST_F(BasicPortAllocatorTest, TestDisableAllPorts) { session_->set_flags(PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | PORTALLOCATOR_DISABLE_TCP); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, 1000, fake_clock); + EXPECT_THAT(webrtc::WaitUntil([&] { return candidate_allocation_done_; }, + IsTrue(), {.clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(0U, candidates_.size()); } @@ -1440,8 +1574,12 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSockets) { fss_->set_udp_sockets_enabled(false); ASSERT_TRUE(CreateSession(1)); session_->StartGettingPorts(); - ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(1U, candidates_.size()); EXPECT_EQ(1U, ports_.size()); EXPECT_TRUE( @@ -1457,8 +1595,12 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSocketsNoTcpListen) { fss_->set_tcp_listen_enabled(false); ASSERT_TRUE(CreateSession(1)); session_->StartGettingPorts(); - ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(1U, candidates_.size()); EXPECT_EQ(1U, ports_.size()); EXPECT_TRUE( @@ -1473,7 +1615,7 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoSockets) { fss_->set_udp_sockets_enabled(false); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - SIMULATED_WAIT(candidates_.size() > 0, 2000, fake_clock); + SIMULATED_WAIT(!candidates_.empty(), 2000, fake_clock); // TODO(deadbeef): Check candidate_allocation_done signal. // In case of Relay, ports creation will succeed but sockets will fail. // There is no error reporting from RelayEntry to handle this failure. @@ -1485,8 +1627,12 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpAllowed) { AddInterface(kClientAddr); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_EQ_SIMULATED_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout, - fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidates_.size(); }, Eq(2U), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(2U, ports_.size()); EXPECT_TRUE( HasCandidate(candidates_, IceCandidateType::kHost, "udp", kClientAddr)); @@ -1494,8 +1640,12 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpAllowed) { HasCandidate(candidates_, IceCandidateType::kHost, "tcp", kClientAddr)); // We wait at least for a full STUN timeout, which // cricket::STUN_TOTAL_TIMEOUT seconds. - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - cricket::STUN_TOTAL_TIMEOUT, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(cricket::STUN_TOTAL_TIMEOUT), + .clock = &fake_clock}), + webrtc::IsRtcOk()); // No additional (STUN) candidates. EXPECT_EQ(2U, candidates_.size()); } @@ -1509,8 +1659,12 @@ TEST_F(BasicPortAllocatorTest, TestCandidatePriorityOfMultipleInterfaces) { PORTALLOCATOR_DISABLE_RELAY); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); ASSERT_EQ(2U, candidates_.size()); EXPECT_EQ(2U, ports_.size()); // Candidates priorities should be different. @@ -1522,8 +1676,12 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsRestarts) { AddInterface(kClientAddr); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(3U, candidates_.size()); EXPECT_EQ(3U, ports_.size()); // TODO(deadbeef): Extend this to verify ICE restart. @@ -1541,8 +1699,12 @@ TEST_F(BasicPortAllocatorTest, TestSessionUsesOwnCandidateFilter) { session_->StartGettingPorts(); // 7 candidates and 4 ports is what we would normally get (see the // TestGetAllPorts* tests). - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(3U, candidates_.size()); EXPECT_EQ(3U, ports_.size()); } @@ -1559,8 +1721,12 @@ TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithRelayOnly) { allocator().SetCandidateFilter(CF_RELAY); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(HasCandidate(candidates_, IceCandidateType::kRelay, "udp", rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0))); @@ -1578,8 +1744,12 @@ TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithHostOnly) { allocator().SetCandidateFilter(CF_HOST); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only. EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only. for (const Candidate& candidate : candidates_) { @@ -1596,8 +1766,12 @@ TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnly) { allocator().SetCandidateFilter(CF_REFLEXIVE); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); // Host is behind NAT, no private address will be exposed. Hence only UDP // port with STUN candidate will be sent outside. EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate. @@ -1615,8 +1789,12 @@ TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnlyAndNoNAT) { allocator().SetCandidateFilter(CF_REFLEXIVE); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); // Host has a public address, both UDP and TCP candidates will be exposed. EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate. EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state. @@ -1630,8 +1808,12 @@ TEST_F(BasicPortAllocatorTest, TestEnableSharedUfrag) { AddInterface(kClientAddr); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(3U, candidates_.size()); EXPECT_TRUE( HasCandidate(candidates_, IceCandidateType::kHost, "udp", kClientAddr)); @@ -1656,13 +1838,21 @@ TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNat) { PORTALLOCATOR_ENABLE_SHARED_SOCKET); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout, - fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidates_.size(); }, Eq(2U), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(2U, ports_.size()); EXPECT_TRUE( HasCandidate(candidates_, IceCandidateType::kHost, "udp", kClientAddr)); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); } // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port @@ -1676,15 +1866,23 @@ TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNat) { PORTALLOCATOR_ENABLE_SHARED_SOCKET); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout, - fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidates_.size(); }, Eq(3U), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); ASSERT_EQ(2U, ports_.size()); EXPECT_TRUE( HasCandidate(candidates_, IceCandidateType::kHost, "udp", kClientAddr)); EXPECT_TRUE(HasCandidate(candidates_, IceCandidateType::kSrflx, "udp", rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0))); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(3U, candidates_.size()); } @@ -1705,8 +1903,12 @@ TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); ASSERT_EQ(3U, candidates_.size()); ASSERT_EQ(3U, ports_.size()); EXPECT_TRUE( @@ -1845,7 +2047,11 @@ TEST_F(BasicPortAllocatorTestWithRealClock, ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_EQ_WAIT(2U, ports_.size(), kDefaultAllocationTimeout); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return ports_.size(); }, Eq(2U), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout)}), + webrtc::IsRtcOk()); } // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port @@ -1864,8 +2070,12 @@ TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurn) { ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(3U, candidates_.size()); ASSERT_EQ(2U, ports_.size()); EXPECT_TRUE( @@ -1874,8 +2084,12 @@ TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurn) { rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0))); EXPECT_TRUE(HasCandidate(candidates_, IceCandidateType::kRelay, "udp", rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0))); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); // Local port will be created first and then TURN port. // TODO(deadbeef): This isn't something the BasicPortAllocator API contract // guarantees... @@ -1904,8 +2118,12 @@ TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAsStun) { ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(3U, candidates_.size()); EXPECT_TRUE( HasCandidate(candidates_, IceCandidateType::kHost, "udp", kClientAddr)); @@ -1941,8 +2159,12 @@ TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) { ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(2U, candidates_.size()); ASSERT_EQ(2U, ports_.size()); EXPECT_TRUE( @@ -1969,8 +2191,12 @@ TEST_F(BasicPortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) { ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(3U, candidates_.size()); ASSERT_EQ(3U, ports_.size()); EXPECT_TRUE( @@ -2009,8 +2235,12 @@ TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) { ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout, - fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidates_.size(); }, Eq(3U), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_TRUE( HasCandidate(candidates_, IceCandidateType::kHost, "udp", kClientAddr)); Candidate stun_candidate; @@ -2037,14 +2267,21 @@ TEST_F(BasicPortAllocatorTest, TestSharedSocketNoUdpAllowed) { AddInterface(kClientAddr); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_EQ_SIMULATED_WAIT(1U, ports_.size(), kDefaultAllocationTimeout, - fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return ports_.size(); }, Eq(1U), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(1U, candidates_.size()); EXPECT_TRUE( HasCandidate(candidates_, IceCandidateType::kHost, "udp", kClientAddr)); // STUN timeout is 9.5sec. We need to wait to get candidate done signal. - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, kStunTimeoutMs, - fake_clock); + EXPECT_THAT( + webrtc::WaitUntil([&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kStunTimeoutMs), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(1U, candidates_.size()); } @@ -2064,8 +2301,12 @@ TEST_F(BasicPortAllocatorTest, TestNetworkPermissionBlocked) { ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); EXPECT_EQ(0U, session_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); session_->StartGettingPorts(); - EXPECT_EQ_SIMULATED_WAIT(1U, ports_.size(), kDefaultAllocationTimeout, - fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return ports_.size(); }, Eq(1U), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(1U, candidates_.size()); EXPECT_TRUE( HasCandidate(candidates_, IceCandidateType::kHost, "udp", kPrivateAddr)); @@ -2082,8 +2323,12 @@ TEST_F(BasicPortAllocatorTest, TestEnableIPv6Addresses) { allocator_->set_step_delay(kMinimumStepDelay); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(4U, ports_.size()); EXPECT_EQ(4U, candidates_.size()); EXPECT_TRUE(HasCandidate(candidates_, IceCandidateType::kHost, "udp", @@ -2101,10 +2346,14 @@ TEST_F(BasicPortAllocatorTest, TestStopGettingPorts) { allocator_->set_step_delay(kDefaultStepDelay); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock); + ASSERT_THAT(webrtc::WaitUntil([&] { return candidates_.size(); }, Eq(2U), + {.clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(2U, ports_.size()); session_->StopGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, 1000, fake_clock); + EXPECT_THAT(webrtc::WaitUntil([&] { return candidate_allocation_done_; }, + IsTrue(), {.clock = &fake_clock}), + webrtc::IsRtcOk()); // After stopping getting ports, adding a new interface will not start // getting ports again. @@ -2123,10 +2372,14 @@ TEST_F(BasicPortAllocatorTest, TestClearGettingPorts) { allocator_->set_step_delay(kDefaultStepDelay); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock); + ASSERT_THAT(webrtc::WaitUntil([&] { return candidates_.size(); }, Eq(2U), + {.clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(2U, ports_.size()); session_->ClearGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, 1000, fake_clock); + EXPECT_THAT(webrtc::WaitUntil([&] { return candidate_allocation_done_; }, + IsTrue(), {.clock = &fake_clock}), + webrtc::IsRtcOk()); // After clearing getting ports, adding a new interface will start getting // ports again. @@ -2135,10 +2388,16 @@ TEST_F(BasicPortAllocatorTest, TestClearGettingPorts) { ports_.clear(); candidate_allocation_done_ = false; network_manager_.AddInterface(kClientAddr2); - ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock); + ASSERT_THAT(webrtc::WaitUntil([&] { return candidates_.size(); }, Eq(2U), + {.clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(2U, ports_.size()); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); } // Test that the ports and candidates are updated with new ufrag/pwd/etc. when @@ -2151,8 +2410,12 @@ TEST_F(BasicPortAllocatorTest, TestTransportInformationUpdated) { webrtc::NO_PRUNE); const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); ASSERT_NE(nullptr, peeked_session); - EXPECT_EQ_SIMULATED_WAIT(true, peeked_session->CandidatesAllocationDone(), - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return peeked_session->CandidatesAllocationDone(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); // Expect that when TakePooledSession is called, // UpdateTransportInformationInternal will be called and the // BasicPortAllocatorSession will update the ufrag/pwd of ports and @@ -2188,8 +2451,12 @@ TEST_F(BasicPortAllocatorTest, TestSetCandidateFilterAfterCandidatesGathered) { webrtc::NO_PRUNE); const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); ASSERT_NE(nullptr, peeked_session); - EXPECT_EQ_SIMULATED_WAIT(true, peeked_session->CandidatesAllocationDone(), - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return peeked_session->CandidatesAllocationDone(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); size_t initial_candidates_size = peeked_session->ReadyCandidates().size(); size_t initial_ports_size = peeked_session->ReadyPorts().size(); allocator_->SetCandidateFilter(CF_RELAY); @@ -2236,29 +2503,45 @@ TEST_F(BasicPortAllocatorTest, allocator_->SetCandidateFilter(CF_NONE); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(candidates_.empty()); EXPECT_TRUE(ports_.empty()); // Surface the relay candidate previously gathered but not signaled. session_->SetCandidateFilter(CF_RELAY); - ASSERT_EQ_SIMULATED_WAIT(1u, candidates_.size(), kDefaultAllocationTimeout, - fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidates_.size(); }, Eq(1u), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(candidates_.back().is_relay()); EXPECT_EQ(1u, ports_.size()); // Surface the srflx candidate previously gathered but not signaled. session_->SetCandidateFilter(CF_RELAY | CF_REFLEXIVE); - ASSERT_EQ_SIMULATED_WAIT(2u, candidates_.size(), kDefaultAllocationTimeout, - fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidates_.size(); }, Eq(2u), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(candidates_.back().is_stun()); EXPECT_EQ(2u, ports_.size()); // Surface the srflx candidate previously gathered but not signaled. session_->SetCandidateFilter(CF_ALL); - ASSERT_EQ_SIMULATED_WAIT(3u, candidates_.size(), kDefaultAllocationTimeout, - fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidates_.size(); }, Eq(3u), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(candidates_.back().is_local()); EXPECT_EQ(2u, ports_.size()); } @@ -2286,29 +2569,45 @@ TEST_F( allocator_->SetCandidateFilter(CF_NONE); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(candidates_.empty()); EXPECT_TRUE(ports_.empty()); // Surface the relay candidate previously gathered but not signaled. session_->SetCandidateFilter(CF_RELAY); - EXPECT_EQ_SIMULATED_WAIT(1u, candidates_.size(), kDefaultAllocationTimeout, - fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidates_.size(); }, Eq(1u), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(candidates_.back().is_relay()); EXPECT_EQ(1u, ports_.size()); // Surface the srflx candidate previously gathered but not signaled. session_->SetCandidateFilter(CF_REFLEXIVE); - EXPECT_EQ_SIMULATED_WAIT(2u, candidates_.size(), kDefaultAllocationTimeout, - fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidates_.size(); }, Eq(2u), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(candidates_.back().is_stun()); EXPECT_EQ(2u, ports_.size()); // Surface the host candidate previously gathered but not signaled. session_->SetCandidateFilter(CF_HOST); - EXPECT_EQ_SIMULATED_WAIT(3u, candidates_.size(), kDefaultAllocationTimeout, - fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidates_.size(); }, Eq(3u), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_TRUE(candidates_.back().is_local()); // We use a shared socket and cricket::UDPPort handles the srflx candidate. EXPECT_EQ(2u, ports_.size()); @@ -2331,8 +2630,12 @@ TEST_F(BasicPortAllocatorTest, allocator_->SetCandidateFilter(CF_NONE); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); auto test_invariants = [this]() { EXPECT_TRUE(candidates_.empty()); EXPECT_TRUE(ports_.empty()); @@ -2364,8 +2667,12 @@ TEST_F(BasicPortAllocatorTest, SetStunKeepaliveIntervalForPorts) { webrtc::NO_PRUNE, nullptr, expected_stun_keepalive_interval); auto* pooled_session = allocator_->GetPooledSession(); ASSERT_NE(nullptr, pooled_session); - EXPECT_EQ_SIMULATED_WAIT(true, pooled_session->CandidatesAllocationDone(), - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return pooled_session->CandidatesAllocationDone(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); CheckStunKeepaliveIntervalOfAllReadyPorts(pooled_session, expected_stun_keepalive_interval); } @@ -2379,8 +2686,12 @@ TEST_F(BasicPortAllocatorTest, webrtc::NO_PRUNE, nullptr, 123 /* stun keepalive interval */); auto* pooled_session = allocator_->GetPooledSession(); ASSERT_NE(nullptr, pooled_session); - EXPECT_EQ_SIMULATED_WAIT(true, pooled_session->CandidatesAllocationDone(), - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return pooled_session->CandidatesAllocationDone(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); const int expected_stun_keepalive_interval = 321; allocator_->SetConfiguration( allocator_->stun_servers(), allocator_->turn_servers(), pool_size, @@ -2401,8 +2712,12 @@ TEST_F(BasicPortAllocatorTest, webrtc::NO_PRUNE, nullptr, expected_stun_keepalive_interval); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); CheckStunKeepaliveIntervalOfAllReadyPorts(session_.get(), expected_stun_keepalive_interval); } @@ -2419,8 +2734,12 @@ TEST_F(BasicPortAllocatorTest, webrtc::NO_PRUNE, nullptr, expected_stun_keepalive_interval); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); CheckStunKeepaliveIntervalOfAllReadyPorts(session_.get(), expected_stun_keepalive_interval); } @@ -2442,8 +2761,12 @@ TEST_F(BasicPortAllocatorTest, HostCandidateAddressIsReplacedByHostname) { AddInterface(kClientAddr); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(5u, candidates_.size()); int num_host_udp_candidates = 0; int num_host_tcp_candidates = 0; @@ -2520,8 +2843,12 @@ TEST_F(BasicPortAllocatorTest, AssignsUniqueLocalPreferencetoRelayCandidates) { AddInterface(kClientAddr); ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + ASSERT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(3u, candidates_.size()); EXPECT_GT((candidates_[0].priority() >> 8) & 0xFFFF, (candidates_[1].priority() >> 8) & 0xFFFF); @@ -2675,8 +3002,12 @@ TEST_F(BasicPortAllocatorTest, Select2DifferentIntefaces) { ASSERT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(2U, candidates_.size()); // ethe1 and wifi1 were selected. @@ -2702,8 +3033,12 @@ TEST_F(BasicPortAllocatorTest, Select3DifferentIntefaces) { ASSERT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(3U, candidates_.size()); // ethe1, wifi1, and cell1 were selected. @@ -2731,8 +3066,12 @@ TEST_F(BasicPortAllocatorTest, Select4DifferentIntefaces) { ASSERT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); - EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, - kDefaultAllocationTimeout, fake_clock); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return candidate_allocation_done_; }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kDefaultAllocationTimeout), + .clock = &fake_clock}), + webrtc::IsRtcOk()); EXPECT_EQ(4U, candidates_.size()); // ethe1, ethe2, wifi1, and cell1 were selected. diff --git a/p2p/dtls/dtls_transport_unittest.cc b/p2p/dtls/dtls_transport_unittest.cc index 2eed02ee44..75a31bc472 100644 --- a/p2p/dtls/dtls_transport_unittest.cc +++ b/p2p/dtls/dtls_transport_unittest.cc @@ -28,6 +28,7 @@ #include "api/crypto/crypto_options.h" #include "api/dtls_transport_interface.h" #include "api/scoped_refptr.h" +#include "api/test/rtc_error_matchers.h" #include "api/units/time_delta.h" #include "p2p/base/fake_ice_transport.h" #include "p2p/base/packet_transport_internal.h" @@ -39,7 +40,6 @@ #include "rtc_base/checks.h" #include "rtc_base/copy_on_write_buffer.h" #include "rtc_base/fake_clock.h" -#include "rtc_base/gunit.h" #include "rtc_base/logging.h" #include "rtc_base/network/received_packet.h" #include "rtc_base/rtc_certificate.h" @@ -48,7 +48,9 @@ #include "rtc_base/ssl_stream_adapter.h" #include "rtc_base/third_party/sigslot/sigslot.h" #include "rtc_base/thread.h" +#include "test/gmock.h" #include "test/gtest.h" +#include "test/wait_until.h" #define MAYBE_SKIP_TEST(feature) \ if (!(rtc::SSLStreamAdapter::feature())) { \ @@ -58,6 +60,9 @@ namespace cricket { +using ::testing::Eq; +using ::testing::IsTrue; + static const size_t kPacketNumOffset = 8; static const size_t kPacketHeaderLen = 12; static const int kFakePacketId = 0x1234; @@ -380,9 +385,15 @@ class DtlsTransportTestBase { Negotiate(client1_server); EXPECT_TRUE(client1_.Connect(&client2_, false)); - EXPECT_TRUE_SIMULATED_WAIT(client1_.dtls_transport()->writable() && - client2_.dtls_transport()->writable(), - kTimeout, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return client1_.dtls_transport()->writable() && + client2_.dtls_transport()->writable(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeout), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); if (!client1_.dtls_transport()->writable() || !client2_.dtls_transport()->writable()) return false; @@ -432,8 +443,11 @@ class DtlsTransportTestBase { RTC_LOG(LS_INFO) << "Expect packets, size=" << size; client2_.ExpectPackets(size); client1_.SendPackets(size, count, srtp); - EXPECT_EQ_SIMULATED_WAIT(count, client2_.NumPacketsReceived(), kTimeout, - fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return client2_.NumPacketsReceived(); }, Eq(count), + {.timeout = webrtc::TimeDelta::Millis(kTimeout), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); } protected: @@ -630,9 +644,15 @@ class DtlsTransportVersionTest EXPECT_TRUE(client1_.Connect(&client2_, false)); - EXPECT_TRUE_SIMULATED_WAIT(client1_.dtls_transport()->writable() && - client2_.dtls_transport()->writable(), - kTimeout, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return client1_.dtls_transport()->writable() && + client2_.dtls_transport()->writable(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeout), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); client1_.fake_ice_transport()->set_packet_send_filter(nullptr); client2_.fake_ice_transport()->set_packet_send_filter(nullptr); @@ -842,9 +862,15 @@ TEST_F(DtlsTransportTest, TestRenegotiateBeforeConnect) { Negotiate(); Negotiate(); EXPECT_TRUE(client1_.Connect(&client2_, false)); - EXPECT_TRUE_SIMULATED_WAIT(client1_.dtls_transport()->writable() && - client2_.dtls_transport()->writable(), - kTimeout, fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { + return client1_.dtls_transport()->writable() && + client2_.dtls_transport()->writable(); + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeout), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); TestTransfer(1000, 100, true); } @@ -905,11 +931,18 @@ TEST_F(DtlsTransportTest, TestRetransmissionSchedule) { // Make client2_ writable, but not client1_. // This means client1_ will send DTLS client hellos but get no response. EXPECT_TRUE(client2_.Connect(&client1_, true)); - EXPECT_TRUE_SIMULATED_WAIT(client2_.fake_ice_transport()->writable(), - kTimeout, fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return client2_.fake_ice_transport()->writable(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeout), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); // Wait for the first client hello to be sent. - EXPECT_EQ_WAIT(1, client1_.received_dtls_client_hellos(), kTimeout); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return client1_.received_dtls_client_hellos(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kTimeout)}), + webrtc::IsRtcOk()); EXPECT_FALSE(client1_.fake_ice_transport()->writable()); static int timeout_schedule_ms[] = {50, 100, 200, 400, 800, 1600, @@ -992,29 +1025,49 @@ class DtlsEventOrderingTest break; case CALLER_WRITABLE: EXPECT_TRUE(client1_.Connect(&client2_, true)); - EXPECT_TRUE_SIMULATED_WAIT(client1_.fake_ice_transport()->writable(), - kTimeout, fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return client1_.fake_ice_transport()->writable(); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeout), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); break; case CALLER_RECEIVES_CLIENTHELLO: // Sanity check that a ClientHello hasn't already been received. EXPECT_EQ(0, client1_.received_dtls_client_hellos()); // Making client2_ writable will cause it to send the ClientHello. EXPECT_TRUE(client2_.Connect(&client1_, true)); - EXPECT_TRUE_SIMULATED_WAIT(client2_.fake_ice_transport()->writable(), - kTimeout, fake_clock_); - EXPECT_EQ_SIMULATED_WAIT(1, client1_.received_dtls_client_hellos(), - kTimeout, fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return client2_.fake_ice_transport()->writable(); }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeout), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { return client1_.received_dtls_client_hellos(); }, Eq(1), + {.timeout = webrtc::TimeDelta::Millis(kTimeout), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); break; case HANDSHAKE_FINISHES: // Sanity check that the handshake hasn't already finished. EXPECT_FALSE(client1_.dtls_transport()->IsDtlsConnected() || client1_.dtls_transport()->dtls_state() == webrtc::DtlsTransportState::kFailed); - EXPECT_TRUE_SIMULATED_WAIT( - client1_.dtls_transport()->IsDtlsConnected() || - client1_.dtls_transport()->dtls_state() == - webrtc::DtlsTransportState::kFailed, - kTimeout, fake_clock_); + EXPECT_THAT( + webrtc::WaitUntil( + [&] { + return client1_.dtls_transport()->IsDtlsConnected() || + client1_.dtls_transport()->dtls_state() == + webrtc::DtlsTransportState::kFailed; + }, + IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kTimeout), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); break; } } @@ -1022,12 +1075,18 @@ class DtlsEventOrderingTest webrtc::DtlsTransportState expected_final_state = valid_fingerprint ? webrtc::DtlsTransportState::kConnected : webrtc::DtlsTransportState::kFailed; - EXPECT_EQ_SIMULATED_WAIT(expected_final_state, - client1_.dtls_transport()->dtls_state(), kTimeout, - fake_clock_); - EXPECT_EQ_SIMULATED_WAIT(expected_final_state, - client2_.dtls_transport()->dtls_state(), kTimeout, - fake_clock_); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return client1_.dtls_transport()->dtls_state(); }, + Eq(expected_final_state), + {.timeout = webrtc::TimeDelta::Millis(kTimeout), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); + EXPECT_THAT(webrtc::WaitUntil( + [&] { return client2_.dtls_transport()->dtls_state(); }, + Eq(expected_final_state), + {.timeout = webrtc::TimeDelta::Millis(kTimeout), + .clock = &fake_clock_}), + webrtc::IsRtcOk()); // Transports should be writable iff there was a valid fingerprint. EXPECT_EQ(valid_fingerprint, client1_.dtls_transport()->writable());