Replace gunit.h macros with WaitUntil in pc/

Bug: webrtc:381524905
Change-Id: I15946ab73aaef2e830d6801451636e717708adbf
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/373704
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Auto-Submit: Evan Shrubsole <eshr@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43680}
This commit is contained in:
Evan Shrubsole 2025-01-08 11:30:31 +00:00 committed by WebRTC LUCI CQ
parent a75ad9278c
commit 3e8e4784ac
31 changed files with 2489 additions and 1013 deletions

View File

@ -2000,6 +2000,7 @@ if (rtc_include_tests && !build_with_chromium) {
"../api:make_ref_counted",
"../api:priority",
"../api:rtc_error",
"../api:rtc_error_matchers",
"../api:rtp_headers",
"../api:rtp_parameters",
"../api:rtp_transceiver_direction",
@ -2013,6 +2014,7 @@ if (rtc_include_tests && !build_with_chromium) {
"../api/task_queue:task_queue",
"../api/transport:datagram_transport_interface",
"../api/transport:enums",
"../api/units:time_delta",
"../api/video:builtin_video_bitrate_allocator_factory",
"../api/video:recordable_encoded_frame",
"../api/video/test:mock_recordable_encoded_frame",
@ -2063,7 +2065,9 @@ if (rtc_include_tests && !build_with_chromium) {
"../rtc_base:threading",
"../rtc_base:unique_id_generator",
"../rtc_base/containers:flat_set",
"../rtc_base/network:ecn_marking",
"../rtc_base/network:received_packet",
"../rtc_base/network:sent_packet",
"../rtc_base/third_party/sigslot",
"../system_wrappers:metrics",
"../test:explicit_key_value_config",
@ -2071,6 +2075,8 @@ if (rtc_include_tests && !build_with_chromium) {
"../test:scoped_key_value_config",
"../test:test_main",
"../test:test_support",
"../test:wait_until",
"//testing/gmock",
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/functional:any_invocable",
"//third_party/abseil-cpp/absl/memory",
@ -2103,8 +2109,10 @@ if (rtc_include_tests && !build_with_chromium) {
"../api:audio_options_api",
"../api:create_peerconnection_factory",
"../api:libjingle_peerconnection_api",
"../api:make_ref_counted",
"../api:media_stream_interface",
"../api:rtc_error",
"../api:rtc_error_matchers",
"../api:rtc_stats_api",
"../api:scoped_refptr",
"../api/audio:audio_device",
@ -2127,6 +2135,7 @@ if (rtc_include_tests && !build_with_chromium) {
"../api/video_codecs:video_encoder_factory_template_libvpx_vp9_adapter",
"../api/video_codecs:video_encoder_factory_template_open_h264_adapter",
"../media:rtc_media_tests_utils",
"../p2p:basic_packet_socket_factory",
"../p2p:basic_port_allocator",
"../p2p:connection",
"../p2p:p2p_test_utils",
@ -2143,6 +2152,8 @@ if (rtc_include_tests && !build_with_chromium) {
"../rtc_base:threading",
"../system_wrappers",
"../test:test_support",
"../test:wait_until",
"//testing/gmock",
]
}
@ -2157,8 +2168,10 @@ if (rtc_include_tests && !build_with_chromium) {
":sdp_utils",
"../api:function_view",
"../api:libjingle_peerconnection_api",
"../api:make_ref_counted",
"../api:media_stream_interface",
"../api:rtc_error",
"../api:rtc_error_matchers",
"../api:rtc_stats_api",
"../api:rtp_parameters",
"../api:rtp_sender_interface",
@ -2167,6 +2180,8 @@ if (rtc_include_tests && !build_with_chromium) {
"../rtc_base:gunit_helpers",
"../rtc_base:logging",
"../test:test_support",
"../test:wait_until",
"//testing/gmock",
]
}
@ -2178,6 +2193,7 @@ if (rtc_include_tests && !build_with_chromium) {
":pc_test_utils",
"../api:dtmf_sender_interface",
"../api:libjingle_peerconnection_api",
"../api:rtc_error_matchers",
"../api:scoped_refptr",
"../api/units:time_delta",
"../p2p:connection",
@ -2192,6 +2208,7 @@ if (rtc_include_tests && !build_with_chromium) {
"../rtc_base:ssl",
"../test:test_main",
"../test:test_support",
"../test:wait_until",
"../test/time_controller:time_controller",
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/strings",
@ -2329,6 +2346,7 @@ if (rtc_include_tests && !build_with_chromium) {
"../api:rtp_sender_interface",
"../api:rtp_transceiver_direction",
"../api:scoped_refptr",
"../api:sequence_checker",
"../api/adaptation:resource_adaptation_api",
"../api/audio:audio_device",
"../api/audio:audio_mixer_api",
@ -2343,6 +2361,8 @@ if (rtc_include_tests && !build_with_chromium) {
"../api/rtc_event_log:rtc_event_log_factory",
"../api/task_queue",
"../api/task_queue:default_task_queue_factory",
"../api/task_queue:pending_task_safety_flag",
"../api/transport:bitrate_settings",
"../api/transport:datagram_transport_interface",
"../api/transport:enums",
"../api/transport:field_trial_based_config",
@ -2373,6 +2393,7 @@ if (rtc_include_tests && !build_with_chromium) {
"../media:stream_params",
"../modules/audio_processing:mocks",
"../modules/rtp_rtcp:rtp_rtcp_format",
"../p2p:basic_packet_socket_factory",
"../p2p:basic_port_allocator",
"../p2p:connection",
"../p2p:connection_info",
@ -2407,6 +2428,7 @@ if (rtc_include_tests && !build_with_chromium) {
"../rtc_base:rtc_certificate_generator",
"../rtc_base:rtc_json",
"../rtc_base:socket_address",
"../rtc_base:socket_server",
"../rtc_base:ssl",
"../rtc_base:ssl_adapter",
"../rtc_base:stringutils",
@ -2424,6 +2446,7 @@ if (rtc_include_tests && !build_with_chromium) {
"../test:scoped_key_value_config",
"../test:wait_until",
"../test/pc/sctp:fake_sctp_transport",
"//testing/gmock",
"//testing/gtest",
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/memory",
@ -2564,6 +2587,7 @@ if (rtc_include_tests && !build_with_chromium) {
"../api:mock_rtp",
"../api:packet_socket_factory",
"../api:rtc_error",
"../api:rtc_error_matchers",
"../api:rtc_stats_api",
"../api:rtp_parameters",
"../api:rtp_sender_interface",
@ -2639,6 +2663,7 @@ if (rtc_include_tests && !build_with_chromium) {
"../test:rtp_test_utils",
"../test:scoped_key_value_config",
"../test:test_support",
"../test:wait_until",
"../test/pc/sctp:fake_sctp_transport",
"../test/time_controller",
"//third_party/abseil-cpp/absl/algorithm:container",
@ -2720,6 +2745,7 @@ if (rtc_include_tests && !build_with_chromium) {
"../api:media_stream_interface",
"../api:priority",
"../api:rtc_error",
"../api:rtc_error_matchers",
"../api:rtc_stats_api",
"../api:rtp_parameters",
"../api:scoped_refptr",
@ -2758,6 +2784,7 @@ if (rtc_include_tests && !build_with_chromium) {
"../modules/audio_device",
"../modules/audio_processing",
"../modules/rtp_rtcp:rtp_rtcp_format",
"../p2p:basic_packet_socket_factory",
"../p2p:connection",
"../p2p:fake_port_allocator",
"../p2p:p2p_test_utils",
@ -2767,6 +2794,7 @@ if (rtc_include_tests && !build_with_chromium) {
"../rtc_base:logging",
"../rtc_base:macromagic",
"../rtc_base:rtc_certificate_generator",
"../rtc_base:socket_server",
"../rtc_base:ssl",
"../rtc_base:stringutils",
"../rtc_base:task_queue_for_test",
@ -2779,6 +2807,8 @@ if (rtc_include_tests && !build_with_chromium) {
"../test:frame_generator_capturer",
"../test:scoped_key_value_config",
"../test:test_support",
"../test:wait_until",
"//testing/gmock",
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/strings",
]

View File

@ -11,17 +11,24 @@
#include "pc/audio_rtp_receiver.h"
#include <atomic>
#include <cstdint>
#include <string>
#include <vector>
#include "api/make_ref_counted.h"
#include "api/scoped_refptr.h"
#include "api/test/rtc_error_matchers.h"
#include "api/units/time_delta.h"
#include "pc/test/mock_voice_media_receive_channel_interface.h"
#include "rtc_base/gunit.h"
#include "rtc_base/thread.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/run_loop.h"
#include "test/wait_until.h"
using ::testing::_;
using ::testing::Eq;
using ::testing::InvokeWithoutArgs;
using ::testing::Mock;
static const int kTimeOut = 100;
static const double kDefaultVolume = 1;
@ -76,7 +83,9 @@ TEST_F(AudioRtpReceiverTest, SetOutputVolumeIsCalled) {
}));
receiver_->OnSetVolume(kVolume);
EXPECT_TRUE_WAIT(set_volume_calls == 2, kTimeOut);
EXPECT_THAT(WaitUntil([&] { return set_volume_calls.load(); }, Eq(2),
{.timeout = webrtc::TimeDelta::Millis(kTimeOut)}),
IsRtcOk());
}
TEST_F(AudioRtpReceiverTest, VolumesSetBeforeStartingAreRespected) {

View File

@ -15,15 +15,18 @@
#include "absl/strings/str_cat.h"
#include "api/peer_connection_interface.h"
#include "api/test/rtc_error_matchers.h"
#include "pc/test/integration_test_helpers.h"
#include "rtc_base/gunit.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/wait_until.h"
namespace webrtc {
using testing::Eq;
using ::testing::Gt;
using testing::HasSubstr;
using ::testing::IsTrue;
using testing::Not;
class PeerConnectionCongestionControlTest
@ -48,7 +51,8 @@ TEST_F(PeerConnectionCongestionControlTest, ReceiveOfferSetsCcfbFlag) {
ConnectFakeSignalingForSdpOnly();
caller()->AddAudioVideoTracks();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_THAT(WaitUntil([&] { return SignalingStateStable(); }, IsTrue()),
IsRtcOk());
// Check that the callee parsed it.
auto parsed_contents =
callee()->pc()->remote_description()->description()->contents();
@ -74,14 +78,20 @@ TEST_F(PeerConnectionCongestionControlTest, CcfbGetsUsed) {
ConnectFakeSignaling();
caller()->AddAudioVideoTracks();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_THAT(WaitUntil([&] { return SignalingStateStable(); }, IsTrue()),
IsRtcOk());
MediaExpectations media_expectations;
media_expectations.CalleeExpectsSomeAudio();
media_expectations.CalleeExpectsSomeVideo();
ASSERT_TRUE(ExpectNewFrames(media_expectations));
auto pc_internal = caller()->pc_internal();
EXPECT_TRUE_WAIT(pc_internal->FeedbackAccordingToRfc8888CountForTesting() > 0,
kDefaultTimeout);
EXPECT_THAT(
WaitUntil(
[&] {
return pc_internal->FeedbackAccordingToRfc8888CountForTesting();
},
Gt(0)),
IsRtcOk());
// There should be no transport-cc generated.
EXPECT_THAT(pc_internal->FeedbackAccordingToTransportCcCountForTesting(),
Eq(0));
@ -93,15 +103,20 @@ TEST_F(PeerConnectionCongestionControlTest, TransportCcGetsUsed) {
ConnectFakeSignaling();
caller()->AddAudioVideoTracks();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_THAT(WaitUntil([&] { return SignalingStateStable(); }, IsTrue()),
IsRtcOk());
MediaExpectations media_expectations;
media_expectations.CalleeExpectsSomeAudio();
media_expectations.CalleeExpectsSomeVideo();
ASSERT_TRUE(ExpectNewFrames(media_expectations));
auto pc_internal = caller()->pc_internal();
EXPECT_TRUE_WAIT(
pc_internal->FeedbackAccordingToTransportCcCountForTesting() > 0,
kDefaultTimeout);
EXPECT_THAT(
WaitUntil(
[&] {
return pc_internal->FeedbackAccordingToTransportCcCountForTesting();
},
Gt(0)),
IsRtcOk());
// Test that RFC 8888 feedback is NOT generated when field trial disabled.
EXPECT_THAT(pc_internal->FeedbackAccordingToRfc8888CountForTesting(), Eq(0));
}

File diff suppressed because it is too large Load Diff

View File

@ -12,26 +12,32 @@
#include <string.h>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include "api/data_channel_interface.h"
#include "api/make_ref_counted.h"
#include "api/priority.h"
#include "api/rtc_error.h"
#include "api/scoped_refptr.h"
#include "api/sequence_checker.h"
#include "api/task_queue/pending_task_safety_flag.h"
#include "api/test/rtc_error_matchers.h"
#include "api/transport/data_channel_transport_interface.h"
#include "media/base/media_channel.h"
#include "media/sctp/sctp_transport_internal.h"
#include "pc/sctp_data_channel.h"
#include "pc/sctp_utils.h"
#include "pc/test/fake_data_channel_controller.h"
#include "rtc_base/checks.h"
#include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/gunit.h"
#include "rtc_base/null_socket_server.h"
#include "rtc_base/ssl_stream_adapter.h"
#include "rtc_base/thread.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/run_loop.h"
#include "test/wait_until.h"
#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
#include "test/testsupport/rtc_expect_death.h"
@ -41,7 +47,7 @@ namespace webrtc {
namespace {
static constexpr int kDefaultTimeout = 10000;
using ::testing::Eq;
class FakeDataChannelObserver : public DataChannelObserver {
public:
@ -257,7 +263,9 @@ TEST_F(SctpDataChannelTest, SendUnorderedAfterReceivesOpenAck) {
controller_->CreateDataChannel("test1", init);
auto proxy = SctpDataChannel::CreateProxy(dc, signaling_safety_);
EXPECT_EQ_WAIT(DataChannelInterface::kOpen, proxy->state(), 1000);
EXPECT_THAT(WaitUntil([&] { return proxy->state(); },
Eq(DataChannelInterface::kOpen)),
IsRtcOk());
// Sends a message and verifies it's ordered.
DataBuffer buffer("some data");
@ -286,7 +294,9 @@ TEST_F(SctpDataChannelTest, DeprecatedSendUnorderedAfterReceivesOpenAck) {
controller_->CreateDataChannel("test1", init);
auto proxy = SctpDataChannel::CreateProxy(dc, signaling_safety_);
EXPECT_EQ_WAIT(DataChannelInterface::kOpen, proxy->state(), 1000);
EXPECT_THAT(WaitUntil([&] { return proxy->state(); },
Eq(DataChannelInterface::kOpen)),
IsRtcOk());
// Sends a message and verifies it's ordered.
DataBuffer buffer("some data");
@ -315,7 +325,9 @@ TEST_F(SctpDataChannelTest, SendUnorderedAfterReceiveData) {
controller_->CreateDataChannel("test1", init);
auto proxy = SctpDataChannel::CreateProxy(dc, signaling_safety_);
EXPECT_EQ_WAIT(DataChannelInterface::kOpen, proxy->state(), 1000);
EXPECT_THAT(WaitUntil([&] { return proxy->state(); },
Eq(DataChannelInterface::kOpen)),
IsRtcOk());
// Emulates receiving a DATA message.
DataBuffer buffer("data");
@ -338,7 +350,9 @@ TEST_F(SctpDataChannelTest, DeprecatedSendUnorderedAfterReceiveData) {
controller_->CreateDataChannel("test1", init);
auto proxy = SctpDataChannel::CreateProxy(dc, signaling_safety_);
EXPECT_EQ_WAIT(DataChannelInterface::kOpen, proxy->state(), 1000);
EXPECT_THAT(WaitUntil([&] { return proxy->state(); },
Eq(DataChannelInterface::kOpen)),
IsRtcOk());
// Emulates receiving a DATA message.
DataBuffer buffer("data");
@ -397,7 +411,9 @@ TEST_F(SctpDataChannelTest, NoMsgSentIfNegotiatedAndNotFromOpenMsg) {
controller_->CreateDataChannel("test1", config);
auto proxy = SctpDataChannel::CreateProxy(dc, signaling_safety_);
EXPECT_EQ_WAIT(DataChannelInterface::kOpen, proxy->state(), 1000);
EXPECT_THAT(WaitUntil([&] { return proxy->state(); },
Eq(DataChannelInterface::kOpen)),
IsRtcOk());
EXPECT_EQ(0, controller_->last_sid());
}
@ -462,7 +478,9 @@ TEST_F(SctpDataChannelTest, OpenAckSentIfCreatedFromOpenMessage) {
controller_->CreateDataChannel("test1", config);
auto proxy = SctpDataChannel::CreateProxy(dc, signaling_safety_);
EXPECT_EQ_WAIT(DataChannelInterface::kOpen, proxy->state(), 1000);
EXPECT_THAT(WaitUntil([&] { return proxy->state(); },
Eq(DataChannelInterface::kOpen)),
IsRtcOk());
EXPECT_EQ(config.id, controller_->last_sid());
EXPECT_EQ(DataMessageType::kControl,
@ -586,8 +604,9 @@ TEST_F(SctpDataChannelTest, TransportDestroyedWhileDataBuffered) {
network_thread_.BlockingCall(
[&] { inner_channel_->OnTransportChannelClosed(error); });
controller_.reset(nullptr);
EXPECT_EQ_WAIT(DataChannelInterface::kClosed, channel_->state(),
kDefaultTimeout);
EXPECT_THAT(WaitUntil([&] { return channel_->state(); },
Eq(DataChannelInterface::kClosed)),
IsRtcOk());
EXPECT_FALSE(channel_->error().ok());
EXPECT_EQ(RTCErrorType::OPERATION_ERROR_WITH_DATA, channel_->error().type());
EXPECT_EQ(RTCErrorDetailType::SCTP_FAILURE, channel_->error().error_detail());
@ -607,8 +626,9 @@ TEST_F(SctpDataChannelTest, TransportGotErrorCode) {
network_thread_.BlockingCall(
[&] { inner_channel_->OnTransportChannelClosed(error); });
controller_.reset(nullptr);
EXPECT_EQ_WAIT(DataChannelInterface::kClosed, channel_->state(),
kDefaultTimeout);
EXPECT_THAT(WaitUntil([&] { return channel_->state(); },
Eq(DataChannelInterface::kClosed)),
IsRtcOk());
EXPECT_FALSE(channel_->error().ok());
EXPECT_EQ(RTCErrorType::OPERATION_ERROR_WITH_DATA, channel_->error().type());
EXPECT_EQ(RTCErrorDetailType::SCTP_FAILURE, channel_->error().error_detail());

View File

@ -17,6 +17,8 @@
#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 "call/rtp_demuxer.h"
#include "media/base/fake_rtp.h"
#include "p2p/base/fake_ice_transport.h"
@ -30,15 +32,16 @@
#include "rtc_base/buffer.h"
#include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/fake_clock.h"
#include "rtc_base/gunit.h"
#include "rtc_base/rtc_certificate.h"
#include "rtc_base/ssl_fingerprint.h"
#include "rtc_base/ssl_identity.h"
#include "rtc_base/ssl_stream_adapter.h"
#include "rtc_base/string_encode.h"
#include "rtc_base/thread.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/scoped_key_value_config.h"
#include "test/wait_until.h"
const int kRtpAuthTagLen = 10;
static const int kTimeout = 10000;
@ -122,9 +125,15 @@ class DtlsSrtpTransportIntegrationTest : public ::testing::Test {
client_ice_transport_->SetDestination(server_ice_transport_.get());
// Wait for the DTLS connection to be up.
EXPECT_TRUE_SIMULATED_WAIT(client_dtls_transport_->writable() &&
server_dtls_transport_->writable(),
kTimeout, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] {
return client_dtls_transport_->writable() &&
server_dtls_transport_->writable();
},
::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
EXPECT_EQ(client_dtls_transport_->dtls_state(),
webrtc::DtlsTransportState::kConnected);
EXPECT_EQ(server_dtls_transport_->dtls_state(),
@ -174,8 +183,12 @@ class DtlsSrtpTransportIntegrationTest : public ::testing::Test {
EXPECT_TRUE(srtp_transport_.SendRtpPacket(&packet, options,
cricket::PF_SRTP_BYPASS));
EXPECT_TRUE_SIMULATED_WAIT(dtls_srtp_transport_observer_.rtp_count() == 1,
kTimeout, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return dtls_srtp_transport_observer_.rtp_count(); },
::testing::Eq(1),
{.timeout = webrtc::TimeDelta::Millis(kTimeout),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
EXPECT_EQ(1, dtls_srtp_transport_observer_.rtp_count());
ASSERT_TRUE(dtls_srtp_transport_observer_.last_recv_rtp_packet().data());
EXPECT_EQ(
@ -190,8 +203,12 @@ class DtlsSrtpTransportIntegrationTest : public ::testing::Test {
EXPECT_TRUE(dtls_srtp_transport_.SendRtpPacket(&packet, options,
cricket::PF_SRTP_BYPASS));
EXPECT_TRUE_SIMULATED_WAIT(srtp_transport_observer_.rtp_count() == 1,
kTimeout, fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil([&] { return srtp_transport_observer_.rtp_count(); },
::testing::Eq(1),
{.timeout = webrtc::TimeDelta::Millis(kTimeout),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
EXPECT_EQ(1, srtp_transport_observer_.rtp_count());
ASSERT_TRUE(srtp_transport_observer_.last_recv_rtp_packet().data());
EXPECT_EQ(

View File

@ -19,24 +19,24 @@
#include "api/make_ref_counted.h"
#include "api/rtc_error.h"
#include "api/scoped_refptr.h"
#include "api/test/rtc_error_matchers.h"
#include "p2p/base/p2p_constants.h"
#include "p2p/dtls/fake_dtls_transport.h"
#include "rtc_base/fake_ssl_identity.h"
#include "rtc_base/gunit.h"
#include "rtc_base/rtc_certificate.h"
#include "rtc_base/ssl_identity.h"
#include "rtc_base/thread.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/wait_until.h"
namespace webrtc {
constexpr int kDefaultTimeout = 1000; // milliseconds
constexpr int kNonsenseCipherSuite = 1234;
using cricket::FakeDtlsTransport;
using ::testing::ElementsAre;
namespace webrtc {
class TestDtlsTransportObserver : public DtlsTransportObserverInterface {
public:
void OnStateChange(DtlsTransportInformation info) override {
@ -48,7 +48,7 @@ class TestDtlsTransportObserver : public DtlsTransportObserverInterface {
void OnError(RTCError error) override {}
DtlsTransportState state() {
if (states_.size() > 0) {
if (!states_.empty()) {
return states_[states_.size() - 1];
} else {
return DtlsTransportState::kNew;
@ -111,7 +111,9 @@ TEST_F(DtlsTransportTest, EventsObservedWhenConnecting) {
CreateTransport();
transport()->RegisterObserver(observer());
CompleteDtlsHandshake();
ASSERT_TRUE_WAIT(observer_.state_change_called_, kDefaultTimeout);
ASSERT_THAT(WaitUntil([&] { return observer_.state_change_called_; },
::testing::IsTrue()),
IsRtcOk());
EXPECT_THAT(
observer_.states_,
ElementsAre( // FakeDtlsTransport doesn't signal the "connecting" state.
@ -124,11 +126,13 @@ TEST_F(DtlsTransportTest, CloseWhenClearing) {
CreateTransport();
transport()->RegisterObserver(observer());
CompleteDtlsHandshake();
ASSERT_TRUE_WAIT(observer_.state() == DtlsTransportState::kConnected,
kDefaultTimeout);
ASSERT_THAT(WaitUntil([&] { return observer_.state(); },
::testing::Eq(DtlsTransportState::kConnected)),
IsRtcOk());
transport()->Clear();
ASSERT_TRUE_WAIT(observer_.state() == DtlsTransportState::kClosed,
kDefaultTimeout);
ASSERT_THAT(WaitUntil([&] { return observer_.state(); },
::testing::Eq(DtlsTransportState::kClosed)),
IsRtcOk());
}
TEST_F(DtlsTransportTest, RoleAppearsOnConnect) {
@ -137,8 +141,9 @@ TEST_F(DtlsTransportTest, RoleAppearsOnConnect) {
transport()->RegisterObserver(observer());
EXPECT_FALSE(transport()->Information().role());
CompleteDtlsHandshake();
ASSERT_TRUE_WAIT(observer_.state() == DtlsTransportState::kConnected,
kDefaultTimeout);
ASSERT_THAT(WaitUntil([&] { return observer_.state(); },
::testing::Eq(DtlsTransportState::kConnected)),
IsRtcOk());
EXPECT_TRUE(observer_.info_.role());
EXPECT_TRUE(transport()->Information().role());
EXPECT_EQ(transport()->Information().role(), DtlsTransportTlsRole::kClient);
@ -149,8 +154,9 @@ TEST_F(DtlsTransportTest, CertificateAppearsOnConnect) {
CreateTransport(&fake_certificate);
transport()->RegisterObserver(observer());
CompleteDtlsHandshake();
ASSERT_TRUE_WAIT(observer_.state() == DtlsTransportState::kConnected,
kDefaultTimeout);
ASSERT_THAT(WaitUntil([&] { return observer_.state(); },
::testing::Eq(DtlsTransportState::kConnected)),
IsRtcOk());
EXPECT_TRUE(observer_.info_.remote_ssl_certificates() != nullptr);
}
@ -159,12 +165,14 @@ TEST_F(DtlsTransportTest, CertificateDisappearsOnClose) {
CreateTransport(&fake_certificate);
transport()->RegisterObserver(observer());
CompleteDtlsHandshake();
ASSERT_TRUE_WAIT(observer_.state() == DtlsTransportState::kConnected,
kDefaultTimeout);
ASSERT_THAT(WaitUntil([&] { return observer_.state(); },
::testing::Eq(DtlsTransportState::kConnected)),
IsRtcOk());
EXPECT_TRUE(observer_.info_.remote_ssl_certificates() != nullptr);
transport()->Clear();
ASSERT_TRUE_WAIT(observer_.state() == DtlsTransportState::kClosed,
kDefaultTimeout);
ASSERT_THAT(WaitUntil([&] { return observer_.state(); },
::testing::Eq(DtlsTransportState::kClosed)),
IsRtcOk());
EXPECT_FALSE(observer_.info_.remote_ssl_certificates());
}
@ -172,13 +180,15 @@ TEST_F(DtlsTransportTest, CipherSuiteVisibleWhenConnected) {
CreateTransport();
transport()->RegisterObserver(observer());
CompleteDtlsHandshake();
ASSERT_TRUE_WAIT(observer_.state() == DtlsTransportState::kConnected,
kDefaultTimeout);
ASSERT_THAT(WaitUntil([&] { return observer_.state(); },
::testing::Eq(DtlsTransportState::kConnected)),
IsRtcOk());
ASSERT_TRUE(observer_.info_.ssl_cipher_suite());
EXPECT_EQ(kNonsenseCipherSuite, *observer_.info_.ssl_cipher_suite());
transport()->Clear();
ASSERT_TRUE_WAIT(observer_.state() == DtlsTransportState::kClosed,
kDefaultTimeout);
ASSERT_THAT(WaitUntil([&] { return observer_.state(); },
::testing::Eq(DtlsTransportState::kClosed)),
IsRtcOk());
EXPECT_FALSE(observer_.info_.ssl_cipher_suite());
}

View File

@ -12,14 +12,21 @@
#include <stddef.h>
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
#include "api/dtmf_sender_interface.h"
#include "api/scoped_refptr.h"
#include "api/test/rtc_error_matchers.h"
#include "api/units/time_delta.h"
#include "rtc_base/fake_clock.h"
#include "rtc_base/gunit.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 webrtc::DtmfProviderInterface;
using webrtc::DtmfSender;
@ -55,7 +62,7 @@ class FakeDtmfObserver : public DtmfSenderObserverInterface {
const std::vector<std::string>& tones_from_single_argument_callback() const {
return tones_from_single_argument_callback_;
}
const std::string tones_remaining() { return tones_remaining_; }
std::string tones_remaining() { return tones_remaining_; }
bool completed() const { return completed_; }
private:
@ -117,7 +124,7 @@ class DtmfSenderTest : public ::testing::Test {
}
~DtmfSenderTest() {
if (dtmf_.get()) {
if (dtmf_) {
dtmf_->UnregisterObserver();
}
}
@ -225,7 +232,11 @@ TEST_F(DtmfSenderTest, InsertDtmf) {
int duration = 100;
int inter_tone_gap = 50;
EXPECT_TRUE(dtmf_->InsertDtmf(tones, duration, inter_tone_gap));
EXPECT_TRUE_SIMULATED_WAIT(observer_->completed(), kMaxWaitMs, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return observer_->completed(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kMaxWaitMs),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// The unrecognized characters should be ignored.
std::string known_tones = "1a*";
@ -241,14 +252,21 @@ TEST_F(DtmfSenderTest, InsertDtmfTwice) {
EXPECT_TRUE(dtmf_->InsertDtmf(tones1, duration, inter_tone_gap));
VerifyExpectedState(tones1, duration, inter_tone_gap);
// Wait until the first tone got sent.
EXPECT_TRUE_SIMULATED_WAIT(observer_->tones().size() == 1, kMaxWaitMs,
fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return observer_->tones().size(); }, ::testing::Eq(1),
{.timeout = webrtc::TimeDelta::Millis(kMaxWaitMs),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
VerifyExpectedState("2", duration, inter_tone_gap);
// Insert with another tone buffer.
EXPECT_TRUE(dtmf_->InsertDtmf(tones2, duration, inter_tone_gap));
VerifyExpectedState(tones2, duration, inter_tone_gap);
// Wait until it's completed.
EXPECT_TRUE_SIMULATED_WAIT(observer_->completed(), kMaxWaitMs, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return observer_->completed(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kMaxWaitMs),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
std::vector<FakeDtmfProvider::DtmfInfo> dtmf_queue_ref;
GetDtmfInfoFromString("1", duration, inter_tone_gap, &dtmf_queue_ref);
@ -263,13 +281,16 @@ TEST_F(DtmfSenderTest, InsertDtmfWhileProviderIsDeleted) {
int inter_tone_gap = 50;
EXPECT_TRUE(dtmf_->InsertDtmf(tones, duration, inter_tone_gap));
// Wait until the first tone got sent.
EXPECT_TRUE_SIMULATED_WAIT(observer_->tones().size() == 1, kMaxWaitMs,
fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return observer_->tones().size(); }, ::testing::Eq(1),
{.timeout = webrtc::TimeDelta::Millis(kMaxWaitMs),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// Delete provider.
dtmf_->OnDtmfProviderDestroyed();
provider_.reset();
// The queue should be discontinued so no more tone callbacks.
SIMULATED_WAIT(false, 200, fake_clock_);
fake_clock_.AdvanceTime(webrtc::TimeDelta::Millis(200));
EXPECT_EQ(1U, observer_->tones().size());
}
@ -279,12 +300,15 @@ TEST_F(DtmfSenderTest, InsertDtmfWhileSenderIsDeleted) {
int inter_tone_gap = 50;
EXPECT_TRUE(dtmf_->InsertDtmf(tones, duration, inter_tone_gap));
// Wait until the first tone got sent.
EXPECT_TRUE_SIMULATED_WAIT(observer_->tones().size() == 1, kMaxWaitMs,
fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return observer_->tones().size(); }, ::testing::Eq(1),
{.timeout = webrtc::TimeDelta::Millis(kMaxWaitMs),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// Delete the sender.
dtmf_ = NULL;
// The queue should be discontinued so no more tone callbacks.
SIMULATED_WAIT(false, 200, fake_clock_);
fake_clock_.AdvanceTime(webrtc::TimeDelta::Millis(200));
EXPECT_EQ(1U, observer_->tones().size());
}
@ -295,12 +319,19 @@ TEST_F(DtmfSenderTest, InsertEmptyTonesToCancelPreviousTask) {
int inter_tone_gap = 50;
EXPECT_TRUE(dtmf_->InsertDtmf(tones1, duration, inter_tone_gap));
// Wait until the first tone got sent.
EXPECT_TRUE_SIMULATED_WAIT(observer_->tones().size() == 1, kMaxWaitMs,
fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return observer_->tones().size(); }, ::testing::Eq(1),
{.timeout = webrtc::TimeDelta::Millis(kMaxWaitMs),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// Insert with another tone buffer.
EXPECT_TRUE(dtmf_->InsertDtmf(tones2, duration, inter_tone_gap));
// Wait until it's completed.
EXPECT_TRUE_SIMULATED_WAIT(observer_->completed(), kMaxWaitMs, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return observer_->completed(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kMaxWaitMs),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
std::vector<FakeDtmfProvider::DtmfInfo> dtmf_queue_ref;
GetDtmfInfoFromString("1", duration, inter_tone_gap, &dtmf_queue_ref);
@ -315,7 +346,11 @@ TEST_F(DtmfSenderTest, InsertDtmfWithDefaultCommaDelay) {
int default_comma_delay = webrtc::DtmfSender::kDtmfDefaultCommaDelayMs;
EXPECT_EQ(dtmf_->comma_delay(), default_comma_delay);
EXPECT_TRUE(dtmf_->InsertDtmf(tones, duration, inter_tone_gap));
EXPECT_TRUE_SIMULATED_WAIT(observer_->completed(), kMaxWaitMs, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return observer_->completed(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kMaxWaitMs),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
VerifyOnProvider(tones, duration, inter_tone_gap);
VerifyOnObserver(tones);
@ -330,7 +365,11 @@ TEST_F(DtmfSenderTest, InsertDtmfWithNonDefaultCommaDelay) {
int comma_delay = 500;
EXPECT_EQ(dtmf_->comma_delay(), default_comma_delay);
EXPECT_TRUE(dtmf_->InsertDtmf(tones, duration, inter_tone_gap, comma_delay));
EXPECT_TRUE_SIMULATED_WAIT(observer_->completed(), kMaxWaitMs, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return observer_->completed(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kMaxWaitMs),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
VerifyOnProvider(tones, duration, inter_tone_gap, comma_delay);
VerifyOnObserver(tones);
@ -365,7 +404,10 @@ TEST_F(DtmfSenderTest, InsertDtmfSendsAfterWait) {
EXPECT_TRUE(dtmf_->InsertDtmf(tones, duration, inter_tone_gap));
VerifyExpectedState("ABC", duration, inter_tone_gap);
// Wait until the first tone got sent.
EXPECT_TRUE_SIMULATED_WAIT(observer_->tones().size() == 1, kMaxWaitMs,
fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return observer_->tones().size(); }, ::testing::Eq(1),
{.timeout = webrtc::TimeDelta::Millis(kMaxWaitMs),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
VerifyExpectedState("BC", duration, inter_tone_gap);
}

View File

@ -27,8 +27,10 @@
#include "api/make_ref_counted.h"
#include "api/peer_connection_interface.h"
#include "api/scoped_refptr.h"
#include "api/test/rtc_error_matchers.h"
#include "api/transport/data_channel_transport_interface.h"
#include "api/transport/enums.h"
#include "api/units/time_delta.h"
#include "call/payload_type_picker.h"
#include "p2p/base/candidate_pair_interface.h"
#include "p2p/base/fake_ice_transport.h"
@ -47,7 +49,6 @@
#include "rtc_base/checks.h"
#include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/fake_ssl_identity.h"
#include "rtc_base/gunit.h"
#include "rtc_base/logging.h"
#include "rtc_base/net_helper.h"
#include "rtc_base/socket_address.h"
@ -57,13 +58,14 @@
#include "rtc_base/task_queue_for_test.h"
#include "rtc_base/third_party/sigslot/sigslot.h"
#include "rtc_base/thread.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/scoped_key_value_config.h"
#include "test/wait_until.h"
using cricket::Candidate;
using cricket::Candidates;
using cricket::FakeDtlsTransport;
using webrtc::SdpType;
static const int kTimeout = 100;
static const char kIceUfrag1[] = "u0001";
@ -562,7 +564,10 @@ TEST_F(JsepTransportControllerTest, MaybeStartGathering) {
// After setting the local description, we should be able to start gathering
// candidates.
transport_controller_->MaybeStartGathering();
EXPECT_EQ_WAIT(cricket::kIceGatheringGathering, gathering_state_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return cricket::kIceGatheringGathering; },
::testing::Eq(gathering_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(1, gathering_state_signal_count_);
}
@ -713,13 +718,23 @@ TEST_F(JsepTransportControllerTest, SignalConnectionStateFailed) {
fake_ice->SetConnectionCount(1);
// The connection stats will be failed if there is no active connection.
fake_ice->SetConnectionCount(0);
EXPECT_EQ_WAIT(cricket::kIceConnectionFailed, connection_state_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return cricket::kIceConnectionFailed; },
::testing::Eq(connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(1, connection_state_signal_count_);
EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionFailed,
ice_connection_state_, kTimeout);
EXPECT_THAT(
WaitUntil([&] { return PeerConnectionInterface::kIceConnectionFailed; },
::testing::Eq(ice_connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(1, ice_connection_state_signal_count_);
EXPECT_EQ_WAIT(PeerConnectionInterface::PeerConnectionState::kFailed,
combined_connection_state_, kTimeout);
EXPECT_THAT(
WaitUntil(
[&] { return PeerConnectionInterface::PeerConnectionState::kFailed; },
::testing::Eq(combined_connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(1, combined_connection_state_signal_count_);
}
@ -748,13 +763,23 @@ TEST_F(JsepTransportControllerTest,
fake_video_dtls->fake_ice_transport()->SetConnectionCount(0);
fake_video_dtls->fake_ice_transport()->SetCandidatesGatheringComplete();
EXPECT_EQ_WAIT(cricket::kIceConnectionFailed, connection_state_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return cricket::kIceConnectionFailed; },
::testing::Eq(connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(1, connection_state_signal_count_);
EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionFailed,
ice_connection_state_, kTimeout);
EXPECT_THAT(
WaitUntil([&] { return PeerConnectionInterface::kIceConnectionFailed; },
::testing::Eq(ice_connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(2, ice_connection_state_signal_count_);
EXPECT_EQ_WAIT(PeerConnectionInterface::PeerConnectionState::kFailed,
combined_connection_state_, kTimeout);
EXPECT_THAT(
WaitUntil(
[&] { return PeerConnectionInterface::PeerConnectionState::kFailed; },
::testing::Eq(combined_connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(2, combined_connection_state_signal_count_);
fake_audio_dtls->SetDtlsState(DtlsTransportState::kConnected);
@ -763,13 +788,26 @@ TEST_F(JsepTransportControllerTest,
// the transport state to be STATE_CONNECTING.
fake_video_dtls->fake_ice_transport()->SetConnectionCount(2);
fake_video_dtls->SetWritable(true);
EXPECT_EQ_WAIT(cricket::kIceConnectionConnected, connection_state_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return cricket::kIceConnectionConnected; },
::testing::Eq(connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(2, connection_state_signal_count_);
EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionConnected,
ice_connection_state_, kTimeout);
EXPECT_THAT(
WaitUntil(
[&] { return PeerConnectionInterface::kIceConnectionConnected; },
::testing::Eq(ice_connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(3, ice_connection_state_signal_count_);
EXPECT_EQ_WAIT(PeerConnectionInterface::PeerConnectionState::kConnected,
combined_connection_state_, kTimeout);
EXPECT_THAT(
WaitUntil(
[&] {
return PeerConnectionInterface::PeerConnectionState::kConnected;
},
::testing::Eq(combined_connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(3, combined_connection_state_signal_count_);
}
@ -795,24 +833,43 @@ TEST_F(JsepTransportControllerTest, SignalConnectionStateComplete) {
fake_audio_dtls->SetWritable(true);
fake_audio_dtls->fake_ice_transport()->SetCandidatesGatheringComplete();
EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
ice_connection_state_, kTimeout);
EXPECT_THAT(
WaitUntil([&] { return PeerConnectionInterface::kIceConnectionChecking; },
::testing::Eq(ice_connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(1, ice_connection_state_signal_count_);
EXPECT_EQ_WAIT(PeerConnectionInterface::PeerConnectionState::kConnecting,
combined_connection_state_, kTimeout);
EXPECT_THAT(
WaitUntil(
[&] {
return PeerConnectionInterface::PeerConnectionState::kConnecting;
},
::testing::Eq(combined_connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(1, combined_connection_state_signal_count_);
fake_video_dtls->fake_ice_transport()->SetTransportState(
IceTransportState::kFailed, cricket::IceTransportState::STATE_FAILED);
fake_video_dtls->fake_ice_transport()->SetCandidatesGatheringComplete();
EXPECT_EQ_WAIT(cricket::kIceConnectionFailed, connection_state_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return cricket::kIceConnectionFailed; },
::testing::Eq(connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(1, connection_state_signal_count_);
EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionFailed,
ice_connection_state_, kTimeout);
EXPECT_THAT(
WaitUntil([&] { return PeerConnectionInterface::kIceConnectionFailed; },
::testing::Eq(ice_connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(2, ice_connection_state_signal_count_);
EXPECT_EQ_WAIT(PeerConnectionInterface::PeerConnectionState::kFailed,
combined_connection_state_, kTimeout);
EXPECT_THAT(
WaitUntil(
[&] { return PeerConnectionInterface::PeerConnectionState::kFailed; },
::testing::Eq(combined_connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(2, combined_connection_state_signal_count_);
fake_audio_dtls->SetDtlsState(DtlsTransportState::kConnected);
@ -823,13 +880,26 @@ TEST_F(JsepTransportControllerTest, SignalConnectionStateComplete) {
IceTransportState::kCompleted,
cricket::IceTransportState::STATE_COMPLETED);
fake_video_dtls->SetWritable(true);
EXPECT_EQ_WAIT(cricket::kIceConnectionCompleted, connection_state_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return cricket::kIceConnectionCompleted; },
::testing::Eq(connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(3, connection_state_signal_count_);
EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
ice_connection_state_, kTimeout);
EXPECT_THAT(
WaitUntil(
[&] { return PeerConnectionInterface::kIceConnectionCompleted; },
::testing::Eq(ice_connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(3, ice_connection_state_signal_count_);
EXPECT_EQ_WAIT(PeerConnectionInterface::PeerConnectionState::kConnected,
combined_connection_state_, kTimeout);
EXPECT_THAT(
WaitUntil(
[&] {
return PeerConnectionInterface::PeerConnectionState::kConnected;
},
::testing::Eq(combined_connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(3, combined_connection_state_signal_count_);
}
@ -845,7 +915,10 @@ TEST_F(JsepTransportControllerTest, SignalIceGatheringStateGathering) {
transport_controller_->GetDtlsTransport(kAudioMid1));
fake_audio_dtls->fake_ice_transport()->MaybeStartGathering();
// Should be in the gathering state as soon as any transport starts gathering.
EXPECT_EQ_WAIT(cricket::kIceGatheringGathering, gathering_state_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return cricket::kIceGatheringGathering; },
::testing::Eq(gathering_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(1, gathering_state_signal_count_);
}
@ -863,7 +936,10 @@ TEST_F(JsepTransportControllerTest, SignalIceGatheringStateComplete) {
transport_controller_->GetDtlsTransport(kVideoMid1));
fake_audio_dtls->fake_ice_transport()->MaybeStartGathering();
EXPECT_EQ_WAIT(cricket::kIceGatheringGathering, gathering_state_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return cricket::kIceGatheringGathering; },
::testing::Eq(gathering_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(1, gathering_state_signal_count_);
// Have one transport finish gathering, to make sure gathering
@ -872,11 +948,17 @@ TEST_F(JsepTransportControllerTest, SignalIceGatheringStateComplete) {
EXPECT_EQ(1, gathering_state_signal_count_);
fake_video_dtls->fake_ice_transport()->MaybeStartGathering();
EXPECT_EQ_WAIT(cricket::kIceGatheringGathering, gathering_state_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return cricket::kIceGatheringGathering; },
::testing::Eq(gathering_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(1, gathering_state_signal_count_);
fake_video_dtls->fake_ice_transport()->SetCandidatesGatheringComplete();
EXPECT_EQ_WAIT(cricket::kIceGatheringComplete, gathering_state_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return cricket::kIceGatheringComplete; },
::testing::Eq(gathering_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(2, gathering_state_signal_count_);
}
@ -900,7 +982,10 @@ TEST_F(JsepTransportControllerTest,
EXPECT_NE(fake_audio_dtls, fake_video_dtls);
fake_audio_dtls->fake_ice_transport()->MaybeStartGathering();
EXPECT_EQ_WAIT(cricket::kIceGatheringGathering, gathering_state_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return cricket::kIceGatheringGathering; },
::testing::Eq(gathering_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(1, gathering_state_signal_count_);
// Let the audio transport complete.
@ -920,12 +1005,18 @@ TEST_F(JsepTransportControllerTest,
fake_video_dtls = static_cast<FakeDtlsTransport*>(
transport_controller_->GetDtlsTransport(kVideoMid1));
EXPECT_EQ(fake_audio_dtls, fake_video_dtls);
EXPECT_EQ_WAIT(cricket::kIceConnectionCompleted, connection_state_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return cricket::kIceConnectionCompleted; },
::testing::Eq(connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(PeerConnectionInterface::kIceConnectionCompleted,
ice_connection_state_);
EXPECT_EQ(PeerConnectionInterface::PeerConnectionState::kConnected,
combined_connection_state_);
EXPECT_EQ_WAIT(cricket::kIceGatheringComplete, gathering_state_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return cricket::kIceGatheringComplete; },
::testing::Eq(gathering_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(2, gathering_state_signal_count_);
}
@ -955,13 +1046,25 @@ TEST_F(JsepTransportControllerTest,
fake_audio_dtls->fake_ice_transport()->SetTransportState(
IceTransportState::kChecking,
cricket::IceTransportState::STATE_CONNECTING);
EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
ice_connection_state_, kTimeout);
EXPECT_THAT(
WaitUntil([&] { return PeerConnectionInterface::kIceConnectionChecking; },
::testing::Eq(ice_connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(1, ice_connection_state_signal_count_);
EXPECT_EQ_WAIT(PeerConnectionInterface::PeerConnectionState::kConnecting,
combined_connection_state_, kTimeout);
EXPECT_THAT(
WaitUntil(
[&] {
return PeerConnectionInterface::PeerConnectionState::kConnecting;
},
::testing::Eq(combined_connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(1, combined_connection_state_signal_count_);
EXPECT_EQ_WAIT(cricket::kIceGatheringGathering, gathering_state_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return cricket::kIceGatheringGathering; },
::testing::Eq(gathering_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(1, gathering_state_signal_count_);
// Reject m= section which should disconnect the transport and return states
@ -971,25 +1074,47 @@ TEST_F(JsepTransportControllerTest,
->SetRemoteDescription(SdpType::kOffer, description.get(),
description.get())
.ok());
EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionNew,
ice_connection_state_, kTimeout);
EXPECT_THAT(
WaitUntil([&] { return PeerConnectionInterface::kIceConnectionNew; },
::testing::Eq(ice_connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(2, ice_connection_state_signal_count_);
EXPECT_EQ_WAIT(PeerConnectionInterface::PeerConnectionState::kNew,
combined_connection_state_, kTimeout);
EXPECT_THAT(
WaitUntil(
[&] { return PeerConnectionInterface::PeerConnectionState::kNew; },
::testing::Eq(combined_connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(2, combined_connection_state_signal_count_);
EXPECT_EQ_WAIT(cricket::kIceGatheringNew, gathering_state_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return cricket::kIceGatheringNew; },
::testing::Eq(gathering_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(2, gathering_state_signal_count_);
// For good measure, rollback the offer and verify that states return to
// their previous values.
EXPECT_TRUE(transport_controller_->RollbackTransports().ok());
EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
ice_connection_state_, kTimeout);
EXPECT_THAT(
WaitUntil([&] { return PeerConnectionInterface::kIceConnectionChecking; },
::testing::Eq(ice_connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(3, ice_connection_state_signal_count_);
EXPECT_EQ_WAIT(PeerConnectionInterface::PeerConnectionState::kConnecting,
combined_connection_state_, kTimeout);
EXPECT_THAT(
WaitUntil(
[&] {
return PeerConnectionInterface::PeerConnectionState::kConnecting;
},
::testing::Eq(combined_connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(3, combined_connection_state_signal_count_);
EXPECT_EQ_WAIT(cricket::kIceGatheringGathering, gathering_state_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return cricket::kIceGatheringGathering; },
::testing::Eq(gathering_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(3, gathering_state_signal_count_);
}
@ -1006,7 +1131,10 @@ TEST_F(JsepTransportControllerTest, SignalCandidatesGathered) {
transport_controller_->GetDtlsTransport(kAudioMid1));
fake_audio_dtls->fake_ice_transport()->SignalCandidateGathered(
fake_audio_dtls->fake_ice_transport(), CreateCandidate(kAudioMid1, 1));
EXPECT_EQ_WAIT(1, candidates_signal_count_, kTimeout);
EXPECT_THAT(
WaitUntil([&] { return 1; }, ::testing::Eq(candidates_signal_count_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(1u, candidates_[kAudioMid1].size());
}
@ -1020,15 +1148,27 @@ TEST_F(JsepTransportControllerTest, IceSignalingOccursOnNetworkThread) {
CreateLocalDescriptionAndCompleteConnectionOnNetworkThread();
// connecting --> connected --> completed
EXPECT_EQ_WAIT(cricket::kIceConnectionCompleted, connection_state_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return cricket::kIceConnectionCompleted; },
::testing::Eq(connection_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(2, connection_state_signal_count_);
// new --> gathering --> complete
EXPECT_EQ_WAIT(cricket::kIceGatheringComplete, gathering_state_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return cricket::kIceGatheringComplete; },
::testing::Eq(gathering_state_),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(2, gathering_state_signal_count_);
EXPECT_EQ_WAIT(1u, candidates_[kAudioMid1].size(), kTimeout);
EXPECT_EQ_WAIT(1u, candidates_[kVideoMid1].size(), kTimeout);
EXPECT_THAT(WaitUntil([&] { return candidates_[kAudioMid1].size(); },
::testing::Eq(1u),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_THAT(WaitUntil([&] { return candidates_[kVideoMid1].size(); },
::testing::Eq(1u),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_EQ(2, candidates_signal_count_);
EXPECT_EQ(ice_signaled_on_thread_, network_thread_.get());

View File

@ -12,33 +12,33 @@
#include <memory>
#include <optional>
#include <string>
#include "api/adaptation/resource.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
#include "api/make_ref_counted.h"
#include "api/media_stream_interface.h"
#include "api/peer_connection_interface.h"
#include "api/rtc_error.h"
#include "api/rtp_parameters.h"
#include "api/rtp_sender_interface.h"
#include "api/scoped_refptr.h"
#include "api/test/rtc_error_matchers.h"
#include "api/video/video_source_interface.h"
#include "call/adaptation/test/fake_resource.h"
#include "pc/test/fake_periodic_video_source.h"
#include "pc/test/fake_periodic_video_track_source.h"
#include "pc/test/peer_connection_test_wrapper.h"
#include "rtc_base/checks.h"
#include "rtc_base/gunit.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/wait_until.h"
namespace webrtc {
const int64_t kDefaultTimeoutMs = 5000;
struct TrackWithPeriodicSource {
rtc::scoped_refptr<VideoTrackInterface> track;
rtc::scoped_refptr<FakePeriodicVideoTrackSource> periodic_track_source;
@ -132,10 +132,13 @@ TEST_F(PeerConnectionAdaptationIntegrationTest,
// Inject a fake resource and spam kOveruse until resolution becomes limited.
auto fake_resource = FakeResource::Create("FakeResource");
caller->AddAdaptationResource(fake_resource);
EXPECT_TRUE_WAIT(
TriggerOveruseAndGetSinkWants(fake_resource, source).max_pixel_count <
pixel_count_before_overuse,
kDefaultTimeoutMs);
EXPECT_THAT(WaitUntil(
[&] {
return TriggerOveruseAndGetSinkWants(fake_resource, source)
.max_pixel_count;
},
::testing::Lt(pixel_count_before_overuse)),
IsRtcOk());
}
TEST_F(PeerConnectionAdaptationIntegrationTest,
@ -163,10 +166,13 @@ TEST_F(PeerConnectionAdaptationIntegrationTest,
int pixel_count_before_overuse = source.wants().max_pixel_count;
// Spam kOveruse until resolution becomes limited.
EXPECT_TRUE_WAIT(
TriggerOveruseAndGetSinkWants(fake_resource, source).max_pixel_count <
pixel_count_before_overuse,
kDefaultTimeoutMs);
EXPECT_THAT(WaitUntil(
[&] {
return TriggerOveruseAndGetSinkWants(fake_resource, source)
.max_pixel_count;
},
::testing::Lt(pixel_count_before_overuse)),
IsRtcOk());
}
} // namespace webrtc

View File

@ -10,18 +10,14 @@
#include <stddef.h>
#include <cstdint>
#include <memory>
#include <ostream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
#include "api/audio/audio_device.h"
#include "api/audio/audio_mixer.h"
#include "api/audio/audio_processing.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
#include "api/candidate.h"
@ -33,9 +29,9 @@
#include "api/rtp_sender_interface.h"
#include "api/rtp_transceiver_interface.h"
#include "api/scoped_refptr.h"
#include "api/stats/rtc_stats.h"
#include "api/stats/rtc_stats_report.h"
#include "api/stats/rtcstats_objects.h"
#include "api/test/rtc_error_matchers.h"
#include "api/video_codecs/video_decoder_factory_template.h"
#include "api/video_codecs/video_decoder_factory_template_dav1d_adapter.h"
#include "api/video_codecs/video_decoder_factory_template_libvpx_vp8_adapter.h"
@ -47,8 +43,8 @@
#include "api/video_codecs/video_encoder_factory_template_libvpx_vp9_adapter.h"
#include "api/video_codecs/video_encoder_factory_template_open_h264_adapter.h"
#include "media/base/stream_params.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/transport_info.h"
#include "p2p/client/basic_port_allocator.h"
@ -66,16 +62,15 @@
#include "rtc_base/logging.h"
#include "rtc_base/net_helper.h"
#include "rtc_base/network.h"
#include "rtc_base/rtc_certificate_generator.h"
#include "rtc_base/socket_address.h"
#include "rtc_base/thread.h"
#include "test/gtest.h"
#include "test/wait_until.h"
#ifdef WEBRTC_ANDROID
#include "pc/test/android_test_initializer.h"
#endif
#include "pc/test/fake_audio_capture_module.h"
#include "rtc_base/fake_network.h"
#include "rtc_base/gunit.h"
#include "rtc_base/virtual_socket_server.h"
#include "test/gmock.h"
@ -87,7 +82,6 @@ using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
using RtcpMuxPolicy = PeerConnectionInterface::RtcpMuxPolicy;
using rtc::SocketAddress;
using ::testing::Combine;
using ::testing::ElementsAre;
using ::testing::UnorderedElementsAre;
using ::testing::Values;
@ -356,7 +350,9 @@ TEST_P(PeerConnectionBundleTest,
ASSERT_TRUE(caller->SetRemoteDescription(std::move(answer)));
// Check that caller has separate RTP and RTCP candidates for each media.
EXPECT_TRUE_WAIT(caller->IsIceGatheringDone(), kDefaultTimeout);
EXPECT_THAT(WaitUntil([&] { return caller->IsIceGatheringDone(); },
::testing::IsTrue()),
IsRtcOk());
EXPECT_THAT(
GetCandidateComponents(caller->observer()->GetCandidatesByMline(0)),
UnorderedElementsAre(cricket::ICE_CANDIDATE_COMPONENT_RTP,
@ -367,7 +363,9 @@ TEST_P(PeerConnectionBundleTest,
cricket::ICE_CANDIDATE_COMPONENT_RTCP));
// Check that callee has separate RTP and RTCP candidates for each media.
EXPECT_TRUE_WAIT(callee->IsIceGatheringDone(), kDefaultTimeout);
EXPECT_THAT(WaitUntil([&] { return callee->IsIceGatheringDone(); },
::testing::IsTrue()),
IsRtcOk());
EXPECT_THAT(
GetCandidateComponents(callee->observer()->GetCandidatesByMline(0)),
UnorderedElementsAre(cricket::ICE_CANDIDATE_COMPONENT_RTP,
@ -394,7 +392,9 @@ TEST_P(PeerConnectionBundleTest,
ASSERT_TRUE(
caller->SetRemoteDescription(callee->CreateAnswer(options_no_bundle)));
EXPECT_TRUE_WAIT(caller->IsIceGatheringDone(), kDefaultTimeout);
EXPECT_THAT(WaitUntil([&] { return caller->IsIceGatheringDone(); },
::testing::IsTrue()),
IsRtcOk());
EXPECT_EQ(1u, caller->observer()->GetCandidatesByMline(0).size());
EXPECT_EQ(1u, caller->observer()->GetCandidatesByMline(1).size());
@ -415,7 +415,9 @@ TEST_P(PeerConnectionBundleTest,
ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
ASSERT_TRUE(caller->SetRemoteDescription(callee->CreateAnswer()));
EXPECT_TRUE_WAIT(caller->IsIceGatheringDone(), kDefaultTimeout);
EXPECT_THAT(WaitUntil([&] { return caller->IsIceGatheringDone(); },
::testing::IsTrue()),
IsRtcOk());
EXPECT_EQ(1u, caller->observer()->GetCandidatesByMline(0).size());
EXPECT_EQ(0u, caller->observer()->GetCandidatesByMline(1).size());
@ -692,10 +694,20 @@ TEST_P(PeerConnectionBundleTest,
ASSERT_TRUE(caller->AddIceCandidateToMedia(&audio_candidate2,
cricket::MEDIA_TYPE_AUDIO));
EXPECT_TRUE_WAIT(caller->HasConnectionWithRemoteAddress(kAudioAddress1),
kDefaultTimeout);
EXPECT_TRUE_WAIT(caller->HasConnectionWithRemoteAddress(kAudioAddress2),
kDefaultTimeout);
EXPECT_THAT(
WaitUntil(
[&] {
return caller->HasConnectionWithRemoteAddress(kAudioAddress1);
},
::testing::IsTrue()),
IsRtcOk());
EXPECT_THAT(
WaitUntil(
[&] {
return caller->HasConnectionWithRemoteAddress(kAudioAddress2);
},
::testing::IsTrue()),
IsRtcOk());
EXPECT_FALSE(caller->HasConnectionWithRemoteAddress(kVideoAddress));
}

View File

@ -11,25 +11,22 @@
#include <stddef.h>
#include <memory>
#include <optional>
#include <ostream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
#include "api/audio/audio_device.h"
#include "api/audio/audio_mixer.h"
#include "api/audio/audio_processing.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
#include "api/create_peerconnection_factory.h"
#include "api/crypto/crypto_options.h"
#include "api/field_trials.h"
#include "api/jsep.h"
#include "api/make_ref_counted.h"
#include "api/peer_connection_interface.h"
#include "api/scoped_refptr.h"
#include "api/test/rtc_error_matchers.h"
#include "api/units/time_delta.h"
#include "api/video_codecs/video_decoder_factory_template.h"
#include "api/video_codecs/video_decoder_factory_template_dav1d_adapter.h"
#include "api/video_codecs/video_decoder_factory_template_libvpx_vp8_adapter.h"
@ -40,8 +37,8 @@
#include "api/video_codecs/video_encoder_factory_template_libvpx_vp8_adapter.h"
#include "api/video_codecs/video_encoder_factory_template_libvpx_vp9_adapter.h"
#include "api/video_codecs/video_encoder_factory_template_open_h264_adapter.h"
#include "p2p/base/basic_packet_socket_factory.h"
#include "p2p/base/fake_port_allocator.h"
#include "p2p/base/port_allocator.h"
#include "p2p/base/transport_description.h"
#include "p2p/base/transport_info.h"
#include "pc/media_protocol_names.h"
@ -57,12 +54,12 @@
#include "rtc_base/thread.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/wait_until.h"
#ifdef WEBRTC_ANDROID
#include "pc/test/android_test_initializer.h"
#endif
#include "pc/test/fake_audio_capture_module.h"
#include "pc/test/fake_rtc_certificate_generator.h"
#include "rtc_base/gunit.h"
#include "rtc_base/virtual_socket_server.h"
namespace webrtc {
@ -383,10 +380,15 @@ TEST_P(PeerConnectionCryptoDtlsCertGenTest, TestCertificateGeneration) {
pc->SetRemoteDescription(caller->CreateOfferAndSetAsLocal());
}
if (cert_gen_time_ == CertGenTime::kBefore) {
ASSERT_TRUE_WAIT(fake_certificate_generator->generated_certificates() +
fake_certificate_generator->generated_failures() >
0,
kGenerateCertTimeout);
ASSERT_THAT(
WaitUntil(
[&] {
return fake_certificate_generator->generated_certificates() +
fake_certificate_generator->generated_failures();
},
::testing::Gt(0),
{.timeout = webrtc::TimeDelta::Millis(kGenerateCertTimeout)}),
IsRtcOk());
} else {
ASSERT_EQ(fake_certificate_generator->generated_certificates(), 0);
fake_certificate_generator->set_should_wait(false);
@ -406,7 +408,9 @@ TEST_P(PeerConnectionCryptoDtlsCertGenTest, TestCertificateGeneration) {
}
}
for (auto& observer : observers) {
EXPECT_TRUE_WAIT(observer->called(), 1000);
EXPECT_THAT(
WaitUntil([&] { return observer->called(); }, ::testing::IsTrue()),
IsRtcOk());
if (cert_gen_result_ == CertGenResult::kSucceed) {
EXPECT_TRUE(observer->result());
} else {

View File

@ -15,7 +15,6 @@
#include <memory>
#include <optional>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
@ -35,19 +34,23 @@
#include "api/audio_options.h"
#include "api/data_channel_interface.h"
#include "api/environment/environment.h"
#include "api/make_ref_counted.h"
#include "api/media_stream_interface.h"
#include "api/peer_connection_interface.h"
#include "api/rtc_error.h"
#include "api/rtp_parameters.h"
#include "api/scoped_refptr.h"
#include "api/test/rtc_error_matchers.h"
#include "api/units/time_delta.h"
#include "media/sctp/sctp_transport_internal.h"
#include "rtc_base/checks.h"
#include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/gunit.h"
#include "rtc_base/physical_socket_server.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"
#ifdef WEBRTC_ANDROID
#include "pc/test/android_test_initializer.h"
@ -66,7 +69,6 @@ using ::testing::StrictMock;
using ::testing::Values;
using ::webrtc::DataChannelInterface;
using ::webrtc::Environment;
using ::webrtc::MediaStreamInterface;
using ::webrtc::PeerConnectionInterface;
using ::webrtc::SdpSemantics;
@ -184,14 +186,24 @@ class PeerConnectionEndToEndBaseTest : public sigslot::has_slots<>,
}
EXPECT_TRUE(dc1->Send(buffer));
EXPECT_EQ_WAIT(buffer.data,
rtc::CopyOnWriteBuffer(dc2_observer->last_message()),
kMaxWait);
EXPECT_THAT(
webrtc::WaitUntil(
[&] {
return rtc::CopyOnWriteBuffer(dc2_observer->last_message());
},
::testing::Eq(buffer.data),
{.timeout = webrtc::TimeDelta::Millis(kMaxWait)}),
webrtc::IsRtcOk());
EXPECT_TRUE(dc2->Send(buffer));
EXPECT_EQ_WAIT(buffer.data,
rtc::CopyOnWriteBuffer(dc1_observer->last_message()),
kMaxWait);
EXPECT_THAT(
webrtc::WaitUntil(
[&] {
return rtc::CopyOnWriteBuffer(dc1_observer->last_message());
},
::testing::Eq(buffer.data),
{.timeout = webrtc::TimeDelta::Millis(kMaxWait)}),
webrtc::IsRtcOk());
EXPECT_EQ(1U, dc1_observer->received_message_count());
EXPECT_EQ(size, dc1_observer->last_message().length());
@ -202,11 +214,22 @@ class PeerConnectionEndToEndBaseTest : public sigslot::has_slots<>,
void WaitForDataChannelsToOpen(DataChannelInterface* local_dc,
const DataChannelList& remote_dc_list,
size_t remote_dc_index) {
EXPECT_EQ_WAIT(DataChannelInterface::kOpen, local_dc->state(), kMaxWait);
EXPECT_THAT(
webrtc::WaitUntil([&] { return local_dc->state(); },
::testing::Eq(DataChannelInterface::kOpen),
{.timeout = webrtc::TimeDelta::Millis(kMaxWait)}),
webrtc::IsRtcOk());
ASSERT_TRUE_WAIT(remote_dc_list.size() > remote_dc_index, kMaxWait);
EXPECT_EQ_WAIT(DataChannelInterface::kOpen,
remote_dc_list[remote_dc_index]->state(), kMaxWait);
ASSERT_THAT(
webrtc::WaitUntil([&] { return remote_dc_list.size(); },
::testing::Gt(remote_dc_index),
{.timeout = webrtc::TimeDelta::Millis(kMaxWait)}),
webrtc::IsRtcOk());
EXPECT_THAT(webrtc::WaitUntil(
[&] { return remote_dc_list[remote_dc_index]->state(); },
::testing::Eq(DataChannelInterface::kOpen),
{.timeout = webrtc::TimeDelta::Millis(kMaxWait)}),
webrtc::IsRtcOk());
EXPECT_EQ(local_dc->id(), remote_dc_list[remote_dc_index]->id());
}
@ -214,9 +237,16 @@ class PeerConnectionEndToEndBaseTest : public sigslot::has_slots<>,
const DataChannelList& remote_dc_list,
size_t remote_dc_index) {
local_dc->Close();
EXPECT_EQ_WAIT(DataChannelInterface::kClosed, local_dc->state(), kMaxWait);
EXPECT_EQ_WAIT(DataChannelInterface::kClosed,
remote_dc_list[remote_dc_index]->state(), kMaxWait);
EXPECT_THAT(
webrtc::WaitUntil([&] { return local_dc->state(); },
::testing::Eq(DataChannelInterface::kClosed),
{.timeout = webrtc::TimeDelta::Millis(kMaxWait)}),
webrtc::IsRtcOk());
EXPECT_THAT(webrtc::WaitUntil(
[&] { return remote_dc_list[remote_dc_index]->state(); },
::testing::Eq(DataChannelInterface::kClosed),
{.timeout = webrtc::TimeDelta::Millis(kMaxWait)}),
webrtc::IsRtcOk());
}
protected:
@ -648,10 +678,18 @@ TEST_P(PeerConnectionEndToEndTest,
const std::string message_2 = "hello 2";
caller_dc_1->Send(webrtc::DataBuffer(message_1));
EXPECT_EQ_WAIT(message_1, dc_1_observer->last_message(), kMaxWait);
EXPECT_THAT(
webrtc::WaitUntil([&] { return dc_1_observer->last_message(); },
::testing::Eq(message_1),
{.timeout = webrtc::TimeDelta::Millis(kMaxWait)}),
webrtc::IsRtcOk());
caller_dc_2->Send(webrtc::DataBuffer(message_2));
EXPECT_EQ_WAIT(message_2, dc_2_observer->last_message(), kMaxWait);
EXPECT_THAT(
webrtc::WaitUntil([&] { return dc_2_observer->last_message(); },
::testing::Eq(message_2),
{.timeout = webrtc::TimeDelta::Millis(kMaxWait)}),
webrtc::IsRtcOk());
EXPECT_EQ(1U, dc_1_observer->received_message_count());
EXPECT_EQ(1U, dc_2_observer->received_message_count());
@ -679,7 +717,11 @@ TEST_P(PeerConnectionEndToEndTest,
// Previously, the channel on which Close is called reported being closed
// prematurely, and this caused issues; see bugs.webrtc.org/4453.
caller_dc->Close();
EXPECT_EQ_WAIT(DataChannelInterface::kClosed, caller_dc->state(), kMaxWait);
EXPECT_THAT(
webrtc::WaitUntil([&] { return caller_dc->state(); },
::testing::Eq(DataChannelInterface::kClosed),
{.timeout = webrtc::TimeDelta::Millis(kMaxWait)}),
webrtc::IsRtcOk());
// Create a new channel and ensure it works after closing the previous one.
caller_dc = caller_->CreateDataChannel("data2", init);
@ -712,7 +754,11 @@ TEST_P(PeerConnectionEndToEndTest, CloseDataChannelRemotelyWhileNotReferenced) {
// This removes the reference to the remote data channel that we hold.
callee_signaled_data_channels_.clear();
caller_dc->Close();
EXPECT_EQ_WAIT(DataChannelInterface::kClosed, caller_dc->state(), kMaxWait);
EXPECT_THAT(
webrtc::WaitUntil([&] { return caller_dc->state(); },
::testing::Eq(DataChannelInterface::kClosed),
{.timeout = webrtc::TimeDelta::Millis(kMaxWait)}),
webrtc::IsRtcOk());
// Wait for a bit longer so the remote data channel will receive the
// close message and be destroyed.
@ -733,8 +779,11 @@ TEST_P(PeerConnectionEndToEndTest, TooManyDataChannelsOpenedBeforeConnecting) {
}
Negotiate();
WaitForConnection();
EXPECT_EQ_WAIT(callee_signaled_data_channels_.size(),
static_cast<size_t>(cricket::kMaxSctpStreams / 2), kMaxWait);
EXPECT_THAT(
webrtc::WaitUntil([&] { return callee_signaled_data_channels_; },
::testing::SizeIs(cricket::kMaxSctpStreams / 2),
{.timeout = webrtc::TimeDelta::Millis(kMaxWait)}),
webrtc::IsRtcOk());
EXPECT_EQ(DataChannelInterface::kOpen,
channels[(cricket::kMaxSctpStreams / 2) - 1]->state());
EXPECT_EQ(DataChannelInterface::kClosed,

View File

@ -17,13 +17,13 @@
#include "api/jsep.h"
#include "api/jsep_session_description.h"
#include "api/make_ref_counted.h"
#include "api/peer_connection_interface.h"
#include "api/rtc_error.h"
#include "api/scoped_refptr.h"
#include "api/task_queue/default_task_queue_factory.h"
#include "api/task_queue/task_queue_factory.h"
#include "api/test/mock_async_dns_resolver.h"
#include "media/base/media_engine.h"
#include "api/test/rtc_error_matchers.h"
#include "p2p/base/port_allocator.h"
#include "p2p/client/basic_port_allocator.h"
#include "pc/peer_connection.h"
@ -40,20 +40,19 @@
#include "rtc_base/fake_mdns_responder.h"
#include "rtc_base/fake_network.h"
#include "rtc_base/gunit.h"
#include "rtc_base/mdns_responder_interface.h"
#include "rtc_base/socket_address.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/wait_until.h"
namespace webrtc {
using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
using ::testing::NiceMock;
using ::testing::Values;
static const char kUsagePatternMetric[] = "WebRTC.PeerConnection.UsagePattern";
static constexpr int kDefaultTimeout = 10000;
@ -206,7 +205,9 @@ class PeerConnectionWrapperForUsageHistogramTest
if (!set_local_offer) {
return false;
}
EXPECT_TRUE_WAIT(observer()->ice_gathering_complete_, kDefaultTimeout);
EXPECT_THAT(WaitUntil([&] { return observer()->ice_gathering_complete_; },
::testing::IsTrue()),
IsRtcOk());
return true;
}
@ -386,8 +387,10 @@ TEST_F(PeerConnectionUsageHistogramTest, UsageFingerprintHistogramFromTimeout) {
auto pc = CreatePeerConnectionWithImmediateReport();
int expected_fingerprint = MakeUsageFingerprint({});
EXPECT_METRIC_EQ_WAIT(1, metrics::NumSamples(kUsagePatternMetric),
kDefaultTimeout);
EXPECT_THAT(
WaitUntil([&] { return metrics::NumSamples(kUsagePatternMetric); },
::testing::Eq(1)),
IsRtcOk());
EXPECT_METRIC_EQ(
1, metrics::NumEvents(kUsagePatternMetric, expected_fingerprint));
}
@ -512,7 +515,9 @@ TEST_F(PeerConnectionUsageHistogramTest, FingerprintDataOnly) {
auto callee = CreatePeerConnection();
caller->CreateDataChannel("foodata");
ASSERT_TRUE(caller->ConnectTo(callee.get()));
ASSERT_TRUE_WAIT(callee->HaveDataChannel(), kDefaultTimeout);
ASSERT_THAT(
WaitUntil([&] { return callee->HaveDataChannel(); }, ::testing::IsTrue()),
IsRtcOk());
caller->pc()->Close();
callee->pc()->Close();
int expected_fingerprint = MakeUsageFingerprint(
@ -658,8 +663,10 @@ TEST_F(PeerConnectionUsageHistogramTest,
ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer()));
// Wait until the gathering completes so that the session description would
// have contained ICE candidates.
EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
caller->ice_gathering_state(), kDefaultTimeout);
EXPECT_THAT(
WaitUntil([&] { return caller->ice_gathering_state(); },
::testing::Eq(PeerConnectionInterface::kIceGatheringComplete)),
IsRtcOk());
EXPECT_TRUE(caller->observer()->candidate_gathered());
// Get the current offer that contains candidates and pass it to the callee.
//
@ -680,11 +687,18 @@ TEST_F(PeerConnectionUsageHistogramTest,
auto answer = callee->CreateAnswer();
callee->SetLocalDescription(CloneSessionDescription(answer.get()));
caller->SetRemoteDescription(std::move(answer));
EXPECT_TRUE_WAIT(caller->IsConnected(), kDefaultTimeout);
EXPECT_TRUE_WAIT(callee->IsConnected(), kDefaultTimeout);
EXPECT_THAT(
WaitUntil([&] { return caller->IsConnected(); }, ::testing::IsTrue()),
IsRtcOk());
EXPECT_THAT(
WaitUntil([&] { return callee->IsConnected(); }, ::testing::IsTrue()),
IsRtcOk());
// The callee needs to process the open message to have the data channel open.
EXPECT_TRUE_WAIT(callee->observer()->last_datachannel_ != nullptr,
kDefaultTimeout);
EXPECT_THAT(
WaitUntil(
[&] { return callee->observer()->last_datachannel_ != nullptr; },
::testing::IsTrue()),
IsRtcOk());
caller->pc()->Close();
callee->pc()->Close();
@ -741,8 +755,10 @@ TEST_F(PeerConnectionUsageHistogramTest, NotableUsageOnEventFiring) {
UsageEvent::CANDIDATE_COLLECTED});
EXPECT_METRIC_EQ(0, metrics::NumSamples(kUsagePatternMetric));
caller->GetInternalPeerConnection()->RequestUsagePatternReportForTesting();
EXPECT_METRIC_EQ_WAIT(1, metrics::NumSamples(kUsagePatternMetric),
kDefaultTimeout);
EXPECT_THAT(
WaitUntil([&] { return metrics::NumSamples(kUsagePatternMetric); },
::testing::Eq(1)),
IsRtcOk());
EXPECT_METRIC_TRUE(
expected_fingerprint == ObservedFingerprint() ||
(expected_fingerprint |
@ -765,8 +781,10 @@ TEST_F(PeerConnectionUsageHistogramTest,
EXPECT_METRIC_EQ(1, metrics::NumSamples(kUsagePatternMetric));
caller->GetInternalPeerConnection()->RequestUsagePatternReportForTesting();
caller->observer()->ClearInterestingUsageDetector();
EXPECT_METRIC_EQ_WAIT(2, metrics::NumSamples(kUsagePatternMetric),
kDefaultTimeout);
EXPECT_THAT(
WaitUntil([&] { return metrics::NumSamples(kUsagePatternMetric); },
::testing::Eq(2)),
IsRtcOk());
EXPECT_METRIC_TRUE(
expected_fingerprint == ObservedFingerprint() ||
(expected_fingerprint |

View File

@ -15,25 +15,26 @@
#include <optional>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
#include "api/audio/audio_device.h"
#include "api/audio/audio_mixer.h"
#include "api/audio/audio_processing.h"
#include "api/candidate.h"
#include "api/field_trials.h"
#include "api/ice_transport_interface.h"
#include "api/jsep.h"
#include "api/make_ref_counted.h"
#include "api/media_types.h"
#include "api/packet_socket_factory.h"
#include "api/peer_connection_interface.h"
#include "api/rtc_error.h"
#include "api/scoped_refptr.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/fake_port_allocator.h"
#include "p2p/base/ice_transport_internal.h"
#include "p2p/base/p2p_constants.h"
#include "p2p/base/port.h"
#include "p2p/base/port_allocator.h"
#include "p2p/base/transport_description.h"
#include "p2p/base/transport_info.h"
@ -51,10 +52,11 @@
#include "rtc_base/ip_address.h"
#include "rtc_base/logging.h"
#include "rtc_base/net_helper.h"
#include "rtc_base/rtc_certificate_generator.h"
#include "rtc_base/socket_address.h"
#include "rtc_base/socket_server.h"
#include "rtc_base/thread.h"
#include "test/gtest.h"
#include "test/wait_until.h"
#ifdef WEBRTC_ANDROID
#include "pc/test/android_test_initializer.h"
#endif
@ -76,7 +78,6 @@
#include "pc/test/fake_audio_capture_module.h"
#include "pc/test/mock_peer_connection_observers.h"
#include "rtc_base/fake_network.h"
#include "rtc_base/gunit.h"
#include "rtc_base/strings/string_builder.h"
#include "rtc_base/virtual_socket_server.h"
#include "system_wrappers/include/metrics.h"
@ -103,7 +104,7 @@ class PeerConnectionWrapperForIceTest : public PeerConnectionWrapper {
cricket::Candidate* candidate) {
RTC_DCHECK(pc()->remote_description());
const auto* desc = pc()->remote_description()->description();
RTC_DCHECK(desc->contents().size() > 0);
RTC_DCHECK(!desc->contents().empty());
const auto& first_content = desc->contents()[0];
candidate->set_transport_name(first_content.name);
return CreateIceCandidate(first_content.name, -1, *candidate);
@ -251,7 +252,7 @@ class PeerConnectionIceBaseTest : public ::testing::Test {
cricket::TransportDescription* GetFirstTransportDescription(
SessionDescriptionInterface* sdesc) {
auto* desc = sdesc->description();
RTC_DCHECK(desc->contents().size() > 0);
RTC_DCHECK(!desc->contents().empty());
auto* transport_info =
desc->GetTransportInfoByName(desc->contents()[0].name);
RTC_DCHECK(transport_info);
@ -261,7 +262,7 @@ class PeerConnectionIceBaseTest : public ::testing::Test {
const cricket::TransportDescription* GetFirstTransportDescription(
const SessionDescriptionInterface* sdesc) {
auto* desc = sdesc->description();
RTC_DCHECK(desc->contents().size() > 0);
RTC_DCHECK(!desc->contents().empty());
auto* transport_info =
desc->GetTransportInfoByName(desc->contents()[0].name);
RTC_DCHECK(transport_info);
@ -309,7 +310,7 @@ class PeerConnectionIceBaseTest : public ::testing::Test {
bool AddCandidateToFirstTransport(cricket::Candidate* candidate,
SessionDescriptionInterface* sdesc) {
auto* desc = sdesc->description();
RTC_DCHECK(desc->contents().size() > 0);
RTC_DCHECK(!desc->contents().empty());
const auto& first_content = desc->contents()[0];
candidate->set_transport_name(first_content.name);
std::unique_ptr<IceCandidateInterface> jsep_candidate =
@ -382,7 +383,11 @@ TEST_P(PeerConnectionIceTest, OfferContainsGatheredCandidates) {
// Start ICE candidate gathering by setting the local offer.
ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer()));
EXPECT_TRUE_WAIT(caller->IsIceGatheringDone(), kIceCandidatesTimeout);
EXPECT_THAT(
WaitUntil([&] { return caller->IsIceGatheringDone(); },
::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kIceCandidatesTimeout)}),
IsRtcOk());
auto offer = caller->CreateOffer();
EXPECT_LT(0u, caller->observer()->GetCandidatesByMline(0).size());
@ -403,7 +408,11 @@ TEST_P(PeerConnectionIceTest, AnswerContainsGatheredCandidates) {
ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
ASSERT_TRUE(callee->SetLocalDescription(callee->CreateAnswer()));
EXPECT_TRUE_WAIT(callee->IsIceGatheringDone(), kIceCandidatesTimeout);
EXPECT_THAT(
WaitUntil([&] { return callee->IsIceGatheringDone(); },
::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kIceCandidatesTimeout)}),
IsRtcOk());
auto* answer = callee->pc()->local_description();
EXPECT_LT(0u, caller->observer()->GetCandidatesByMline(0).size());
@ -723,7 +732,11 @@ TEST_P(PeerConnectionIceTest, CandidatesGeneratedForEachLocalInterface) {
caller->network()->AddInterface(kLocalAddress2);
caller->CreateOfferAndSetAsLocal();
EXPECT_TRUE_WAIT(caller->IsIceGatheringDone(), kIceCandidatesTimeout);
EXPECT_THAT(
WaitUntil([&] { return caller->IsIceGatheringDone(); },
::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kIceCandidatesTimeout)}),
IsRtcOk());
auto candidates = caller->observer()->GetCandidatesByMline(0);
EXPECT_PRED_FORMAT2(AssertIpInCandidates, kLocalAddress1, candidates);
@ -787,7 +800,10 @@ TEST_P(PeerConnectionIceTest, AsyncAddIceCandidateIsAddedToRemoteDescription) {
EXPECT_TRUE(result.ok());
operation_completed = true;
});
EXPECT_TRUE_WAIT(operation_completed, kWaitTimeout);
EXPECT_THAT(
WaitUntil([&] { return operation_completed; }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kWaitTimeout)}),
IsRtcOk());
auto candidates = callee->GetIceCandidatesFromRemoteDescription();
ASSERT_EQ(1u, candidates.size());
@ -836,7 +852,10 @@ TEST_P(PeerConnectionIceTest,
// The operation will not be able to complete until we EXPECT_TRUE_WAIT()
// allowing CreateAnswer() to complete.
EXPECT_FALSE(operation_completed);
EXPECT_TRUE_WAIT(answer_observer->called(), kWaitTimeout);
EXPECT_THAT(
WaitUntil([&] { return answer_observer->called(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kWaitTimeout)}),
IsRtcOk());
// As soon as it does, AddIceCandidate() will execute without delay, so it
// must also have completed.
EXPECT_TRUE(operation_completed);
@ -858,7 +877,10 @@ TEST_P(PeerConnectionIceTest,
std::string("The remote description was null"));
operation_completed = true;
});
EXPECT_TRUE_WAIT(operation_completed, kWaitTimeout);
EXPECT_THAT(
WaitUntil([&] { return operation_completed; }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kWaitTimeout)}),
IsRtcOk());
}
TEST_P(PeerConnectionIceTest,
@ -892,7 +914,10 @@ TEST_P(PeerConnectionIceTest,
EXPECT_FALSE(operation_completed);
// This should delete the callee PC.
callee = nullptr;
EXPECT_TRUE_WAIT(operation_completed, kWaitTimeout);
EXPECT_THAT(
WaitUntil([&] { return operation_completed; }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kWaitTimeout)}),
IsRtcOk());
}
TEST_P(PeerConnectionIceTest, LocalDescriptionUpdatedWhenContinualGathering) {
@ -909,9 +934,14 @@ TEST_P(PeerConnectionIceTest, LocalDescriptionUpdatedWhenContinualGathering) {
ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer()));
// Since we're using continual gathering, we won't get "gathering done".
EXPECT_TRUE_WAIT(
caller->pc()->local_description()->candidates(0)->count() > 0,
kIceCandidatesTimeout);
EXPECT_THAT(
WaitUntil(
[&] {
return caller->pc()->local_description()->candidates(0)->count();
},
::testing::Gt(0),
{.timeout = webrtc::TimeDelta::Millis(kIceCandidatesTimeout)}),
IsRtcOk());
}
// Test that when continual gathering is enabled, and a network interface goes
@ -931,16 +961,27 @@ TEST_P(PeerConnectionIceTest,
// Start ICE candidate gathering by setting the local offer.
ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer()));
EXPECT_TRUE_WAIT(
caller->pc()->local_description()->candidates(0)->count() > 0,
kIceCandidatesTimeout);
EXPECT_THAT(
WaitUntil(
[&] {
return caller->pc()->local_description()->candidates(0)->count();
},
::testing::Gt(0),
{.timeout = webrtc::TimeDelta::Millis(kIceCandidatesTimeout)}),
IsRtcOk());
// Remove the only network interface, causing the PeerConnection to signal
// the removal of all candidates derived from this interface.
caller->network()->RemoveInterface(kLocalAddress);
EXPECT_EQ_WAIT(0u, caller->pc()->local_description()->candidates(0)->count(),
kIceCandidatesTimeout);
EXPECT_THAT(
WaitUntil(
[&] {
return caller->pc()->local_description()->candidates(0)->count();
},
::testing::Eq(0u),
{.timeout = webrtc::TimeDelta::Millis(kIceCandidatesTimeout)}),
IsRtcOk());
EXPECT_LT(0, caller->observer()->num_candidates_removed_);
}
@ -957,7 +998,11 @@ TEST_P(PeerConnectionIceTest,
// Start ICE candidate gathering by setting the local offer.
ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer()));
EXPECT_TRUE_WAIT(caller->IsIceGatheringDone(), kIceCandidatesTimeout);
EXPECT_THAT(
WaitUntil([&] { return caller->IsIceGatheringDone(); },
::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kIceCandidatesTimeout)}),
IsRtcOk());
caller->network()->RemoveInterface(kLocalAddress);

File diff suppressed because it is too large Load Diff

View File

@ -13,15 +13,16 @@
#include <limits.h>
#include <stdint.h>
#include <cstddef>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "absl/strings/str_replace.h"
#include "absl/strings/string_view.h"
#include "api/audio/audio_device.h"
#include "api/audio/audio_mixer.h"
#include "api/audio/audio_processing.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
#include "api/create_peerconnection_factory.h"
@ -29,18 +30,25 @@
#include "api/enable_media_with_defaults.h"
#include "api/field_trials.h"
#include "api/jsep.h"
#include "api/make_ref_counted.h"
#include "api/media_stream_interface.h"
#include "api/media_types.h"
#include "api/packet_socket_factory.h"
#include "api/rtc_error.h"
#include "api/rtc_event_log/rtc_event_log.h"
#include "api/rtc_event_log/rtc_event_log_factory.h"
#include "api/rtc_event_log_output.h"
#include "api/rtp_parameters.h"
#include "api/rtp_receiver_interface.h"
#include "api/rtp_sender_interface.h"
#include "api/rtp_transceiver_direction.h"
#include "api/scoped_refptr.h"
#include "api/task_queue/default_task_queue_factory.h"
#include "api/test/rtc_error_matchers.h"
#include "api/transport/bitrate_settings.h"
#include "api/transport/enums.h"
#include "api/transport/field_trial_based_config.h"
#include "api/units/time_delta.h"
#include "api/video_codecs/video_decoder_factory_template.h"
#include "api/video_codecs/video_decoder_factory_template_dav1d_adapter.h"
#include "api/video_codecs/video_decoder_factory_template_libvpx_vp8_adapter.h"
@ -53,9 +61,7 @@
#include "api/video_codecs/video_encoder_factory_template_open_h264_adapter.h"
#include "media/base/codec.h"
#include "media/base/media_config.h"
#include "media/base/media_engine.h"
#include "media/base/stream_params.h"
#include "media/engine/webrtc_media_engine.h"
#include "media/sctp/sctp_transport_internal.h"
#include "p2p/base/fake_port_allocator.h"
#include "p2p/base/p2p_constants.h"
@ -79,13 +85,14 @@
#include "pc/test/test_sdp_strings.h"
#include "pc/video_track.h"
#include "rtc_base/checks.h"
#include "rtc_base/gunit.h"
#include "rtc_base/rtc_certificate_generator.h"
#include "rtc_base/socket_address.h"
#include "rtc_base/socket_server.h"
#include "rtc_base/thread.h"
#include "rtc_base/virtual_socket_server.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/wait_until.h"
#ifdef WEBRTC_ANDROID
#include "pc/test/android_test_initializer.h"
@ -857,7 +864,10 @@ class PeerConnectionInterfaceBaseTest : public ::testing::Test {
pc_->CreateAnswer(observer.get(),
options ? *options : RTCOfferAnswerOptions());
}
EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
EXPECT_THAT(
WaitUntil([&] { return observer->called(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
*desc = observer->MoveDescription();
return observer->result();
}
@ -882,7 +892,10 @@ class PeerConnectionInterfaceBaseTest : public ::testing::Test {
pc_->SetRemoteDescription(observer.get(), desc.release());
}
if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
EXPECT_THAT(
WaitUntil([&] { return observer->called(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
}
return observer->result();
}
@ -905,7 +918,10 @@ class PeerConnectionInterfaceBaseTest : public ::testing::Test {
if (!pc_->GetStats(observer.get(), track,
PeerConnectionInterface::kStatsOutputLevelStandard))
return false;
EXPECT_TRUE_WAIT(observer->called(), kTimeout);
EXPECT_THAT(
WaitUntil([&] { return observer->called(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
return observer->called();
}
@ -913,7 +929,10 @@ class PeerConnectionInterfaceBaseTest : public ::testing::Test {
bool DoGetRTCStats() {
auto callback = rtc::make_ref_counted<MockRTCStatsCollectorCallback>();
pc_->GetStats(callback.get());
EXPECT_TRUE_WAIT(callback->called(), kTimeout);
EXPECT_THAT(
WaitUntil([&] { return callback->called(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
return callback->called();
}
@ -1019,7 +1038,10 @@ class PeerConnectionInterfaceBaseTest : public ::testing::Test {
EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
// Wait for the ice_complete message, so that SDP will have candidates.
EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return observer_.ice_gathering_complete_; },
::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
}
void CreateAnswerAsRemoteDescription(const std::string& sdp) {
@ -1049,9 +1071,16 @@ class PeerConnectionInterfaceBaseTest : public ::testing::Test {
void WaitAndVerifyOnAddStream(const std::string& stream_id,
int expected_num_tracks) {
// Verify that both OnAddStream and OnAddTrack are called.
EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
EXPECT_EQ_WAIT(expected_num_tracks,
observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
EXPECT_THAT(WaitUntil([&] { return observer_.GetLastAddedStreamId(); },
::testing::Eq(stream_id),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_THAT(
WaitUntil(
[&] { return observer_.CountAddTrackEventsForStream(stream_id); },
::testing::Eq(expected_num_tracks),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
}
// Creates an offer and applies it as a local session description.
@ -1167,7 +1196,10 @@ class PeerConnectionInterfaceBaseTest : public ::testing::Test {
auto observer =
rtc::make_ref_counted<MockCreateSessionDescriptionObserver>();
pc_->CreateOffer(observer.get(), offer_answer_options);
EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
EXPECT_THAT(
WaitUntil([&] { return observer->called(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
return observer->MoveDescription();
}
@ -1759,8 +1791,14 @@ TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return observer_.last_candidate(); },
::testing::Ne(nullptr),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_THAT(WaitUntil([&] { return observer_.ice_gathering_complete_; },
::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
}
@ -2444,10 +2482,14 @@ TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
ASSERT_TRUE(audio_receiver);
ASSERT_TRUE(video_receiver);
// Track state may be updated asynchronously.
EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
audio_receiver->track()->state(), kTimeout);
EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
video_receiver->track()->state(), kTimeout);
EXPECT_THAT(WaitUntil([&] { return audio_receiver->track()->state(); },
::testing::Eq(MediaStreamTrackInterface::kEnded),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_THAT(WaitUntil([&] { return video_receiver->track()->state(); },
::testing::Eq(MediaStreamTrackInterface::kEnded),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
} else {
ASSERT_FALSE(audio_receiver);
ASSERT_FALSE(video_receiver);
@ -2567,10 +2609,14 @@ TEST_F(PeerConnectionInterfaceTestPlanB,
EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
reference_collection_.get()));
// Track state may be updated asynchronously.
EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, audio_track2->state(),
kTimeout);
EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, video_track2->state(),
kTimeout);
EXPECT_THAT(WaitUntil([&] { return audio_track2->state(); },
::testing::Eq(MediaStreamTrackInterface::kEnded),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_THAT(WaitUntil([&] { return video_track2->state(); },
::testing::Eq(MediaStreamTrackInterface::kEnded),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
}
// This tests that remote tracks are ended if a local session description is set
@ -2614,10 +2660,14 @@ TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
audio_info->rejected = true;
EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
// Track state may be updated asynchronously.
EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
kTimeout);
EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
kTimeout);
EXPECT_THAT(WaitUntil([&] { return remote_audio->state(); },
::testing::Eq(MediaStreamTrackInterface::kEnded),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
EXPECT_THAT(WaitUntil([&] { return remote_video->state(); },
::testing::Eq(MediaStreamTrackInterface::kEnded),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
}
// This tests that we won't crash if the remote track has been removed outside
@ -3603,22 +3653,34 @@ TEST_F(PeerConnectionInterfaceTestPlanB,
rtc::scoped_refptr<VideoTrackInterface> video_track(
CreateVideoTrack("video_track"));
stream->AddTrack(audio_track);
EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return observer_.renegotiation_needed_; },
::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
observer_.renegotiation_needed_ = false;
CreateOfferReceiveAnswer();
stream->AddTrack(video_track);
EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return observer_.renegotiation_needed_; },
::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
observer_.renegotiation_needed_ = false;
CreateOfferReceiveAnswer();
stream->RemoveTrack(audio_track);
EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return observer_.renegotiation_needed_; },
::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
observer_.renegotiation_needed_ = false;
CreateOfferReceiveAnswer();
stream->RemoveTrack(video_track);
EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
EXPECT_THAT(WaitUntil([&] { return observer_.renegotiation_needed_; },
::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
IsRtcOk());
observer_.renegotiation_needed_ = false;
}
@ -3704,7 +3766,7 @@ class PeerConnectionMediaConfigTest : public ::testing::Test {
void SetUp() override {
pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
}
const cricket::MediaConfig TestCreatePeerConnection(
cricket::MediaConfig TestCreatePeerConnection(
const RTCConfiguration& config) {
PeerConnectionDependencies pc_dependencies(&observer_);
auto result =

View File

@ -15,13 +15,12 @@
#include <vector>
#include "api/audio/audio_device.h"
#include "api/audio/audio_mixer.h"
#include "api/audio/audio_processing.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
#include "api/audio_options.h"
#include "api/create_peerconnection_factory.h"
#include "api/jsep.h"
#include "api/make_ref_counted.h"
#include "api/media_stream_interface.h"
#include "api/peer_connection_interface.h"
#include "api/rtc_error.h"
@ -31,6 +30,7 @@
#include "api/stats/rtcstats_objects.h"
#include "api/test/metrics/global_metrics_logger_and_exporter.h"
#include "api/test/metrics/metric.h"
#include "api/test/rtc_error_matchers.h"
#include "api/video_codecs/video_decoder_factory_template.h"
#include "api/video_codecs/video_decoder_factory_template_dav1d_adapter.h"
#include "api/video_codecs/video_decoder_factory_template_libvpx_vp8_adapter.h"
@ -41,6 +41,7 @@
#include "api/video_codecs/video_encoder_factory_template_libvpx_vp8_adapter.h"
#include "api/video_codecs/video_encoder_factory_template_libvpx_vp9_adapter.h"
#include "api/video_codecs/video_encoder_factory_template_open_h264_adapter.h"
#include "p2p/base/basic_packet_socket_factory.h"
#include "p2p/base/port_allocator.h"
#include "p2p/base/port_interface.h"
#include "p2p/base/test_turn_server.h"
@ -54,16 +55,16 @@
#include "rtc_base/crypto_random.h"
#include "rtc_base/fake_network.h"
#include "rtc_base/firewall_socket_server.h"
#include "rtc_base/gunit.h"
#include "rtc_base/socket_address.h"
#include "rtc_base/socket_factory.h"
#include "rtc_base/ssl_certificate.h"
#include "rtc_base/task_queue_for_test.h"
#include "rtc_base/test_certificate_verifier.h"
#include "rtc_base/thread.h"
#include "rtc_base/virtual_socket_server.h"
#include "system_wrappers/include/clock.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/wait_until.h"
namespace webrtc {
namespace {
@ -75,7 +76,6 @@ using ::webrtc::test::Unit;
static const int kDefaultTestTimeMs = 15000;
static const int kRampUpTimeMs = 5000;
static const int kPollIntervalTimeMs = 50;
static const int kDefaultTimeoutMs = 10000;
static const rtc::SocketAddress kDefaultLocalAddress("1.1.1.1", 0);
static const char kTurnInternalAddress[] = "88.88.88.0";
static const char kTurnExternalAddress[] = "88.88.88.1";
@ -234,11 +234,15 @@ class PeerConnectionRampUpTest : public ::testing::Test {
// Do the SDP negotiation, and also exchange ice candidates.
ASSERT_TRUE(caller_->ExchangeOfferAnswerWith(callee_.get()));
ASSERT_TRUE_WAIT(
caller_->signaling_state() == PeerConnectionInterface::kStable,
kDefaultTimeoutMs);
ASSERT_TRUE_WAIT(caller_->IsIceGatheringDone(), kDefaultTimeoutMs);
ASSERT_TRUE_WAIT(callee_->IsIceGatheringDone(), kDefaultTimeoutMs);
ASSERT_THAT(WaitUntil([&] { return caller_->signaling_state(); },
::testing::Eq(PeerConnectionInterface::kStable)),
IsRtcOk());
ASSERT_THAT(WaitUntil([&] { return caller_->IsIceGatheringDone(); },
::testing::IsTrue()),
IsRtcOk());
ASSERT_THAT(WaitUntil([&] { return callee_->IsIceGatheringDone(); },
::testing::IsTrue()),
IsRtcOk());
// Connect an ICE candidate pairs.
ASSERT_TRUE(
@ -246,8 +250,12 @@ class PeerConnectionRampUpTest : public ::testing::Test {
ASSERT_TRUE(
caller_->AddIceCandidates(callee_->observer()->GetAllCandidates()));
// This means that ICE and DTLS are connected.
ASSERT_TRUE_WAIT(callee_->IsIceConnected(), kDefaultTimeoutMs);
ASSERT_TRUE_WAIT(caller_->IsIceConnected(), kDefaultTimeoutMs);
ASSERT_THAT(WaitUntil([&] { return callee_->IsIceConnected(); },
::testing::IsTrue()),
IsRtcOk());
ASSERT_THAT(WaitUntil([&] { return caller_->IsIceConnected(); },
::testing::IsTrue()),
IsRtcOk());
}
void CreateTurnServer(cricket::ProtocolType type,
@ -308,7 +316,7 @@ class PeerConnectionRampUpTest : public ::testing::Test {
double GetCallerAvailableBitrateEstimate() {
auto stats = caller_->GetStats();
auto transport_stats = stats->GetStatsOfType<RTCTransportStats>();
if (transport_stats.size() == 0u ||
if (transport_stats.empty() ||
!transport_stats[0]->selected_candidate_pair_id.has_value()) {
return 0;
}

View File

@ -17,13 +17,11 @@
#include <utility>
#include <vector>
#include "api/audio/audio_device.h"
#include "api/audio/audio_mixer.h"
#include "api/audio/audio_processing.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
#include "api/create_peerconnection_factory.h"
#include "api/jsep.h"
#include "api/make_ref_counted.h"
#include "api/media_stream_interface.h"
#include "api/media_types.h"
#include "api/peer_connection_interface.h"
@ -35,7 +33,8 @@
#include "api/rtp_transceiver_interface.h"
#include "api/scoped_refptr.h"
#include "api/set_remote_description_observer_interface.h"
#include "api/uma_metrics.h"
#include "api/test/rtc_error_matchers.h"
#include "api/video_codecs/sdp_video_format.h"
#include "api/video_codecs/video_decoder_factory_template.h"
#include "api/video_codecs/video_decoder_factory_template_dav1d_adapter.h"
#include "api/video_codecs/video_decoder_factory_template_libvpx_vp8_adapter.h"
@ -46,8 +45,8 @@
#include "api/video_codecs/video_encoder_factory_template_libvpx_vp8_adapter.h"
#include "api/video_codecs/video_encoder_factory_template_libvpx_vp9_adapter.h"
#include "api/video_codecs/video_encoder_factory_template_open_h264_adapter.h"
#include "media/base/codec.h"
#include "media/base/stream_params.h"
#include "p2p/base/port_allocator.h"
#include "pc/media_session.h"
#include "pc/peer_connection_wrapper.h"
#include "pc/sdp_utils.h"
@ -56,12 +55,11 @@
#include "pc/test/integration_test_helpers.h"
#include "pc/test/mock_peer_connection_observers.h"
#include "rtc_base/checks.h"
#include "rtc_base/gunit.h"
#include "rtc_base/rtc_certificate_generator.h"
#include "rtc_base/thread.h"
#include "system_wrappers/include/metrics.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/wait_until.h"
// This file contains tests for RTP Media API-related behavior of
// `webrtc::PeerConnection`, see https://w3c.github.io/webrtc-pc/#rtp-media-api.
@ -70,7 +68,6 @@ namespace webrtc {
using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
using ::testing::ElementsAre;
using ::testing::Pair;
using ::testing::UnorderedElementsAre;
using ::testing::Values;
@ -757,8 +754,12 @@ TEST_F(PeerConnectionRtpTestPlanB,
std::move(srd2_sdp),
rtc::make_ref_counted<OnSuccessObserver<decltype(srd2_callback)>>(
srd2_callback));
EXPECT_TRUE_WAIT(srd1_callback_called, kDefaultTimeout);
EXPECT_TRUE_WAIT(srd2_callback_called, kDefaultTimeout);
EXPECT_THAT(
WaitUntil([&] { return srd1_callback_called; }, ::testing::IsTrue()),
IsRtcOk());
EXPECT_THAT(
WaitUntil([&] { return srd2_callback_called; }, ::testing::IsTrue()),
IsRtcOk());
}
// Tests that a remote track is created with the signaled MSIDs when they are

View File

@ -20,18 +20,16 @@
#include <set>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
#include "api/audio/audio_device.h"
#include "api/audio/audio_mixer.h"
#include "api/audio/audio_processing.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
#include "api/create_peerconnection_factory.h"
#include "api/dtls_transport_interface.h"
#include "api/jsep.h"
#include "api/make_ref_counted.h"
#include "api/media_types.h"
#include "api/peer_connection_interface.h"
#include "api/rtc_error.h"
@ -39,8 +37,8 @@
#include "api/rtp_sender_interface.h"
#include "api/rtp_transceiver_interface.h"
#include "api/scoped_refptr.h"
#include "api/set_local_description_observer_interface.h"
#include "api/set_remote_description_observer_interface.h"
#include "api/test/rtc_error_matchers.h"
#include "api/units/time_delta.h"
#include "api/video_codecs/video_decoder_factory_template.h"
#include "api/video_codecs/video_decoder_factory_template_dav1d_adapter.h"
#include "api/video_codecs/video_decoder_factory_template_libvpx_vp8_adapter.h"
@ -52,7 +50,6 @@
#include "api/video_codecs/video_encoder_factory_template_libvpx_vp9_adapter.h"
#include "api/video_codecs/video_encoder_factory_template_open_h264_adapter.h"
#include "media/base/codec.h"
#include "p2p/base/port_allocator.h"
#include "pc/peer_connection.h"
#include "pc/peer_connection_proxy.h"
#include "pc/peer_connection_wrapper.h"
@ -60,18 +57,16 @@
#include "pc/session_description.h"
#include "pc/test/mock_peer_connection_observers.h"
#include "rtc_base/checks.h"
#include "rtc_base/rtc_certificate.h"
#include "rtc_base/rtc_certificate_generator.h"
#include "rtc_base/string_encode.h"
#include "rtc_base/thread.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/wait_until.h"
#ifdef WEBRTC_ANDROID
#include "pc/test/android_test_initializer.h"
#endif
#include "pc/test/fake_audio_capture_module.h"
#include "pc/test/fake_rtc_certificate_generator.h"
#include "rtc_base/gunit.h"
#include "rtc_base/virtual_socket_server.h"
namespace webrtc {
@ -595,7 +590,10 @@ TEST_P(PeerConnectionSignalingTest, CreateOffersAndShutdown) {
// We expect to have received a notification now even if the PeerConnection
// was terminated. The offer creation may or may not have succeeded, but we
// must have received a notification.
EXPECT_TRUE_WAIT(observer->called(), kWaitTimeout);
EXPECT_THAT(
WaitUntil([&] { return observer->called(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kWaitTimeout)}),
IsRtcOk());
}
}
@ -609,7 +607,9 @@ TEST_P(PeerConnectionSignalingTest, CloseCreateOfferAndShutdown) {
caller->pc()->Close();
caller->pc()->CreateOffer(observer.get(), RTCOfferAnswerOptions());
caller.reset(nullptr);
EXPECT_TRUE_WAIT(observer->called(), kWaitTimeout);
EXPECT_THAT(WaitUntil([&] { return observer->called(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kWaitTimeout)}),
IsRtcOk());
}
TEST_P(PeerConnectionSignalingTest,
@ -701,7 +701,9 @@ TEST_P(PeerConnectionSignalingTest,
bool checkpoint_reached = false;
rtc::Thread::Current()->PostTask(
[&checkpoint_reached] { checkpoint_reached = true; });
EXPECT_TRUE_WAIT(checkpoint_reached, kWaitTimeout);
EXPECT_THAT(WaitUntil([&] { return checkpoint_reached; }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kWaitTimeout)}),
IsRtcOk());
// If resolving the observer was pending, it must now have been called.
EXPECT_TRUE(observer->called());
}
@ -745,7 +747,10 @@ TEST_P(PeerConnectionSignalingTest, CreateOfferBlocksSetRemoteDescription) {
// yet.
EXPECT_EQ(0u, callee->pc()->GetReceivers().size());
// EXPECT_TRUE_WAIT causes messages to be processed...
EXPECT_TRUE_WAIT(offer_observer->called(), kWaitTimeout);
EXPECT_THAT(
WaitUntil([&] { return offer_observer->called(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kWaitTimeout)}),
IsRtcOk());
// Now that the offer has been completed, SetRemoteDescription() will have
// been executed next in the chain.
EXPECT_EQ(2u, callee->pc()->GetReceivers().size());
@ -765,7 +770,9 @@ TEST_P(PeerConnectionSignalingTest,
EXPECT_EQ(PeerConnection::kStable, caller->signaling_state());
// Wait for messages to be processed.
EXPECT_TRUE_WAIT(observer->called(), kWaitTimeout);
EXPECT_THAT(WaitUntil([&] { return observer->called(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kWaitTimeout)}),
IsRtcOk());
EXPECT_TRUE(observer->result());
EXPECT_TRUE(caller->pc()->pending_local_description());
EXPECT_EQ(SdpType::kOffer,
@ -790,7 +797,9 @@ TEST_P(PeerConnectionSignalingTest,
EXPECT_FALSE(callee->pc()->current_local_description());
// Wait for messages to be processed.
EXPECT_TRUE_WAIT(observer->called(), kWaitTimeout);
EXPECT_THAT(WaitUntil([&] { return observer->called(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kWaitTimeout)}),
IsRtcOk());
EXPECT_TRUE(observer->result());
EXPECT_TRUE(callee->pc()->current_local_description());
EXPECT_EQ(SdpType::kAnswer,
@ -808,8 +817,11 @@ TEST_P(PeerConnectionSignalingTest,
MockSetSessionDescriptionObserver::Create();
caller->pc()->SetLocalDescription(
caller_set_local_description_observer.get());
EXPECT_TRUE_WAIT(caller_set_local_description_observer->called(),
kWaitTimeout);
EXPECT_THAT(
WaitUntil([&] { return caller_set_local_description_observer->called(); },
::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kWaitTimeout)}),
IsRtcOk());
ASSERT_TRUE(caller->pc()->pending_local_description());
// SetRemoteDescription(offer)
@ -825,8 +837,11 @@ TEST_P(PeerConnectionSignalingTest,
MockSetSessionDescriptionObserver::Create();
callee->pc()->SetLocalDescription(
callee_set_local_description_observer.get());
EXPECT_TRUE_WAIT(callee_set_local_description_observer->called(),
kWaitTimeout);
EXPECT_THAT(
WaitUntil([&] { return callee_set_local_description_observer->called(); },
::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kWaitTimeout)}),
IsRtcOk());
// Chaining guarantees SetRemoteDescription() happened before
// SetLocalDescription().
EXPECT_TRUE(callee_set_remote_description_observer->called());
@ -839,8 +854,12 @@ TEST_P(PeerConnectionSignalingTest,
caller_set_remote_description_observer.get(),
CloneSessionDescription(callee->pc()->current_local_description())
.release());
EXPECT_TRUE_WAIT(caller_set_remote_description_observer->called(),
kWaitTimeout);
EXPECT_THAT(
WaitUntil(
[&] { return caller_set_remote_description_observer->called(); },
::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kWaitTimeout)}),
IsRtcOk());
EXPECT_EQ(PeerConnection::kStable, caller->signaling_state());
EXPECT_EQ(PeerConnection::kStable, callee->signaling_state());
@ -856,7 +875,9 @@ TEST_P(PeerConnectionSignalingTest,
// The operation should fail asynchronously.
EXPECT_FALSE(observer->called());
EXPECT_TRUE_WAIT(observer->called(), kWaitTimeout);
EXPECT_THAT(WaitUntil([&] { return observer->called(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kWaitTimeout)}),
IsRtcOk());
EXPECT_FALSE(observer->result());
// This did not affect the signaling state.
EXPECT_EQ(PeerConnection::kClosed, caller->pc()->signaling_state());
@ -876,7 +897,9 @@ TEST_P(PeerConnectionSignalingTest,
// The operation should fail asynchronously.
EXPECT_FALSE(observer->called());
EXPECT_TRUE_WAIT(observer->called(), kWaitTimeout);
EXPECT_THAT(WaitUntil([&] { return observer->called(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kWaitTimeout)}),
IsRtcOk());
EXPECT_FALSE(observer->result());
// This did not affect the signaling state.
EXPECT_EQ(PeerConnection::kClosed, caller->pc()->signaling_state());
@ -1175,7 +1198,10 @@ TEST_F(PeerConnectionSignalingUnifiedPlanTest,
EXPECT_TRUE(pc->GetTransceivers()[0]->mid().has_value());
});
caller->pc()->CreateOffer(offer_observer.get(), RTCOfferAnswerOptions());
EXPECT_TRUE_WAIT(offer_observer->was_called(), kWaitTimeout);
EXPECT_THAT(WaitUntil([&] { return offer_observer->was_called(); },
::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kWaitTimeout)}),
IsRtcOk());
}
// Test that transports are shown in the sender/receiver API after offer/answer.
@ -1272,7 +1298,9 @@ TEST_F(PeerConnectionSignalingUnifiedPlanTest,
// When the Operations Chain becomes empty again, a new negotiation needed
// event will be generated that is not suppressed.
EXPECT_TRUE_WAIT(observer->called(), kWaitTimeout);
EXPECT_THAT(WaitUntil([&] { return observer->called(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kWaitTimeout)}),
IsRtcOk());
EXPECT_TRUE(caller->observer()->has_negotiation_needed_event());
EXPECT_TRUE(caller->pc()->ShouldFireNegotiationNeededEvent(
caller->observer()->latest_negotiation_needed_event()));

View File

@ -13,18 +13,23 @@
#include <stdint.h>
#include <functional>
#include <algorithm>
#include <vector>
#include "absl/strings/match.h"
#include "absl/strings/string_view.h"
#include "api/media_types.h"
#include "api/peer_connection_interface.h"
#include "api/rtc_error.h"
#include "api/rtp_parameters.h"
#include "api/rtp_transceiver_interface.h"
#include "api/scoped_refptr.h"
#include "api/test/rtc_error_matchers.h"
#include "media/base/media_constants.h"
#include "pc/test/integration_test_helpers.h"
#include "rtc_base/crypto_random.h"
#include "rtc_base/gunit.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/wait_until.h"
namespace webrtc {
@ -134,7 +139,9 @@ TEST_F(PeerConnectionSVCIntegrationTest,
EXPECT_TRUE(SetCodecPreferences(transceiver, cricket::kVp8CodecName).ok());
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_THAT(
WaitUntil([&] { return SignalingStateStable(); }, ::testing::IsTrue()),
IsRtcOk());
RtpParameters parameters = transceiver->sender()->GetParameters();
ASSERT_EQ(parameters.encodings.size(), 1u);
@ -158,7 +165,9 @@ TEST_F(PeerConnectionSVCIntegrationTest,
EXPECT_TRUE(SetCodecPreferences(transceiver, cricket::kVp9CodecName).ok());
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_THAT(
WaitUntil([&] { return SignalingStateStable(); }, ::testing::IsTrue()),
IsRtcOk());
RtpParameters parameters = transceiver->sender()->GetParameters();
ASSERT_EQ(parameters.encodings.size(), 1u);
@ -182,7 +191,9 @@ TEST_F(PeerConnectionSVCIntegrationTest,
EXPECT_TRUE(SetCodecPreferences(transceiver, cricket::kVp8CodecName).ok());
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_THAT(
WaitUntil([&] { return SignalingStateStable(); }, ::testing::IsTrue()),
IsRtcOk());
RtpParameters parameters = transceiver->sender()->GetParameters();
ASSERT_EQ(parameters.encodings.size(), 1u);
@ -207,7 +218,9 @@ TEST_F(PeerConnectionSVCIntegrationTest,
EXPECT_TRUE(SetCodecPreferences(transceiver, cricket::kVp9CodecName).ok());
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_THAT(
WaitUntil([&] { return SignalingStateStable(); }, ::testing::IsTrue()),
IsRtcOk());
RtpParameters parameters = transceiver->sender()->GetParameters();
ASSERT_EQ(parameters.encodings.size(), 1u);
@ -251,7 +264,9 @@ TEST_F(PeerConnectionSVCIntegrationTest, FallbackToL1Tx) {
EXPECT_TRUE(result.ok());
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_THAT(
WaitUntil([&] { return SignalingStateStable(); }, ::testing::IsTrue()),
IsRtcOk());
parameters = caller_transceiver->sender()->GetParameters();
ASSERT_TRUE(parameters.encodings[0].scalability_mode.has_value());
@ -271,7 +286,9 @@ TEST_F(PeerConnectionSVCIntegrationTest, FallbackToL1Tx) {
// Renegotiate to force the new codec list to be used
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_THAT(
WaitUntil([&] { return SignalingStateStable(); }, ::testing::IsTrue()),
IsRtcOk());
// Fallback should happen and L3T3 is not used anymore
parameters = caller_transceiver->sender()->GetParameters();

View File

@ -12,27 +12,39 @@
#include <stdint.h>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "api/data_channel_interface.h"
#include "api/function_view.h"
#include "api/set_remote_description_observer_interface.h"
#include "api/jsep.h"
#include "api/make_ref_counted.h"
#include "api/media_stream_interface.h"
#include "api/media_types.h"
#include "api/peer_connection_interface.h"
#include "api/rtc_error.h"
#include "api/rtp_parameters.h"
#include "api/rtp_sender_interface.h"
#include "api/rtp_transceiver_interface.h"
#include "api/scoped_refptr.h"
#include "api/stats/rtc_stats_report.h"
#include "api/test/rtc_error_matchers.h"
#include "pc/sdp_utils.h"
#include "pc/test/fake_video_track_source.h"
#include "pc/test/mock_peer_connection_observers.h"
#include "rtc_base/checks.h"
#include "rtc_base/gunit.h"
#include "rtc_base/logging.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/wait_until.h"
namespace webrtc {
using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
namespace {
const uint32_t kDefaultTimeout = 10000U;
}
PeerConnectionWrapper::PeerConnectionWrapper(
rtc::scoped_refptr<PeerConnectionFactoryInterface> pc_factory,
rtc::scoped_refptr<PeerConnectionInterface> pc,
@ -136,7 +148,9 @@ std::unique_ptr<SessionDescriptionInterface> PeerConnectionWrapper::CreateSdp(
std::string* error_out) {
auto observer = rtc::make_ref_counted<MockCreateSessionDescriptionObserver>();
fn(observer.get());
EXPECT_EQ_WAIT(true, observer->called(), kDefaultTimeout);
EXPECT_THAT(
WaitUntil([&] { return observer->called(); }, ::testing::IsTrue()),
IsRtcOk());
if (error_out && !observer->result()) {
*error_out = observer->error();
}
@ -168,7 +182,9 @@ bool PeerConnectionWrapper::SetRemoteDescription(
RTCError* error_out) {
auto observer = rtc::make_ref_counted<FakeSetRemoteDescriptionObserver>();
pc()->SetRemoteDescription(std::move(desc), observer);
EXPECT_EQ_WAIT(true, observer->called(), kDefaultTimeout);
EXPECT_THAT(
WaitUntil([&] { return observer->called(); }, ::testing::IsTrue()),
IsRtcOk());
bool ok = observer->error().ok();
if (error_out)
*error_out = std::move(observer->error());
@ -180,7 +196,9 @@ bool PeerConnectionWrapper::SetSdp(
std::string* error_out) {
auto observer = rtc::make_ref_counted<MockSetSessionDescriptionObserver>();
fn(observer.get());
EXPECT_EQ_WAIT(true, observer->called(), kDefaultTimeout);
EXPECT_THAT(
WaitUntil([&] { return observer->called(); }, ::testing::IsTrue()),
IsRtcOk());
if (error_out && !observer->result()) {
*error_out = observer->error();
}
@ -342,7 +360,9 @@ bool PeerConnectionWrapper::IsIceConnected() {
rtc::scoped_refptr<const RTCStatsReport> PeerConnectionWrapper::GetStats() {
auto callback = rtc::make_ref_counted<MockRTCStatsCollectorCallback>();
pc()->GetStats(callback.get());
EXPECT_TRUE_WAIT(callback->called(), kDefaultTimeout);
EXPECT_THAT(
WaitUntil([&] { return callback->called(); }, ::testing::IsTrue()),
IsRtcOk());
return callback->report();
}

View File

@ -42,6 +42,7 @@
#include "api/stats/rtc_stats_collector_callback.h"
#include "api/stats/rtc_stats_report.h"
#include "api/stats/rtcstats_objects.h"
#include "api/test/rtc_error_matchers.h"
#include "api/transport/enums.h"
#include "api/units/time_delta.h"
#include "api/units/timestamp.h"
@ -77,7 +78,6 @@
#include "rtc_base/checks.h"
#include "rtc_base/fake_clock.h"
#include "rtc_base/fake_ssl_identity.h"
#include "rtc_base/gunit.h"
#include "rtc_base/network_constants.h"
#include "rtc_base/ref_counted_object.h"
#include "rtc_base/rtc_certificate.h"
@ -92,6 +92,7 @@
#include "rtc_base/time_utils.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/wait_until.h"
using ::testing::_;
using ::testing::Invoke;
@ -604,7 +605,11 @@ class RTCStatsCollectorWrapper {
private:
rtc::scoped_refptr<const RTCStatsReport> WaitForReport(
rtc::scoped_refptr<RTCStatsObtainer> callback) {
EXPECT_TRUE_WAIT(callback->report() != nullptr, kGetStatsReportTimeoutMs);
EXPECT_THAT(
WaitUntil(
[&] { return callback->report() != nullptr; }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kGetStatsReportTimeoutMs)}),
IsRtcOk());
int64_t after = rtc::TimeUTCMicros();
for (const RTCStats& stats : *callback->report()) {
if (stats.type() == RTCRemoteInboundRtpStreamStats::kType ||
@ -883,7 +888,11 @@ class RTCStatsCollectorTest : public ::testing::Test {
TEST_F(RTCStatsCollectorTest, SingleCallback) {
rtc::scoped_refptr<const RTCStatsReport> result;
stats_->stats_collector()->GetStatsReport(RTCStatsObtainer::Create(&result));
EXPECT_TRUE_WAIT(result != nullptr, kGetStatsReportTimeoutMs);
EXPECT_THAT(
WaitUntil(
[&] { return result != nullptr; }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kGetStatsReportTimeoutMs)}),
IsRtcOk());
}
TEST_F(RTCStatsCollectorTest, MultipleCallbacks) {
@ -891,9 +900,21 @@ TEST_F(RTCStatsCollectorTest, MultipleCallbacks) {
stats_->stats_collector()->GetStatsReport(RTCStatsObtainer::Create(&a));
stats_->stats_collector()->GetStatsReport(RTCStatsObtainer::Create(&b));
stats_->stats_collector()->GetStatsReport(RTCStatsObtainer::Create(&c));
EXPECT_TRUE_WAIT(a != nullptr, kGetStatsReportTimeoutMs);
EXPECT_TRUE_WAIT(b != nullptr, kGetStatsReportTimeoutMs);
EXPECT_TRUE_WAIT(c != nullptr, kGetStatsReportTimeoutMs);
EXPECT_THAT(
WaitUntil(
[&] { return a != nullptr; }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kGetStatsReportTimeoutMs)}),
IsRtcOk());
EXPECT_THAT(
WaitUntil(
[&] { return b != nullptr; }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kGetStatsReportTimeoutMs)}),
IsRtcOk());
EXPECT_THAT(
WaitUntil(
[&] { return c != nullptr; }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kGetStatsReportTimeoutMs)}),
IsRtcOk());
EXPECT_EQ(a.get(), b.get());
EXPECT_EQ(b.get(), c.get());
@ -922,9 +943,21 @@ TEST_F(RTCStatsCollectorTest, MultipleCallbacksWithInvalidatedCacheInBetween) {
// Cache is invalidated after 50 ms.
fake_clock_.AdvanceTime(TimeDelta::Millis(51));
stats_->stats_collector()->GetStatsReport(RTCStatsObtainer::Create(&c));
EXPECT_TRUE_WAIT(a != nullptr, kGetStatsReportTimeoutMs);
EXPECT_TRUE_WAIT(b != nullptr, kGetStatsReportTimeoutMs);
EXPECT_TRUE_WAIT(c != nullptr, kGetStatsReportTimeoutMs);
EXPECT_THAT(
WaitUntil(
[&] { return a != nullptr; }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kGetStatsReportTimeoutMs)}),
IsRtcOk());
EXPECT_THAT(
WaitUntil(
[&] { return b != nullptr; }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kGetStatsReportTimeoutMs)}),
IsRtcOk());
EXPECT_THAT(
WaitUntil(
[&] { return c != nullptr; }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kGetStatsReportTimeoutMs)}),
IsRtcOk());
EXPECT_EQ(a.get(), b.get());
// The act of doing `AdvanceTime` processes all messages. If this was not the
// case we might not require `c` to be fresher than `b`.
@ -3702,8 +3735,16 @@ TEST_F(RTCStatsCollectorTest, DoNotCrashWhenGetStatsCalledDuringCallback) {
auto callback2 = rtc::make_ref_counted<RecursiveCallback>(stats_.get());
stats_->stats_collector()->GetStatsReport(callback1);
stats_->stats_collector()->GetStatsReport(callback2);
EXPECT_TRUE_WAIT(callback1->called(), kGetStatsReportTimeoutMs);
EXPECT_TRUE_WAIT(callback2->called(), kGetStatsReportTimeoutMs);
EXPECT_THAT(
WaitUntil(
[&] { return callback1->called(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kGetStatsReportTimeoutMs)}),
IsRtcOk());
EXPECT_THAT(
WaitUntil(
[&] { return callback2->called(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kGetStatsReportTimeoutMs)}),
IsRtcOk());
}
class RTCTestStats : public RTCStats {
@ -3755,7 +3796,11 @@ class FakeRTCStatsCollector : public RTCStatsCollector,
void VerifyThreadUsageAndResultsMerging() {
GetStatsReport(rtc::scoped_refptr<RTCStatsCollectorCallback>(this));
EXPECT_TRUE_WAIT(HasVerifiedResults(), kGetStatsReportTimeoutMs);
EXPECT_THAT(
WaitUntil(
[&] { return HasVerifiedResults(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kGetStatsReportTimeoutMs)}),
IsRtcOk());
}
bool HasVerifiedResults() {

View File

@ -9,7 +9,6 @@
*/
#include <stdint.h>
#include <string.h>
#include <memory>
#include <optional>
@ -23,24 +22,27 @@
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
#include "api/audio_options.h"
#include "api/data_channel_interface.h"
#include "api/make_ref_counted.h"
#include "api/peer_connection_interface.h"
#include "api/rtp_receiver_interface.h"
#include "api/rtp_sender_interface.h"
#include "api/scoped_refptr.h"
#include "api/stats/attribute.h"
#include "api/stats/rtc_stats.h"
#include "api/stats/rtc_stats_report.h"
#include "api/stats/rtcstats_objects.h"
#include "api/test/rtc_error_matchers.h"
#include "api/units/time_delta.h"
#include "pc/rtc_stats_traversal.h"
#include "pc/test/peer_connection_test_wrapper.h"
#include "pc/test/rtc_stats_obtainer.h"
#include "rtc_base/checks.h"
#include "rtc_base/event_tracer.h"
#include "rtc_base/gunit.h"
#include "rtc_base/thread.h"
#include "rtc_base/trace_event.h"
#include "rtc_base/virtual_socket_server.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/wait_until.h"
using ::testing::Contains;
@ -124,7 +126,11 @@ class RTCStatsIntegrationTest : public ::testing::Test {
rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer =
RTCStatsObtainer::Create();
pc->GetStats(stats_obtainer.get());
EXPECT_TRUE_WAIT(stats_obtainer->report() != nullptr, kGetStatsTimeoutMs);
EXPECT_THAT(
WaitUntil([&] { return stats_obtainer->report() != nullptr; },
::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kGetStatsTimeoutMs)}),
IsRtcOk());
return stats_obtainer->report();
}
@ -135,7 +141,11 @@ class RTCStatsIntegrationTest : public ::testing::Test {
rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer =
RTCStatsObtainer::Create();
pc->GetStats(selector, stats_obtainer);
EXPECT_TRUE_WAIT(stats_obtainer->report() != nullptr, kGetStatsTimeoutMs);
EXPECT_THAT(
WaitUntil([&] { return stats_obtainer->report() != nullptr; },
::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kGetStatsTimeoutMs)}),
IsRtcOk());
return stats_obtainer->report();
}
@ -1024,7 +1034,11 @@ TEST_F(RTCStatsIntegrationTest, GetStatsFromCallee) {
inbound_stats.front()->round_trip_time.has_value() &&
inbound_stats.front()->round_trip_time_measurements.has_value();
};
EXPECT_TRUE_WAIT(GetStatsReportAndReturnTrueIfRttIsDefined(), kMaxWaitMs);
EXPECT_THAT(
WaitUntil([&] { return GetStatsReportAndReturnTrueIfRttIsDefined(); },
::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kMaxWaitMs)}),
IsRtcOk());
RTCStatsReportVerifier(report.get()).VerifyReport({});
}

View File

@ -25,16 +25,17 @@
#include "api/crypto/frame_decryptor_interface.h"
#include "api/crypto/frame_encryptor_interface.h"
#include "api/dtmf_sender_interface.h"
#include "api/environment/environment.h"
#include "api/environment/environment_factory.h"
#include "api/make_ref_counted.h"
#include "api/media_stream_interface.h"
#include "api/rtc_error.h"
#include "api/rtc_event_log/rtc_event_log.h"
#include "api/rtp_parameters.h"
#include "api/rtp_receiver_interface.h"
#include "api/scoped_refptr.h"
#include "api/test/fake_frame_decryptor.h"
#include "api/test/fake_frame_encryptor.h"
#include "api/test/rtc_error_matchers.h"
#include "api/video/builtin_video_bitrate_allocator_factory.h"
#include "api/video/video_bitrate_allocator_factory.h"
#include "api/video/video_codec_constants.h"
@ -61,19 +62,12 @@
#include "pc/video_rtp_receiver.h"
#include "pc/video_track.h"
#include "rtc_base/checks.h"
#include "rtc_base/gunit.h"
#include "rtc_base/thread.h"
#include "rtc_base/unique_id_generator.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/run_loop.h"
using ::testing::_;
using ::testing::ContainerEq;
using ::testing::Exactly;
using ::testing::InvokeWithoutArgs;
using ::testing::Return;
using RidList = std::vector<std::string>;
#include "test/wait_until.h"
namespace {
@ -86,7 +80,6 @@ static const uint32_t kAudioSsrc = 99;
static const uint32_t kAudioSsrc2 = 101;
static const uint32_t kVideoSsrcSimulcast = 102;
static const uint32_t kVideoSimulcastLayerCount = 2;
static const int kDefaultTimeout = 10000; // 10 seconds.
class MockSetStreamsObserver
: public webrtc::RtpSenderBase::SetStreamsObserver {
@ -98,6 +91,9 @@ class MockSetStreamsObserver
namespace webrtc {
using ::testing::ContainerEq;
using RidList = std::vector<std::string>;
class RtpSenderReceiverTest
: public ::testing::Test,
public ::testing::WithParamInterface<std::pair<RidList, RidList>> {
@ -431,7 +427,7 @@ class RtpSenderReceiverTest
// This test assumes that some layers have already been disabled.
void RunSetLastLayerAsInactiveTest(VideoRtpSender* sender) {
auto parameters = sender->GetParameters();
if (parameters.encodings.size() == 0) {
if (parameters.encodings.empty()) {
return;
}
@ -1784,8 +1780,11 @@ TEST_F(RtpSenderReceiverTest, InsertDtmf) {
dtmf_sender->InsertDtmf("012", expected_duration, 100);
// Verify
ASSERT_EQ_WAIT(3U, voice_media_send_channel()->dtmf_info_queue().size(),
kDefaultTimeout);
ASSERT_THAT(
WaitUntil(
[&] { return voice_media_send_channel()->dtmf_info_queue().size(); },
::testing::Eq(3U)),
IsRtcOk());
const uint32_t send_ssrc =
voice_media_send_channel()->send_streams()[0].first_ssrc();
EXPECT_TRUE(CompareDtmfInfo(voice_media_send_channel()->dtmf_info_queue()[0],

View File

@ -10,17 +10,26 @@
#include "pc/rtp_transport.h"
#include <utility>
#include <cerrno>
#include <cstdint>
#include <optional>
#include "api/test/rtc_error_matchers.h"
#include "api/units/time_delta.h"
#include "call/rtp_demuxer.h"
#include "p2p/base/fake_packet_transport.h"
#include "pc/test/rtp_transport_test_util.h"
#include "rtc_base/buffer.h"
#include "rtc_base/containers/flat_set.h"
#include "rtc_base/gunit.h"
#include "rtc_base/network/ecn_marking.h"
#include "rtc_base/network/sent_packet.h"
#include "rtc_base/network_route.h"
#include "rtc_base/third_party/sigslot/sigslot.h"
#include "test/explicit_key_value_config.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/run_loop.h"
#include "test/wait_until.h"
namespace webrtc {
@ -398,7 +407,10 @@ TEST(RtpTransportTest, RecursiveSetSendDoesNotCrash) {
EXPECT_TRUE(observer.ready_to_send());
EXPECT_EQ(observer.ready_to_send_signal_count(), 1);
// After the wait, the ready-to-send false is observed.
EXPECT_EQ_WAIT(observer.ready_to_send_signal_count(), 2, kShortTimeout);
EXPECT_THAT(WaitUntil([&] { return observer.ready_to_send_signal_count(); },
::testing::Eq(2),
{.timeout = webrtc::TimeDelta::Millis(kShortTimeout)}),
IsRtcOk());
EXPECT_FALSE(observer.ready_to_send());
}
@ -423,7 +435,10 @@ TEST(RtpTransportTest, RecursiveOnSentPacketDoesNotCrash) {
rtc::CopyOnWriteBuffer rtp_data(kRtpData, kRtpLen);
transport.SendRtpPacket(&rtp_data, options, flags);
EXPECT_EQ(observer.sent_packet_count(), 1);
EXPECT_EQ_WAIT(observer.sent_packet_count(), 2, kShortTimeout);
EXPECT_THAT(
WaitUntil([&] { return observer.sent_packet_count(); }, ::testing::Eq(2),
{.timeout = webrtc::TimeDelta::Millis(kShortTimeout)}),
IsRtcOk());
}
} // namespace webrtc

View File

@ -24,27 +24,26 @@
#include "api/rtc_error.h"
#include "api/scoped_refptr.h"
#include "api/sctp_transport_interface.h"
#include "api/test/rtc_error_matchers.h"
#include "api/transport/data_channel_transport_interface.h"
#include "media/sctp/sctp_transport_internal.h"
#include "p2p/base/p2p_constants.h"
#include "p2p/base/packet_transport_internal.h"
#include "p2p/dtls/dtls_transport_internal.h"
#include "p2p/dtls/fake_dtls_transport.h"
#include "pc/dtls_transport.h"
#include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/gunit.h"
#include "rtc_base/thread.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/wait_until.h"
namespace webrtc {
constexpr int kDefaultTimeout = 1000; // milliseconds
constexpr int kTestMaxSctpStreams = 1234;
using cricket::FakeDtlsTransport;
using ::testing::ElementsAre;
namespace webrtc {
namespace {
class FakeCricketSctpTransport : public cricket::SctpTransportInternal {
@ -105,7 +104,7 @@ class TestSctpTransportObserver : public SctpTransportObserverInterface {
}
SctpTransportState State() {
if (states_.size() > 0) {
if (!states_.empty()) {
return states_[states_.size() - 1];
} else {
return SctpTransportState::kNew;
@ -182,8 +181,9 @@ TEST_F(SctpTransportTest, EventsObservedWhenConnecting) {
CreateTransport();
transport()->RegisterObserver(observer());
CompleteSctpHandshake();
ASSERT_EQ_WAIT(SctpTransportState::kConnected, observer_.State(),
kDefaultTimeout);
ASSERT_THAT(WaitUntil([&] { return observer_.State(); },
::testing::Eq(SctpTransportState::kConnected)),
IsRtcOk());
EXPECT_THAT(observer_.States(), ElementsAre(SctpTransportState::kConnected));
}
@ -191,11 +191,13 @@ TEST_F(SctpTransportTest, CloseWhenClearing) {
CreateTransport();
transport()->RegisterObserver(observer());
CompleteSctpHandshake();
ASSERT_EQ_WAIT(SctpTransportState::kConnected, observer_.State(),
kDefaultTimeout);
ASSERT_THAT(WaitUntil([&] { return observer_.State(); },
::testing::Eq(SctpTransportState::kConnected)),
IsRtcOk());
transport()->Clear();
ASSERT_EQ_WAIT(SctpTransportState::kClosed, observer_.State(),
kDefaultTimeout);
ASSERT_THAT(WaitUntil([&] { return observer_.State(); },
::testing::Eq(SctpTransportState::kClosed)),
IsRtcOk());
}
TEST_F(SctpTransportTest, MaxChannelsSignalled) {
@ -204,8 +206,9 @@ TEST_F(SctpTransportTest, MaxChannelsSignalled) {
EXPECT_FALSE(transport()->Information().MaxChannels());
EXPECT_FALSE(observer_.LastReceivedInformation().MaxChannels());
CompleteSctpHandshake();
ASSERT_EQ_WAIT(SctpTransportState::kConnected, observer_.State(),
kDefaultTimeout);
ASSERT_THAT(WaitUntil([&] { return observer_.State(); },
::testing::Eq(SctpTransportState::kConnected)),
IsRtcOk());
EXPECT_TRUE(transport()->Information().MaxChannels());
EXPECT_EQ(kTestMaxSctpStreams, *(transport()->Information().MaxChannels()));
EXPECT_TRUE(observer_.LastReceivedInformation().MaxChannels());
@ -217,11 +220,13 @@ TEST_F(SctpTransportTest, CloseWhenTransportCloses) {
CreateTransport();
transport()->RegisterObserver(observer());
CompleteSctpHandshake();
ASSERT_EQ_WAIT(SctpTransportState::kConnected, observer_.State(),
kDefaultTimeout);
ASSERT_THAT(WaitUntil([&] { return observer_.State(); },
::testing::Eq(SctpTransportState::kConnected)),
IsRtcOk());
static_cast<cricket::FakeDtlsTransport*>(dtls_transport_->internal())
->SetDtlsState(DtlsTransportState::kClosed);
ASSERT_EQ_WAIT(SctpTransportState::kClosed, observer_.State(),
kDefaultTimeout);
ASSERT_THAT(WaitUntil([&] { return observer_.State(); },
::testing::Eq(SctpTransportState::kClosed)),
IsRtcOk());
}
} // namespace webrtc

View File

@ -14,8 +14,8 @@
#include <stdint.h>
#include <memory>
#include <optional>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
@ -25,6 +25,7 @@
#include "api/peer_connection_interface.h"
#include "api/rtp_receiver_interface.h"
#include "api/scoped_refptr.h"
#include "api/test/rtc_error_matchers.h"
#include "api/units/time_delta.h"
#include "p2p/base/port_allocator.h"
#include "p2p/base/port_interface.h"
@ -38,10 +39,10 @@
#include "rtc_base/gunit.h"
#include "rtc_base/logging.h"
#include "rtc_base/socket_address.h"
#include "rtc_base/ssl_certificate.h"
#include "rtc_base/test_certificate_verifier.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/wait_until.h"
namespace webrtc {
@ -104,23 +105,35 @@ TEST_P(PeerConnectionIntegrationTest,
callee()->AddAudioVideoTracks();
// Start offer/answer exchange and wait for it to complete.
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_THAT(
WaitUntil([&] { return SignalingStateStable(); }, ::testing::IsTrue()),
IsRtcOk());
// Should be one receiver each for audio/video.
EXPECT_EQ(2U, caller()->rtp_receiver_observers().size());
EXPECT_EQ(2U, callee()->rtp_receiver_observers().size());
// Wait for all "first packet received" callbacks to be fired.
EXPECT_TRUE_WAIT(
absl::c_all_of(caller()->rtp_receiver_observers(),
[](const std::unique_ptr<MockRtpReceiverObserver>& o) {
return o->first_packet_received();
}),
kMaxWaitForFramesMs);
EXPECT_TRUE_WAIT(
absl::c_all_of(callee()->rtp_receiver_observers(),
[](const std::unique_ptr<MockRtpReceiverObserver>& o) {
return o->first_packet_received();
}),
kMaxWaitForFramesMs);
EXPECT_THAT(WaitUntil(
[&] {
return absl::c_all_of(
caller()->rtp_receiver_observers(),
[](const std::unique_ptr<MockRtpReceiverObserver>& o) {
return o->first_packet_received();
});
},
::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kMaxWaitForFramesMs)}),
IsRtcOk());
EXPECT_THAT(WaitUntil(
[&] {
return absl::c_all_of(
callee()->rtp_receiver_observers(),
[](const std::unique_ptr<MockRtpReceiverObserver>& o) {
return o->first_packet_received();
});
},
::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kMaxWaitForFramesMs)}),
IsRtcOk());
// If new observers are set after the first packet was already received, the
// callback should still be invoked.
caller()->ResetRtpReceiverObservers();
@ -234,7 +247,9 @@ TEST_P(PeerConnectionIntegrationTest, GetCaptureStartNtpTimeWithOldStatsApi) {
// Do offer/answer, wait for the callee to receive some frames.
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_THAT(
WaitUntil([&] { return SignalingStateStable(); }, ::testing::IsTrue()),
IsRtcOk());
// Get the remote audio track created on the receiver, so they can be used as
// GetStats filters.
@ -244,9 +259,16 @@ TEST_P(PeerConnectionIntegrationTest, GetCaptureStartNtpTimeWithOldStatsApi) {
// Get the audio output level stats. Note that the level is not available
// until an RTCP packet has been received.
EXPECT_TRUE_WAIT(callee()->OldGetStatsForTrack(remote_audio_track.get())
->CaptureStartNtpTime() > 0,
2 * kMaxWaitForFramesMs);
EXPECT_THAT(
WaitUntil(
[&] {
return callee()
->OldGetStatsForTrack(remote_audio_track.get())
->CaptureStartNtpTime();
},
::testing::Gt(0),
{.timeout = webrtc::TimeDelta::Millis(2 * kMaxWaitForFramesMs)}),
IsRtcOk());
}
// Test that firewalling the ICE connection causes the clients to identify the
@ -357,12 +379,16 @@ TEST_P(PeerConnectionIntegrationIceStatesTestWithFakeClock, VerifyIceStates) {
// background.
caller()->CreateAndSetAndSignalOffer();
ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
caller()->ice_connection_state(), kDefaultTimeout,
FakeClock());
ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
caller()->standardized_ice_connection_state(),
kDefaultTimeout, FakeClock());
ASSERT_THAT(
WaitUntil([&] { return caller()->ice_connection_state(); },
::testing::Eq(PeerConnectionInterface::kIceConnectionCompleted),
{.clock = &FakeClock()}),
IsRtcOk());
ASSERT_THAT(
WaitUntil([&] { return caller()->standardized_ice_connection_state(); },
::testing::Eq(PeerConnectionInterface::kIceConnectionCompleted),
{.clock = &FakeClock()}),
IsRtcOk());
// Verify that the observer was notified of the intermediate transitions.
EXPECT_THAT(caller()->ice_connection_state_history(),
@ -387,22 +413,33 @@ TEST_P(PeerConnectionIntegrationIceStatesTestWithFakeClock, VerifyIceStates) {
firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address);
}
RTC_LOG(LS_INFO) << "Firewall rules applied";
ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
caller()->ice_connection_state(), kDefaultTimeout,
FakeClock());
ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
caller()->standardized_ice_connection_state(),
kDefaultTimeout, FakeClock());
ScopedFakeClock& fake_clock = FakeClock();
ASSERT_THAT(
WaitUntil(
[&] { return caller()->ice_connection_state(); },
::testing::Eq(PeerConnectionInterface::kIceConnectionDisconnected),
{.timeout = TimeDelta::Seconds(10), .clock = &fake_clock}),
IsRtcOk());
ASSERT_THAT(
WaitUntil(
[&] { return caller()->standardized_ice_connection_state(); },
::testing::Eq(PeerConnectionInterface::kIceConnectionDisconnected),
{.timeout = TimeDelta::Seconds(10), .clock = &fake_clock}),
IsRtcOk());
// Let ICE re-establish by removing the firewall rules.
firewall()->ClearRules();
RTC_LOG(LS_INFO) << "Firewall rules cleared";
ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
caller()->ice_connection_state(), kDefaultTimeout,
FakeClock());
ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
caller()->standardized_ice_connection_state(),
kDefaultTimeout, FakeClock());
ASSERT_THAT(
WaitUntil([&] { return caller()->ice_connection_state(); },
::testing::Eq(PeerConnectionInterface::kIceConnectionCompleted),
{.clock = &fake_clock}),
IsRtcOk());
ASSERT_THAT(
WaitUntil([&] { return caller()->standardized_ice_connection_state(); },
::testing::Eq(PeerConnectionInterface::kIceConnectionCompleted),
{.clock = &fake_clock}),
IsRtcOk());
// According to RFC7675, if there is no response within 30 seconds then the
// peer should consider the other side to have rejected the connection. This
@ -412,12 +449,18 @@ TEST_P(PeerConnectionIntegrationIceStatesTestWithFakeClock, VerifyIceStates) {
firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address);
}
RTC_LOG(LS_INFO) << "Firewall rules applied again";
ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionFailed,
caller()->ice_connection_state(), kConsentTimeout,
FakeClock());
ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionFailed,
caller()->standardized_ice_connection_state(),
kConsentTimeout, FakeClock());
ASSERT_THAT(
WaitUntil([&] { return caller()->ice_connection_state(); },
::testing::Eq(PeerConnectionInterface::kIceConnectionFailed),
{.timeout = webrtc::TimeDelta::Millis(kConsentTimeout),
.clock = &fake_clock}),
IsRtcOk());
ASSERT_THAT(
WaitUntil([&] { return caller()->standardized_ice_connection_state(); },
::testing::Eq(PeerConnectionInterface::kIceConnectionFailed),
{.timeout = webrtc::TimeDelta::Millis(kConsentTimeout),
.clock = &fake_clock}),
IsRtcOk());
}
#endif
@ -429,7 +472,9 @@ TEST_P(PeerConnectionIntegrationTest, CallTransferredForCallee) {
caller()->AddAudioVideoTracks();
callee()->AddAudioVideoTracks();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_THAT(
WaitUntil([&] { return SignalingStateStable(); }, ::testing::IsTrue()),
IsRtcOk());
// Keep the original peer around which will still send packets to the
// receiving client. These SRTP packets will be dropped.
@ -443,7 +488,9 @@ TEST_P(PeerConnectionIntegrationTest, CallTransferredForCallee) {
ConnectFakeSignaling();
caller()->AddAudioVideoTracks();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_THAT(
WaitUntil([&] { return SignalingStateStable(); }, ::testing::IsTrue()),
IsRtcOk());
// Wait for some additional frames to be transmitted end-to-end.
MediaExpectations media_expectations;
media_expectations.ExpectBidirectionalAudioAndVideo();
@ -458,7 +505,9 @@ TEST_P(PeerConnectionIntegrationTest, CallTransferredForCaller) {
caller()->AddAudioVideoTracks();
callee()->AddAudioVideoTracks();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_THAT(
WaitUntil([&] { return SignalingStateStable(); }, ::testing::IsTrue()),
IsRtcOk());
// Keep the original peer around which will still send packets to the
// receiving client. These SRTP packets will be dropped.
@ -473,7 +522,9 @@ TEST_P(PeerConnectionIntegrationTest, CallTransferredForCaller) {
callee()->AddAudioVideoTracks();
caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions());
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_THAT(
WaitUntil([&] { return SignalingStateStable(); }, ::testing::IsTrue()),
IsRtcOk());
// Wait for some additional frames to be transmitted end-to-end.
MediaExpectations media_expectations;
media_expectations.ExpectBidirectionalAudioAndVideo();

View File

@ -13,11 +13,17 @@
#include <string.h>
#include <algorithm>
#include <cstdint>
#include "api/audio/audio_device_defines.h"
#include "api/scoped_refptr.h"
#include "rtc_base/gunit.h"
#include "api/test/rtc_error_matchers.h"
#include "api/units/time_delta.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/wait_until.h"
class FakeAdmTest : public ::testing::Test, public webrtc::AudioTransport {
protected:
@ -151,7 +157,10 @@ TEST_F(FakeAdmTest, PlayoutTest) {
EXPECT_EQ(0, fake_audio_capture_module_->PlayoutDelay(&delay_ms));
EXPECT_EQ(0, delay_ms);
EXPECT_TRUE_WAIT(pull_iterations() > 0, kMsInSecond);
EXPECT_THAT(
webrtc::WaitUntil([&] { return pull_iterations(); }, ::testing::Gt(0),
{.timeout = webrtc::TimeDelta::Millis(kMsInSecond)}),
webrtc::IsRtcOk());
EXPECT_GE(0, push_iterations());
EXPECT_EQ(0, fake_audio_capture_module_->StopPlayout());
@ -174,7 +183,10 @@ TEST_F(FakeAdmTest, RecordTest) {
EXPECT_EQ(0, fake_audio_capture_module_->StartRecording());
EXPECT_TRUE(fake_audio_capture_module_->Recording());
EXPECT_TRUE_WAIT(push_iterations() > 0, kMsInSecond);
EXPECT_THAT(
webrtc::WaitUntil([&] { return push_iterations(); }, ::testing::Gt(0),
{.timeout = webrtc::TimeDelta::Millis(kMsInSecond)}),
webrtc::IsRtcOk());
EXPECT_GE(0, pull_iterations());
EXPECT_EQ(0, fake_audio_capture_module_->StopRecording());
@ -190,8 +202,14 @@ TEST_F(FakeAdmTest, DuplexTest) {
EXPECT_EQ(0, fake_audio_capture_module_->InitRecording());
EXPECT_EQ(0, fake_audio_capture_module_->StartRecording());
EXPECT_TRUE_WAIT(push_iterations() > 0, kMsInSecond);
EXPECT_TRUE_WAIT(pull_iterations() > 0, kMsInSecond);
EXPECT_THAT(
webrtc::WaitUntil([&] { return push_iterations(); }, ::testing::Gt(0),
{.timeout = webrtc::TimeDelta::Millis(kMsInSecond)}),
webrtc::IsRtcOk());
EXPECT_THAT(
webrtc::WaitUntil([&] { return pull_iterations(); }, ::testing::Gt(0),
{.timeout = webrtc::TimeDelta::Millis(kMsInSecond)}),
webrtc::IsRtcOk());
EXPECT_EQ(0, fake_audio_capture_module_->StopPlayout());
EXPECT_EQ(0, fake_audio_capture_module_->StopRecording());

View File

@ -47,6 +47,7 @@
#include "api/rtp_parameters.h"
#include "api/rtp_receiver_interface.h"
#include "api/rtp_sender_interface.h"
#include "api/rtp_transceiver_direction.h"
#include "api/rtp_transceiver_interface.h"
#include "api/scoped_refptr.h"
#include "api/sequence_checker.h"
@ -54,6 +55,7 @@
#include "api/stats/rtcstats_objects.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/units/time_delta.h"
#include "api/video/video_rotation.h"
#include "logging/rtc_event_log/fake_rtc_event_log_factory.h"
@ -81,7 +83,6 @@
#include "rtc_base/fake_mdns_responder.h"
#include "rtc_base/fake_network.h"
#include "rtc_base/firewall_socket_server.h"
#include "rtc_base/gunit.h"
#include "rtc_base/ip_address.h"
#include "rtc_base/logging.h"
#include "rtc_base/socket_address.h"
@ -95,6 +96,7 @@
#include "system_wrappers/include/metrics.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/wait_until.h"
namespace webrtc {
@ -444,7 +446,7 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver,
// Return the last observed data channel.
DataChannelInterface* data_channel() {
if (data_channels_.size() == 0) {
if (data_channels_.empty()) {
return nullptr;
}
return data_channels_.back().get();
@ -455,7 +457,7 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver,
}
MockDataChannelObserver* data_observer() const {
if (data_observers_.size() == 0) {
if (data_observers_.empty()) {
return nullptr;
}
return data_observers_.back().get();
@ -500,7 +502,9 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver,
EXPECT_TRUE(peer_connection_->GetStats(
observer.get(), nullptr,
PeerConnectionInterface::kStatsOutputLevelStandard));
EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout);
EXPECT_THAT(
WaitUntil([&] { return observer->called(); }, ::testing::IsTrue()),
IsRtcOk());
return observer;
}
@ -514,7 +518,9 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver,
rtc::scoped_refptr<const RTCStatsReport> NewGetStats() {
auto callback = rtc::make_ref_counted<MockRTCStatsCollectorCallback>();
peer_connection_->GetStats(callback.get());
EXPECT_TRUE_WAIT(callback->called(), kDefaultTimeout);
EXPECT_THAT(
WaitUntil([&] { return callback->called(); }, ::testing::IsTrue()),
IsRtcOk());
return callback->report();
}
@ -689,7 +695,9 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver,
RTC_LOG(LS_INFO) << debug_name_ << ": SetRemoteDescription SDP:" << desc;
pc()->SetRemoteDescription(std::move(desc), observer); // desc.release());
RemoveUnusedVideoRenderers();
EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout);
EXPECT_THAT(
WaitUntil([&] { return observer->called(); }, ::testing::IsTrue()),
IsRtcOk());
auto err = observer->error();
if (!err.ok()) {
RTC_LOG(LS_WARNING) << debug_name_
@ -849,7 +857,9 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver,
std::unique_ptr<SessionDescriptionInterface> WaitForDescriptionFromObserver(
MockCreateSessionDescriptionObserver* observer) {
EXPECT_EQ_WAIT(true, observer->called(), kDefaultTimeout);
EXPECT_THAT(
WaitUntil([&] { return observer->called(); }, ::testing::IsTrue()),
IsRtcOk());
if (!observer->result()) {
return nullptr;
}
@ -878,7 +888,9 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver,
// As mentioned above, we need to send the message immediately after
// SetLocalDescription.
SendSdpMessage(type, sdp);
EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout);
EXPECT_THAT(
WaitUntil([&] { return observer->called(); }, ::testing::IsTrue()),
IsRtcOk());
return true;
}
@ -980,7 +992,9 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver,
pc()->AddIceCandidate(absl::WrapUnique(CreateIceCandidate(
sdp_mid, sdp_mline_index, msg, nullptr)),
[&result](RTCError r) { result = r; });
EXPECT_TRUE_WAIT(result.has_value(), kDefaultTimeout);
EXPECT_THAT(
WaitUntil([&] { return result.has_value(); }, ::testing::IsTrue()),
IsRtcOk());
EXPECT_TRUE(result.value().ok());
}
@ -1744,15 +1758,21 @@ class PeerConnectionIntegrationBaseTest : public ::testing::Test {
}
// Wait for the expected frames.
EXPECT_TRUE_WAIT(caller()->audio_frames_received() >=
total_caller_audio_frames_expected &&
caller()->min_video_frames_received_per_track() >=
total_caller_video_frames_expected &&
callee()->audio_frames_received() >=
total_callee_audio_frames_expected &&
callee()->min_video_frames_received_per_track() >=
total_callee_video_frames_expected,
kMaxWaitForFramesMs);
EXPECT_THAT(
WaitUntil(
[&] {
return caller()->audio_frames_received() >=
total_caller_audio_frames_expected &&
caller()->min_video_frames_received_per_track() >=
total_caller_video_frames_expected &&
callee()->audio_frames_received() >=
total_callee_audio_frames_expected &&
callee()->min_video_frames_received_per_track() >=
total_callee_video_frames_expected;
},
::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kMaxWaitForFramesMs)}),
IsRtcOk());
bool expectations_correct =
caller()->audio_frames_received() >=
total_caller_audio_frames_expected &&
@ -1831,9 +1851,13 @@ class PeerConnectionIntegrationBaseTest : public ::testing::Test {
caller()->AddAudioVideoTracks();
callee()->AddAudioVideoTracks();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout);
EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(expected_cipher_suite),
caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout);
ASSERT_THAT(WaitUntil([&] { return DtlsConnected(); }, ::testing::IsTrue()),
IsRtcOk());
EXPECT_THAT(
WaitUntil(
[&] { return caller()->OldGetStats()->SrtpCipher(); },
::testing::Eq(rtc::SrtpCryptoSuiteToName(expected_cipher_suite))),
IsRtcOk());
}
void TestGcmNegotiationUsesCipherSuite(bool local_gcm_enabled,

View File

@ -20,19 +20,33 @@
#include "absl/strings/match.h"
#include "api/audio/audio_device.h"
#include "api/audio/audio_mixer.h"
#include "api/audio/audio_processing.h"
#include "api/audio_codecs/audio_decoder_factory.h"
#include "api/audio_codecs/audio_encoder_factory.h"
#include "api/audio_options.h"
#include "api/create_peerconnection_factory.h"
#include "api/data_channel_interface.h"
#include "api/environment/environment.h"
#include "api/field_trials_view.h"
#include "api/jsep.h"
#include "api/make_ref_counted.h"
#include "api/media_stream_interface.h"
#include "api/media_types.h"
#include "api/peer_connection_interface.h"
#include "api/rtc_error.h"
#include "api/rtp_parameters.h"
#include "api/rtp_receiver_interface.h"
#include "api/scoped_refptr.h"
#include "api/sequence_checker.h"
#include "api/video_codecs/video_decoder_factory.h"
#include "api/test/rtc_error_matchers.h"
#include "api/units/time_delta.h"
#include "api/video/resolution.h"
#include "api/video_codecs/sdp_video_format.h"
#include "api/video_codecs/video_decoder_factory_template.h"
#include "api/video_codecs/video_decoder_factory_template_dav1d_adapter.h"
#include "api/video_codecs/video_decoder_factory_template_libvpx_vp8_adapter.h"
#include "api/video_codecs/video_decoder_factory_template_libvpx_vp9_adapter.h"
#include "api/video_codecs/video_decoder_factory_template_open_h264_adapter.h"
#include "api/video_codecs/video_encoder.h"
#include "api/video_codecs/video_encoder_factory.h"
#include "api/video_codecs/video_encoder_factory_template.h"
#include "api/video_codecs/video_encoder_factory_template_libaom_av1_adapter.h"
@ -40,17 +54,23 @@
#include "api/video_codecs/video_encoder_factory_template_libvpx_vp9_adapter.h"
#include "api/video_codecs/video_encoder_factory_template_open_h264_adapter.h"
#include "media/engine/simulcast_encoder_adapter.h"
#include "p2p/base/basic_packet_socket_factory.h"
#include "p2p/base/fake_port_allocator.h"
#include "p2p/base/port_allocator.h"
#include "pc/test/fake_audio_capture_module.h"
#include "pc/test/fake_periodic_video_source.h"
#include "pc/test/fake_periodic_video_track_source.h"
#include "pc/test/fake_rtc_certificate_generator.h"
#include "pc/test/fake_video_track_renderer.h"
#include "pc/test/mock_peer_connection_observers.h"
#include "rtc_base/gunit.h"
#include "rtc_base/logging.h"
#include "rtc_base/rtc_certificate_generator.h"
#include "rtc_base/socket_server.h"
#include "rtc_base/string_encode.h"
#include "rtc_base/time_utils.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/wait_until.h"
namespace {
@ -226,7 +246,10 @@ PeerConnectionTestWrapper::FindFirstSendCodecWithName(
}
void PeerConnectionTestWrapper::WaitForNegotiation() {
EXPECT_TRUE_WAIT(!pending_negotiation_, kMaxWait);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return !pending_negotiation_; }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kMaxWait)}),
webrtc::IsRtcOk());
}
void PeerConnectionTestWrapper::OnSignalingChange(
@ -340,7 +363,10 @@ bool PeerConnectionTestWrapper::WaitForCallEstablished() {
}
bool PeerConnectionTestWrapper::WaitForConnection() {
EXPECT_TRUE_WAIT(CheckForConnection(), kMaxWait);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return CheckForConnection(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kMaxWait)}),
webrtc::IsRtcOk());
if (testing::Test::HasFailure()) {
return false;
}
@ -356,7 +382,10 @@ bool PeerConnectionTestWrapper::CheckForConnection() {
}
bool PeerConnectionTestWrapper::WaitForAudio() {
EXPECT_TRUE_WAIT(CheckForAudio(), kMaxWait);
EXPECT_THAT(
webrtc::WaitUntil([&] { return CheckForAudio(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kMaxWait)}),
webrtc::IsRtcOk());
if (testing::Test::HasFailure()) {
return false;
}
@ -371,7 +400,10 @@ bool PeerConnectionTestWrapper::CheckForAudio() {
}
bool PeerConnectionTestWrapper::WaitForVideo() {
EXPECT_TRUE_WAIT(CheckForVideo(), kMaxWait);
EXPECT_THAT(
webrtc::WaitUntil([&] { return CheckForVideo(); }, ::testing::IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kMaxWait)}),
webrtc::IsRtcOk());
if (testing::Test::HasFailure()) {
return false;
}