Replace gunit macros with WaitUntil in test/network
Bug: webrtc:381524905 Change-Id: Ice2888b04ec9105ce4e439a163b35378ae773e61 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/372302 Auto-Submit: Evan Shrubsole <eshr@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Evan Shrubsole <eshr@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43666}
This commit is contained in:
parent
042552959e
commit
2bd81c62e1
@ -70,6 +70,7 @@ specific_include_rules = {
|
|||||||
"+p2p/base/port_allocator.h",
|
"+p2p/base/port_allocator.h",
|
||||||
],
|
],
|
||||||
".*network_emulation_pc_unittest\.cc": [
|
".*network_emulation_pc_unittest\.cc": [
|
||||||
|
"+p2p/base/port_allocator.h",
|
||||||
"+pc/peer_connection_wrapper.h",
|
"+pc/peer_connection_wrapper.h",
|
||||||
"+pc/test/mock_peer_connection_observers.h",
|
"+pc/test/mock_peer_connection_observers.h",
|
||||||
"+p2p/client/basic_port_allocator.h",
|
"+p2p/client/basic_port_allocator.h",
|
||||||
|
|||||||
@ -99,23 +99,32 @@ if (rtc_include_tests && !build_with_chromium) {
|
|||||||
sources = [ "network_emulation_pc_unittest.cc" ]
|
sources = [ "network_emulation_pc_unittest.cc" ]
|
||||||
deps = [
|
deps = [
|
||||||
":emulated_network",
|
":emulated_network",
|
||||||
|
"..:wait_until",
|
||||||
"../:test_support",
|
"../:test_support",
|
||||||
"../..//test/network:simulated_network",
|
"../..//test/network:simulated_network",
|
||||||
|
"../../api:audio_options_api",
|
||||||
"../../api:enable_media_with_defaults",
|
"../../api:enable_media_with_defaults",
|
||||||
"../../api:libjingle_peerconnection_api",
|
"../../api:libjingle_peerconnection_api",
|
||||||
|
"../../api:media_stream_interface",
|
||||||
|
"../../api:network_emulation_manager_api",
|
||||||
|
"../../api:packet_socket_factory",
|
||||||
|
"../../api:rtc_error_matchers",
|
||||||
"../../api:scoped_refptr",
|
"../../api:scoped_refptr",
|
||||||
"../../api:simulated_network_api",
|
"../../api:simulated_network_api",
|
||||||
"../../api/rtc_event_log:rtc_event_log_factory",
|
"../../api/rtc_event_log:rtc_event_log_factory",
|
||||||
"../../api/task_queue:default_task_queue_factory",
|
"../../api/task_queue:default_task_queue_factory",
|
||||||
|
"../../api/test/network_emulation",
|
||||||
"../../api/transport:field_trial_based_config",
|
"../../api/transport:field_trial_based_config",
|
||||||
"../../media:rtc_audio_video",
|
"../../media:rtc_audio_video",
|
||||||
"../../modules/audio_device:test_audio_device_module",
|
"../../modules/audio_device:test_audio_device_module",
|
||||||
"../../p2p:basic_packet_socket_factory",
|
"../../p2p:basic_packet_socket_factory",
|
||||||
"../../p2p:basic_port_allocator",
|
"../../p2p:basic_port_allocator",
|
||||||
|
"../../p2p:port_allocator",
|
||||||
"../../pc:pc_test_utils",
|
"../../pc:pc_test_utils",
|
||||||
"../../pc:peerconnection_wrapper",
|
"../../pc:peerconnection_wrapper",
|
||||||
"../../rtc_base:gunit_helpers",
|
"../../rtc_base:gunit_helpers",
|
||||||
"../../rtc_base:logging",
|
"../../rtc_base:logging",
|
||||||
|
"../../rtc_base:network",
|
||||||
"../../rtc_base:rtc_event",
|
"../../rtc_base:rtc_event",
|
||||||
"../../rtc_base:task_queue_for_test",
|
"../../rtc_base:task_queue_for_test",
|
||||||
]
|
]
|
||||||
@ -146,21 +155,37 @@ if (rtc_include_tests) {
|
|||||||
sources = [ "network_emulation_unittest.cc" ]
|
sources = [ "network_emulation_unittest.cc" ]
|
||||||
deps = [
|
deps = [
|
||||||
":emulated_network",
|
":emulated_network",
|
||||||
|
"..:wait_until",
|
||||||
"../:test_support",
|
"../:test_support",
|
||||||
"../..//test/network:simulated_network",
|
"../..//test/network:simulated_network",
|
||||||
"../../api:create_time_controller",
|
"../../api:create_time_controller",
|
||||||
|
"../../api:network_emulation_manager_api",
|
||||||
|
"../../api:rtc_error_matchers",
|
||||||
"../../api:simulated_network_api",
|
"../../api:simulated_network_api",
|
||||||
"../../api/task_queue:task_queue",
|
"../../api/task_queue:task_queue",
|
||||||
|
"../../api/test/network_emulation",
|
||||||
"../../api/transport:ecn_marking",
|
"../../api/transport:ecn_marking",
|
||||||
|
"../../api/transport:stun_types",
|
||||||
|
"../../api/units:data_size",
|
||||||
"../../api/units:time_delta",
|
"../../api/units:time_delta",
|
||||||
"../../api/units:timestamp",
|
"../../api/units:timestamp",
|
||||||
"../../rtc_base:buffer",
|
"../../rtc_base:buffer",
|
||||||
|
"../../rtc_base:byte_buffer",
|
||||||
|
"../../rtc_base:checks",
|
||||||
|
"../../rtc_base:copy_on_write_buffer",
|
||||||
"../../rtc_base:gunit_helpers",
|
"../../rtc_base:gunit_helpers",
|
||||||
|
"../../rtc_base:ip_address",
|
||||||
"../../rtc_base:logging",
|
"../../rtc_base:logging",
|
||||||
|
"../../rtc_base:macromagic",
|
||||||
|
"../../rtc_base:net_helpers",
|
||||||
"../../rtc_base:rtc_event",
|
"../../rtc_base:rtc_event",
|
||||||
"../../rtc_base:socket",
|
"../../rtc_base:socket",
|
||||||
|
"../../rtc_base:socket_address",
|
||||||
"../../rtc_base:task_queue_for_test",
|
"../../rtc_base:task_queue_for_test",
|
||||||
|
"../../rtc_base:threading",
|
||||||
"../../rtc_base/synchronization:mutex",
|
"../../rtc_base/synchronization:mutex",
|
||||||
|
"../../rtc_base/third_party/sigslot",
|
||||||
|
"//third_party/abseil-cpp/absl/functional:any_invocable",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,34 +8,45 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "api/audio_options.h"
|
||||||
#include "api/enable_media_with_defaults.h"
|
#include "api/enable_media_with_defaults.h"
|
||||||
|
#include "api/jsep.h"
|
||||||
|
#include "api/media_stream_interface.h"
|
||||||
|
#include "api/packet_socket_factory.h"
|
||||||
#include "api/peer_connection_interface.h"
|
#include "api/peer_connection_interface.h"
|
||||||
#include "api/rtc_event_log/rtc_event_log_factory.h"
|
#include "api/rtc_event_log/rtc_event_log_factory.h"
|
||||||
#include "api/scoped_refptr.h"
|
#include "api/scoped_refptr.h"
|
||||||
#include "api/task_queue/default_task_queue_factory.h"
|
#include "api/task_queue/default_task_queue_factory.h"
|
||||||
|
#include "api/test/network_emulation/network_emulation_interfaces.h"
|
||||||
|
#include "api/test/network_emulation_manager.h"
|
||||||
|
#include "api/test/rtc_error_matchers.h"
|
||||||
|
#include "api/test/simulated_network.h"
|
||||||
#include "api/transport/field_trial_based_config.h"
|
#include "api/transport/field_trial_based_config.h"
|
||||||
#include "media/engine/webrtc_media_engine.h"
|
|
||||||
#include "modules/audio_device/include/test_audio_device.h"
|
#include "modules/audio_device/include/test_audio_device.h"
|
||||||
#include "p2p/base/basic_packet_socket_factory.h"
|
#include "p2p/base/port_allocator.h"
|
||||||
#include "p2p/client/basic_port_allocator.h"
|
#include "p2p/client/basic_port_allocator.h"
|
||||||
#include "pc/peer_connection_wrapper.h"
|
#include "pc/peer_connection_wrapper.h"
|
||||||
#include "pc/test/mock_peer_connection_observers.h"
|
#include "pc/test/mock_peer_connection_observers.h"
|
||||||
#include "rtc_base/gunit.h"
|
#include "rtc_base/network.h"
|
||||||
#include "rtc_base/task_queue_for_test.h"
|
#include "rtc_base/task_queue_for_test.h"
|
||||||
#include "test/gmock.h"
|
#include "test/gmock.h"
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
#include "test/network/network_emulation.h"
|
#include "test/network/network_emulation.h"
|
||||||
#include "test/network/network_emulation_manager.h"
|
#include "test/network/network_emulation_manager.h"
|
||||||
#include "test/network/simulated_network.h"
|
#include "test/network/simulated_network.h"
|
||||||
|
#include "test/wait_until.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace test {
|
namespace test {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr int kDefaultTimeoutMs = 1000;
|
using ::testing::Eq;
|
||||||
|
using ::testing::IsTrue;
|
||||||
|
|
||||||
constexpr int kMaxAptitude = 32000;
|
constexpr int kMaxAptitude = 32000;
|
||||||
constexpr int kSamplingFrequency = 48000;
|
constexpr int kSamplingFrequency = 48000;
|
||||||
constexpr char kSignalThreadName[] = "signaling_thread";
|
constexpr char kSignalThreadName[] = "signaling_thread";
|
||||||
@ -171,11 +182,14 @@ TEST(NetworkEmulationManagerPCTest, Run) {
|
|||||||
// Connect peers.
|
// Connect peers.
|
||||||
ASSERT_TRUE(alice->ExchangeOfferAnswerWith(bob.get()));
|
ASSERT_TRUE(alice->ExchangeOfferAnswerWith(bob.get()));
|
||||||
// Do the SDP negotiation, and also exchange ice candidates.
|
// Do the SDP negotiation, and also exchange ice candidates.
|
||||||
ASSERT_TRUE_WAIT(
|
ASSERT_THAT(WaitUntil([&] { return alice->signaling_state(); },
|
||||||
alice->signaling_state() == PeerConnectionInterface::kStable,
|
Eq(PeerConnectionInterface::kStable)),
|
||||||
kDefaultTimeoutMs);
|
IsRtcOk());
|
||||||
ASSERT_TRUE_WAIT(alice->IsIceGatheringDone(), kDefaultTimeoutMs);
|
ASSERT_THAT(
|
||||||
ASSERT_TRUE_WAIT(bob->IsIceGatheringDone(), kDefaultTimeoutMs);
|
WaitUntil([&] { return alice->IsIceGatheringDone(); }, IsTrue()),
|
||||||
|
IsRtcOk());
|
||||||
|
ASSERT_THAT(WaitUntil([&] { return bob->IsIceGatheringDone(); }, IsTrue()),
|
||||||
|
IsRtcOk());
|
||||||
|
|
||||||
// Connect an ICE candidate pairs.
|
// Connect an ICE candidate pairs.
|
||||||
ASSERT_TRUE(
|
ASSERT_TRUE(
|
||||||
@ -183,8 +197,10 @@ TEST(NetworkEmulationManagerPCTest, Run) {
|
|||||||
ASSERT_TRUE(
|
ASSERT_TRUE(
|
||||||
AddIceCandidates(alice.get(), bob->observer()->GetAllCandidates()));
|
AddIceCandidates(alice.get(), bob->observer()->GetAllCandidates()));
|
||||||
// This means that ICE and DTLS are connected.
|
// This means that ICE and DTLS are connected.
|
||||||
ASSERT_TRUE_WAIT(bob->IsIceConnected(), kDefaultTimeoutMs);
|
ASSERT_THAT(WaitUntil([&] { return bob->IsIceConnected(); }, IsTrue()),
|
||||||
ASSERT_TRUE_WAIT(alice->IsIceConnected(), kDefaultTimeoutMs);
|
IsRtcOk());
|
||||||
|
ASSERT_THAT(WaitUntil([&] { return alice->IsIceConnected(); }, IsTrue()),
|
||||||
|
IsRtcOk());
|
||||||
|
|
||||||
// Close peer connections
|
// Close peer connections
|
||||||
alice->pc()->Close();
|
alice->pc()->Close();
|
||||||
@ -281,11 +297,14 @@ TEST(NetworkEmulationManagerPCTest, RunTURN) {
|
|||||||
// Connect peers.
|
// Connect peers.
|
||||||
ASSERT_TRUE(alice->ExchangeOfferAnswerWith(bob.get()));
|
ASSERT_TRUE(alice->ExchangeOfferAnswerWith(bob.get()));
|
||||||
// Do the SDP negotiation, and also exchange ice candidates.
|
// Do the SDP negotiation, and also exchange ice candidates.
|
||||||
ASSERT_TRUE_WAIT(
|
ASSERT_THAT(WaitUntil([&] { return alice->signaling_state(); },
|
||||||
alice->signaling_state() == PeerConnectionInterface::kStable,
|
Eq(PeerConnectionInterface::kStable)),
|
||||||
kDefaultTimeoutMs);
|
IsRtcOk());
|
||||||
ASSERT_TRUE_WAIT(alice->IsIceGatheringDone(), kDefaultTimeoutMs);
|
ASSERT_THAT(
|
||||||
ASSERT_TRUE_WAIT(bob->IsIceGatheringDone(), kDefaultTimeoutMs);
|
WaitUntil([&] { return alice->IsIceGatheringDone(); }, IsTrue()),
|
||||||
|
IsRtcOk());
|
||||||
|
ASSERT_THAT(WaitUntil([&] { return bob->IsIceGatheringDone(); }, IsTrue()),
|
||||||
|
IsRtcOk());
|
||||||
|
|
||||||
// Connect an ICE candidate pairs.
|
// Connect an ICE candidate pairs.
|
||||||
ASSERT_TRUE(
|
ASSERT_TRUE(
|
||||||
@ -293,8 +312,10 @@ TEST(NetworkEmulationManagerPCTest, RunTURN) {
|
|||||||
ASSERT_TRUE(
|
ASSERT_TRUE(
|
||||||
AddIceCandidates(alice.get(), bob->observer()->GetAllCandidates()));
|
AddIceCandidates(alice.get(), bob->observer()->GetAllCandidates()));
|
||||||
// This means that ICE and DTLS are connected.
|
// This means that ICE and DTLS are connected.
|
||||||
ASSERT_TRUE_WAIT(bob->IsIceConnected(), kDefaultTimeoutMs);
|
ASSERT_THAT(WaitUntil([&] { return bob->IsIceConnected(); }, IsTrue()),
|
||||||
ASSERT_TRUE_WAIT(alice->IsIceConnected(), kDefaultTimeoutMs);
|
IsRtcOk());
|
||||||
|
ASSERT_THAT(WaitUntil([&] { return alice->IsIceConnected(); }, IsTrue()),
|
||||||
|
IsRtcOk());
|
||||||
|
|
||||||
// Close peer connections
|
// Close peer connections
|
||||||
alice->pc()->Close();
|
alice->pc()->Close();
|
||||||
|
|||||||
@ -11,32 +11,52 @@
|
|||||||
#include "test/network/network_emulation.h"
|
#include "test/network/network_emulation.h"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/functional/any_invocable.h"
|
||||||
#include "api/task_queue/task_queue_base.h"
|
#include "api/task_queue/task_queue_base.h"
|
||||||
#include "api/test/create_time_controller.h"
|
#include "api/test/network_emulation/network_emulation_interfaces.h"
|
||||||
|
#include "api/test/network_emulation_manager.h"
|
||||||
|
#include "api/test/rtc_error_matchers.h"
|
||||||
#include "api/test/simulated_network.h"
|
#include "api/test/simulated_network.h"
|
||||||
#include "api/transport/ecn_marking.h"
|
#include "api/transport/ecn_marking.h"
|
||||||
|
#include "api/transport/stun.h"
|
||||||
|
#include "api/units/data_size.h"
|
||||||
#include "api/units/time_delta.h"
|
#include "api/units/time_delta.h"
|
||||||
#include "api/units/timestamp.h"
|
#include "api/units/timestamp.h"
|
||||||
#include "rtc_base/buffer.h"
|
#include "rtc_base/buffer.h"
|
||||||
#include "rtc_base/gunit.h"
|
#include "rtc_base/byte_buffer.h"
|
||||||
|
#include "rtc_base/checks.h"
|
||||||
|
#include "rtc_base/copy_on_write_buffer.h"
|
||||||
|
#include "rtc_base/ip_address.h"
|
||||||
|
#include "rtc_base/net_helpers.h"
|
||||||
#include "rtc_base/socket.h"
|
#include "rtc_base/socket.h"
|
||||||
|
#include "rtc_base/socket_address.h"
|
||||||
#include "rtc_base/synchronization/mutex.h"
|
#include "rtc_base/synchronization/mutex.h"
|
||||||
#include "rtc_base/task_queue_for_test.h"
|
#include "rtc_base/task_queue_for_test.h"
|
||||||
|
#include "rtc_base/third_party/sigslot/sigslot.h"
|
||||||
|
#include "rtc_base/thread.h"
|
||||||
|
#include "rtc_base/thread_annotations.h"
|
||||||
#include "test/gmock.h"
|
#include "test/gmock.h"
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
#include "test/network/network_emulation_manager.h"
|
#include "test/network/network_emulation_manager.h"
|
||||||
#include "test/network/simulated_network.h"
|
#include "test/network/simulated_network.h"
|
||||||
|
#include "test/wait_until.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace test {
|
namespace test {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using ::testing::ElementsAreArray;
|
using ::testing::ElementsAreArray;
|
||||||
|
using ::testing::Eq;
|
||||||
|
|
||||||
constexpr TimeDelta kNetworkPacketWaitTimeout = TimeDelta::Millis(100);
|
constexpr TimeDelta kNetworkPacketWaitTimeout = TimeDelta::Millis(100);
|
||||||
constexpr TimeDelta kStatsWaitTimeout = TimeDelta::Seconds(1);
|
constexpr TimeDelta kStatsWaitTimeout = TimeDelta::Seconds(1);
|
||||||
@ -359,9 +379,10 @@ TEST(NetworkEmulationManagerTest, Run) {
|
|||||||
|
|
||||||
received_stats_count++;
|
received_stats_count++;
|
||||||
});
|
});
|
||||||
ASSERT_EQ_SIMULATED_WAIT(received_stats_count.load(), 2,
|
ASSERT_THAT(WaitUntil([&] { return received_stats_count.load(); }, Eq(2),
|
||||||
kStatsWaitTimeout.ms(),
|
{.timeout = kStatsWaitTimeout,
|
||||||
*network_manager.time_controller());
|
.clock = network_manager.time_controller()}),
|
||||||
|
IsRtcOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(NetworkEmulationManagerTest, EcnMarkingIsPropagated) {
|
TEST(NetworkEmulationManagerTest, EcnMarkingIsPropagated) {
|
||||||
@ -440,9 +461,10 @@ TEST(NetworkEmulationManagerTest, EcnMarkingIsPropagated) {
|
|||||||
EXPECT_EQ(st.overall_incoming_stats.ecn_count.not_ect(), 0);
|
EXPECT_EQ(st.overall_incoming_stats.ecn_count.not_ect(), 0);
|
||||||
++received_stats_count;
|
++received_stats_count;
|
||||||
});
|
});
|
||||||
ASSERT_EQ_SIMULATED_WAIT(received_stats_count.load(), 2,
|
ASSERT_THAT(WaitUntil([&] { return received_stats_count.load(); }, Eq(2),
|
||||||
kStatsWaitTimeout.ms(),
|
{.timeout = kStatsWaitTimeout,
|
||||||
*network_manager.time_controller());
|
.clock = network_manager.time_controller()}),
|
||||||
|
IsRtcOk());
|
||||||
|
|
||||||
SendTask(t1, [&] { delete s1; });
|
SendTask(t1, [&] { delete s1; });
|
||||||
SendTask(t2, [&] { delete s2; });
|
SendTask(t2, [&] { delete s2; });
|
||||||
@ -544,9 +566,10 @@ TEST(NetworkEmulationManagerTest, DebugStatsCollectedInDebugMode) {
|
|||||||
|
|
||||||
received_stats_count++;
|
received_stats_count++;
|
||||||
});
|
});
|
||||||
ASSERT_EQ_SIMULATED_WAIT(received_stats_count.load(), 1,
|
ASSERT_THAT(WaitUntil([&] { return received_stats_count.load(); }, Eq(1),
|
||||||
kStatsWaitTimeout.ms(),
|
{.timeout = kStatsWaitTimeout,
|
||||||
*network_manager.time_controller());
|
.clock = network_manager.time_controller()}),
|
||||||
|
IsRtcOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(NetworkEmulationManagerTest, ThroughputStats) {
|
TEST(NetworkEmulationManagerTest, ThroughputStats) {
|
||||||
@ -622,9 +645,10 @@ TEST(NetworkEmulationManagerTest, ThroughputStats) {
|
|||||||
received_stats_count++;
|
received_stats_count++;
|
||||||
});
|
});
|
||||||
|
|
||||||
ASSERT_EQ_SIMULATED_WAIT(received_stats_count.load(), 1,
|
ASSERT_THAT(WaitUntil([&] { return received_stats_count.load(); }, Eq(1),
|
||||||
kStatsWaitTimeout.ms(),
|
{.timeout = kStatsWaitTimeout,
|
||||||
*network_manager.time_controller());
|
.clock = network_manager.time_controller()}),
|
||||||
|
IsRtcOk());
|
||||||
|
|
||||||
EXPECT_EQ(r1.ReceivedCount(), 11);
|
EXPECT_EQ(r1.ReceivedCount(), 11);
|
||||||
EXPECT_EQ(r2.ReceivedCount(), 11);
|
EXPECT_EQ(r2.ReceivedCount(), 11);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user