diff --git a/audio/BUILD.gn b/audio/BUILD.gn index f2bd1eabec..2523c32b93 100644 --- a/audio/BUILD.gn +++ b/audio/BUILD.gn @@ -177,9 +177,11 @@ if (rtc_include_tests) { "../api:mock_frame_encryptor", "../api:mock_frame_transformer", "../api:mock_transformable_audio_frame", + "../api:rtc_error_matchers", "../api:rtp_headers", "../api:rtp_parameters", "../api:scoped_refptr", + "../api:simulated_network_api", "../api:transport_api", "../api/audio:audio_frame_api", "../api/audio:audio_mixer_api", @@ -193,6 +195,7 @@ if (rtc_include_tests) { "../api/crypto:options", "../api/environment", "../api/environment:environment_factory", + "../api/task_queue", "../api/task_queue:default_task_queue_factory", "../api/task_queue/test:mock_task_queue_base", "../api/transport:bitrate_settings", @@ -240,8 +243,10 @@ if (rtc_include_tests) { "../test:test_common", "../test:test_support", "../test:video_test_constants", + "../test:wait_until", "../test/time_controller:time_controller", "utility:utility_tests", + "//testing/gmock", "//testing/gtest", "//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/strings:string_view", diff --git a/audio/channel_send_unittest.cc b/audio/channel_send_unittest.cc index b415b5fc34..d425597102 100644 --- a/audio/channel_send_unittest.cc +++ b/audio/channel_send_unittest.cc @@ -34,6 +34,7 @@ #include "api/scoped_refptr.h" #include "api/test/mock_frame_transformer.h" #include "api/test/mock_transformable_audio_frame.h" +#include "api/test/rtc_error_matchers.h" #include "api/transport/bitrate_settings.h" #include "api/units/data_rate.h" #include "api/units/time_delta.h" @@ -42,18 +43,20 @@ #include "call/rtp_transport_controller_send.h" #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" #include "modules/rtp_rtcp/source/rtp_packet_received.h" -#include "rtc_base/gunit.h" #include "test/gmock.h" #include "test/gtest.h" #include "test/mock_transport.h" #include "test/scoped_key_value_config.h" #include "test/time_controller/simulated_time_controller.h" +#include "test/wait_until.h" namespace webrtc { namespace voe { namespace { +using ::testing::Eq; using ::testing::Invoke; +using ::testing::IsTrue; using ::testing::NiceMock; using ::testing::Return; using ::testing::SaveArg; @@ -212,9 +215,11 @@ TEST_F(ChannelSendTest, FrameTransformerGetsCorrectTimestamp) { // Ensure the RTP timestamp on the frame passed to the transformer // includes the RTP offset and matches the actual RTP timestamp on the sent // packet. - EXPECT_EQ_WAIT(transformable_frame_timestamp, - 0 + channel_->GetRtpRtcp()->StartTimestamp(), 1000); - EXPECT_TRUE_WAIT(sent_timestamp, 1000); + EXPECT_THAT( + WaitUntil([&] { return 0 + channel_->GetRtpRtcp()->StartTimestamp(); }, + Eq(transformable_frame_timestamp)), + IsRtcOk()); + EXPECT_THAT(WaitUntil([&] { return sent_timestamp; }, IsTrue()), IsRtcOk()); EXPECT_EQ(*sent_timestamp, transformable_frame_timestamp); } @@ -264,7 +269,7 @@ TEST_F(ChannelSendTest, AudioLevelsAttachedToCorrectTransformedFrame) { ProcessNextFrame(CreateAudioFrame(/*data_init_value=*/3)); // Wait for both packets to be encoded and sent to the transform. - EXPECT_EQ_WAIT(frames.size(), 2ul, 1000); + EXPECT_THAT(WaitUntil([&] { return frames.size(); }, Eq(2ul)), IsRtcOk()); // Complete the transforms on both frames at the same time callback->OnTransformedFrame(std::move(frames[0])); callback->OnTransformedFrame(std::move(frames[1])); @@ -274,7 +279,8 @@ TEST_F(ChannelSendTest, AudioLevelsAttachedToCorrectTransformedFrame) { // Ensure the audio levels on both sent packets is present and // matches their contents. - EXPECT_EQ_WAIT(sent_audio_levels.size(), 2ul, 1000); + EXPECT_THAT(WaitUntil([&] { return sent_audio_levels.size(); }, Eq(2ul)), + IsRtcOk()); // rms dbov of the packet with raw audio of 7s is 73. EXPECT_EQ(sent_audio_levels[0], 73); // rms dbov of the second packet with raw audio of 3s is 81. @@ -318,14 +324,14 @@ TEST_F(ChannelSendTest, AudioLevelsAttachedToInsertedTransformedFrame) { uint8_t payload[10]; ON_CALL(*mock_frame, GetData()) .WillByDefault(Return(rtc::ArrayView(&payload[0], 10))); - EXPECT_TRUE_WAIT(callback, 1000); + EXPECT_THAT(WaitUntil([&] { return callback; }, IsTrue()), IsRtcOk()); callback->OnTransformedFrame(std::move(mock_frame)); // Allow things posted back to the encoder queue to run. time_controller_.AdvanceTime(TimeDelta::Millis(10)); // Ensure the audio levels is set on the sent packet. - EXPECT_TRUE_WAIT(sent_audio_level, 1000); + EXPECT_THAT(WaitUntil([&] { return sent_audio_level; }, IsTrue()), IsRtcOk()); EXPECT_EQ(*sent_audio_level, audio_level); } diff --git a/audio/test/non_sender_rtt_test.cc b/audio/test/non_sender_rtt_test.cc index 278193e335..17dd97ef09 100644 --- a/audio/test/non_sender_rtt_test.cc +++ b/audio/test/non_sender_rtt_test.cc @@ -8,15 +8,26 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include +#include + +#include "api/task_queue/task_queue_base.h" +#include "api/test/rtc_error_matchers.h" +#include "api/test/simulated_network.h" +#include "api/units/time_delta.h" #include "audio/test/audio_end_to_end_test.h" -#include "rtc_base/gunit.h" +#include "call/audio_receive_stream.h" +#include "call/audio_send_stream.h" #include "rtc_base/task_queue_for_test.h" -#include "system_wrappers/include/sleep.h" +#include "test/call_test.h" +#include "test/gmock.h" #include "test/gtest.h" +#include "test/wait_until.h" namespace webrtc { namespace test { +using ::testing::IsTrue; using NonSenderRttTest = CallTest; TEST_F(NonSenderRttTest, NonSenderRttStats) { @@ -47,7 +58,10 @@ TEST_F(NonSenderRttTest, NonSenderRttStats) { // Wait until we have an RTT measurement, but no longer than // `kLongTimeoutMs`. This usually takes around 5 seconds, but in rare // cases it can take more than 10 seconds. - EXPECT_TRUE_WAIT(HasRoundTripTimeMeasurement(), kLongTimeoutMs); + EXPECT_THAT( + WaitUntil([&] { return HasRoundTripTimeMeasurement(); }, IsTrue(), + {.timeout = webrtc::TimeDelta::Millis(kLongTimeoutMs)}), + IsRtcOk()); } void OnStreamsStopped() override {