Replace gunit.h macros with WaitUntil in P2P

Bug: webrtc:381524905
Change-Id: Ia2614729b17a40cd2f5f226e351b3f82c2038977
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374181
Reviewed-by: Jonas Oreland <jonaso@webrtc.org>
Auto-Submit: Evan Shrubsole <eshr@webrtc.org>
Commit-Queue: Evan Shrubsole <eshr@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43758}
This commit is contained in:
Evan Shrubsole 2025-01-17 13:22:54 +00:00 committed by WebRTC LUCI CQ
parent d9593037dd
commit b0038dd14a
10 changed files with 3193 additions and 1019 deletions

View File

@ -1206,6 +1206,7 @@ if (rtc_include_tests) {
":p2p_server_utils",
":p2p_test_utils",
":p2p_transport_channel",
":p2p_transport_channel_ice_field_trials",
":packet_transport_internal",
":port",
":port_allocator",
@ -1230,6 +1231,8 @@ if (rtc_include_tests) {
"../api:libjingle_peerconnection_api",
"../api:mock_async_dns_resolver",
"../api:packet_socket_factory",
"../api:rtc_error",
"../api:rtc_error_matchers",
"../api:scoped_refptr",
"../api/crypto:options",
"../api/task_queue",
@ -1265,6 +1268,7 @@ if (rtc_include_tests) {
"../rtc_base:socket_server",
"../rtc_base:ssl",
"../rtc_base:ssl_adapter",
"../rtc_base:stream",
"../rtc_base:stringutils",
"../rtc_base:testclient",
"../rtc_base:threading",
@ -1277,6 +1281,7 @@ if (rtc_include_tests) {
"../test:rtc_expect_death",
"../test:scoped_key_value_config",
"../test:test_support",
"../test:wait_until",
"//testing/gtest",
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/functional:any_invocable",

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -14,21 +14,28 @@
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <string>
#include <utility>
#include <vector>
#include "api/array_view.h"
#include "api/task_queue/pending_task_safety_flag.h"
#include "api/task_queue/task_queue_base.h"
#include "api/test/rtc_error_matchers.h"
#include "api/units/time_delta.h"
#include "rtc_base/crypto_random.h"
#include "rtc_base/gunit.h"
#include "rtc_base/logging.h"
#include "rtc_base/memory_stream.h"
#include "rtc_base/stream.h"
#include "rtc_base/thread.h"
#include "rtc_base/time_utils.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/wait_until.h"
using ::cricket::PseudoTcp;
using ::testing::IsTrue;
using ::webrtc::ScopedTaskSafety;
using ::webrtc::TaskQueueBase;
using ::webrtc::TimeDelta;
@ -243,10 +250,16 @@ class PseudoTcpTest : public PseudoTcpTestBase {
// Connect and wait until connected.
start = rtc::Time32();
EXPECT_EQ(0, Connect());
EXPECT_TRUE_WAIT(have_connected_, kConnectTimeoutMs);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return have_connected_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kConnectTimeoutMs)}),
webrtc::IsRtcOk());
// Sending will start from OnTcpWriteable and complete when all data has
// been received.
EXPECT_TRUE_WAIT(have_disconnected_, kTransferTimeoutMs);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return have_disconnected_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTransferTimeoutMs)}),
webrtc::IsRtcOk());
elapsed = rtc::Time32() - start;
recv_stream_.GetSize(&received);
// Ensure we closed down OK and we got the right data.
@ -366,10 +379,16 @@ class PseudoTcpTestPingPong : public PseudoTcpTestBase {
// Connect and wait until connected.
start = rtc::Time32();
EXPECT_EQ(0, Connect());
EXPECT_TRUE_WAIT(have_connected_, kConnectTimeoutMs);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return have_connected_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kConnectTimeoutMs)}),
webrtc::IsRtcOk());
// Sending will start from OnTcpWriteable and stop when the required
// number of iterations have completed.
EXPECT_TRUE_WAIT(have_disconnected_, kTransferTimeoutMs);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return have_disconnected_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTransferTimeoutMs)}),
webrtc::IsRtcOk());
elapsed = rtc::TimeSince(start);
RTC_LOG(LS_INFO) << "Performed " << iterations << " pings in " << elapsed
<< " ms";
@ -488,10 +507,16 @@ class PseudoTcpTestReceiveWindow : public PseudoTcpTestBase {
// Connect and wait until connected.
EXPECT_EQ(0, Connect());
EXPECT_TRUE_WAIT(have_connected_, kConnectTimeoutMs);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return have_connected_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kConnectTimeoutMs)}),
webrtc::IsRtcOk());
TaskQueueBase::Current()->PostTask([this] { WriteData(); });
EXPECT_TRUE_WAIT(have_disconnected_, kTransferTimeoutMs);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return have_disconnected_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTransferTimeoutMs)}),
webrtc::IsRtcOk());
ASSERT_EQ(2u, send_position_.size());
ASSERT_EQ(2u, recv_position_.size());

View File

@ -10,21 +10,45 @@
#include "p2p/base/stun_port.h"
#include <cstddef>
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include "absl/functional/any_invocable.h"
#include "api/candidate.h"
#include "api/field_trials_view.h"
#include "api/packet_socket_factory.h"
#include "api/test/mock_async_dns_resolver.h"
#include "api/test/rtc_error_matchers.h"
#include "api/transport/stun.h"
#include "api/units/time_delta.h"
#include "p2p/base/basic_packet_socket_factory.h"
#include "p2p/base/mock_dns_resolving_packet_socket_factory.h"
#include "p2p/base/port.h"
#include "p2p/base/stun_request.h"
#include "p2p/base/test_stun_server.h"
#include "rtc_base/async_packet_socket.h"
#include "rtc_base/crypto_random.h"
#include "rtc_base/dscp.h"
#include "rtc_base/fake_clock.h"
#include "rtc_base/gunit.h"
#include "rtc_base/ip_address.h"
#include "rtc_base/mdns_responder_interface.h"
#include "rtc_base/net_helpers.h"
#include "rtc_base/network.h"
#include "rtc_base/network/received_packet.h"
#include "rtc_base/network_constants.h"
#include "rtc_base/socket.h"
#include "rtc_base/socket_address.h"
#include "rtc_base/ssl_adapter.h"
#include "rtc_base/third_party/sigslot/sigslot.h"
#include "rtc_base/thread.h"
#include "rtc_base/virtual_socket_server.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/scoped_key_value_config.h"
#include "test/wait_until.h"
namespace {
@ -32,6 +56,8 @@ using cricket::ServerAddresses;
using rtc::SocketAddress;
using ::testing::_;
using ::testing::DoAll;
using ::testing::Eq;
using ::testing::IsTrue;
using ::testing::Return;
using ::testing::ReturnPointee;
using ::testing::SetArgPointee;
@ -286,7 +312,11 @@ TEST_F(StunPortTest, TestCreateUdpPort) {
TEST_F(StunPortTest, TestPrepareAddress) {
CreateStunPort(kStunAddr1);
PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
ASSERT_EQ(1U, port()->Candidates().size());
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
std::string expected_server_url = "stun:127.0.0.1:5000";
@ -297,12 +327,19 @@ TEST_F(StunPortTest, TestPrepareAddress) {
TEST_F(StunPortTest, TestPrepareAddressFail) {
CreateStunPort(kBadAddr);
PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
EXPECT_TRUE(error());
EXPECT_EQ(0U, port()->Candidates().size());
EXPECT_EQ_SIMULATED_WAIT(error_event_.error_code,
cricket::STUN_ERROR_SERVER_NOT_REACHABLE, kTimeoutMs,
fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return error_event_.error_code; },
Eq(cricket::STUN_ERROR_SERVER_NOT_REACHABLE),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
EXPECT_NE(error_event_.error_text.find('.'), std::string::npos);
EXPECT_NE(error_event_.address.find(kLocalAddr.HostAsSensitiveURIString()),
std::string::npos);
@ -315,7 +352,11 @@ TEST_F(StunPortTest, TestPrepareAddressFail) {
TEST_F(StunPortTest, TestServerAddressFamilyMismatch) {
CreateStunPort(kIPv6StunAddr1);
PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
EXPECT_TRUE(error());
EXPECT_EQ(0U, port()->Candidates().size());
EXPECT_EQ(0, error_event_.error_code);
@ -356,7 +397,11 @@ TEST_F(StunPortWithMockDnsResolverTest, TestPrepareAddressHostname) {
});
CreateStunPort(kValidHostnameAddr);
PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
ASSERT_EQ(1U, port()->Candidates().size());
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
EXPECT_EQ(kStunCandidatePriority, port()->Candidates()[0].priority());
@ -381,7 +426,11 @@ TEST_F(StunPortWithMockDnsResolverTest,
});
CreateStunPort(kValidHostnameAddr);
PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
ASSERT_EQ(1U, port()->Candidates().size());
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
EXPECT_EQ(kStunCandidatePriority + (cricket::kMaxTurnServers << 8),
@ -392,11 +441,17 @@ TEST_F(StunPortWithMockDnsResolverTest,
TEST_F(StunPortTestWithRealClock, TestPrepareAddressHostnameFail) {
CreateStunPort(kBadHostnameAddr);
PrepareAddress();
EXPECT_TRUE_WAIT(done(), kTimeoutMs);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs)}),
webrtc::IsRtcOk());
EXPECT_TRUE(error());
EXPECT_EQ(0U, port()->Candidates().size());
EXPECT_EQ_WAIT(error_event_.error_code,
cricket::STUN_ERROR_SERVER_NOT_REACHABLE, kTimeoutMs);
EXPECT_THAT(
webrtc::WaitUntil([&] { return error_event_.error_code; },
Eq(cricket::STUN_ERROR_SERVER_NOT_REACHABLE),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs)}),
webrtc::IsRtcOk());
}
// This test verifies keepalive response messages don't result in
@ -405,7 +460,11 @@ TEST_F(StunPortTest, TestKeepAliveResponse) {
SetKeepaliveDelay(500); // 500ms of keepalive delay.
CreateStunPort(kStunAddr1);
PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
ASSERT_EQ(1U, port()->Candidates().size());
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
SIMULATED_WAIT(false, 1000, fake_clock);
@ -416,7 +475,11 @@ TEST_F(StunPortTest, TestKeepAliveResponse) {
TEST_F(StunPortTest, TestSharedSocketPrepareAddress) {
CreateSharedUdpPort(kStunAddr1, nullptr);
PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
ASSERT_EQ(1U, port()->Candidates().size());
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
}
@ -428,7 +491,10 @@ TEST_F(StunPortTestWithRealClock,
TestSharedSocketPrepareAddressInvalidHostname) {
CreateSharedUdpPort(kBadHostnameAddr, nullptr);
PrepareAddress();
EXPECT_TRUE_WAIT(done(), kTimeoutMs);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs)}),
webrtc::IsRtcOk());
ASSERT_EQ(1U, port()->Candidates().size());
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
@ -444,7 +510,11 @@ TEST_F(StunPortTestWithRealClock,
TEST_F(StunPortTest, TestStunCandidateDiscardedWithMdnsObfuscationNotEnabled) {
CreateSharedUdpPort(kStunAddr1, nullptr);
PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
ASSERT_EQ(1U, port()->Candidates().size());
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
EXPECT_TRUE(port()->Candidates()[0].is_local());
@ -456,7 +526,11 @@ TEST_F(StunPortTest, TestStunCandidateGeneratedWithMdnsObfuscationEnabled) {
EnableMdnsObfuscation();
CreateSharedUdpPort(kStunAddr1, nullptr);
PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
ASSERT_EQ(2U, port()->Candidates().size());
// The addresses of the candidates are both equal to kLocalAddr.
@ -483,7 +557,11 @@ TEST_F(StunPortTest, TestNoDuplicatedAddressWithTwoStunServers) {
CreateStunPort(stun_servers);
EXPECT_EQ(IceCandidateType::kSrflx, port()->Type());
PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
EXPECT_EQ(1U, port()->Candidates().size());
EXPECT_EQ(port()->Candidates()[0].relay_protocol(), "");
}
@ -497,11 +575,18 @@ TEST_F(StunPortTest, TestMultipleStunServersWithBadServer) {
CreateStunPort(stun_servers);
EXPECT_EQ(IceCandidateType::kSrflx, port()->Type());
PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
EXPECT_EQ(1U, port()->Candidates().size());
std::string server_url = "stun:" + kBadAddr.ToString();
ASSERT_EQ_SIMULATED_WAIT(error_event_.url, server_url, kTimeoutMs,
fake_clock);
ASSERT_THAT(
webrtc::WaitUntil([&] { return error_event_.url; }, Eq(server_url),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
}
// Test that two candidates are allocated if the two STUN servers return
@ -518,7 +603,11 @@ TEST_F(StunPortTest, TestTwoCandidatesWithTwoStunServersAcrossNat) {
CreateStunPort(stun_servers);
EXPECT_EQ(IceCandidateType::kSrflx, port()->Type());
PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
EXPECT_EQ(2U, port()->Candidates().size());
EXPECT_EQ(port()->Candidates()[0].relay_protocol(), "");
EXPECT_EQ(port()->Candidates()[1].relay_protocol(), "");
@ -567,9 +656,16 @@ TEST_F(StunPortTest, TestStunBindingRequestShortLifetime) {
SetKeepaliveLifetime(100);
CreateStunPort(kStunAddr1);
PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
EXPECT_TRUE_SIMULATED_WAIT(!HasPendingRequest(cricket::STUN_BINDING_REQUEST),
2000, fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
EXPECT_THAT(
webrtc::WaitUntil(
[&] { return !HasPendingRequest(cricket::STUN_BINDING_REQUEST); },
IsTrue(), {.clock = &fake_clock}),
webrtc::IsRtcOk());
}
// Test that by default, the STUN binding requests will last for a long time.
@ -577,9 +673,16 @@ TEST_F(StunPortTest, TestStunBindingRequestLongLifetime) {
SetKeepaliveDelay(101);
CreateStunPort(kStunAddr1);
PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
EXPECT_TRUE_SIMULATED_WAIT(HasPendingRequest(cricket::STUN_BINDING_REQUEST),
1000, fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
EXPECT_THAT(
webrtc::WaitUntil(
[&] { return HasPendingRequest(cricket::STUN_BINDING_REQUEST); },
IsTrue(), {.clock = &fake_clock}),
webrtc::IsRtcOk());
}
class MockAsyncPacketSocket : public rtc::AsyncPacketSocket {
@ -621,10 +724,9 @@ TEST_F(StunPortTest, TestStunPacketsHaveDscpPacketOption) {
EXPECT_CALL(*socket, SetOption(_, _)).WillRepeatedly(Return(0));
// If DSCP is not set on the socket, stun packets should have no value.
EXPECT_CALL(*socket,
SendTo(_, _, _,
::testing::Field(&rtc::PacketOptions::dscp,
::testing::Eq(rtc::DSCP_NO_CHANGE))))
EXPECT_CALL(*socket, SendTo(_, _, _,
::testing::Field(&rtc::PacketOptions::dscp,
Eq(rtc::DSCP_NO_CHANGE))))
.WillOnce(Return(100));
PrepareAddress();
@ -632,9 +734,13 @@ TEST_F(StunPortTest, TestStunPacketsHaveDscpPacketOption) {
port()->SetOption(rtc::Socket::OPT_DSCP, rtc::DSCP_AF41);
EXPECT_CALL(*socket, SendTo(_, _, _,
::testing::Field(&rtc::PacketOptions::dscp,
::testing::Eq(rtc::DSCP_AF41))))
Eq(rtc::DSCP_AF41))))
.WillRepeatedly(Return(100));
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
}
class StunIPv6PortTestBase : public StunPortTestBase {
@ -661,7 +767,11 @@ class StunIPv6PortTest : public FakeClockBase, public StunIPv6PortTestBase {};
TEST_F(StunIPv6PortTest, TestPrepareAddress) {
CreateStunPort(kIPv6StunAddr1);
PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
ASSERT_EQ(1U, port()->Candidates().size());
EXPECT_TRUE(kIPv6LocalAddr.EqualIPs(port()->Candidates()[0].address()));
std::string expected_server_url = "stun:::1:5000";
@ -672,12 +782,19 @@ TEST_F(StunIPv6PortTest, TestPrepareAddress) {
TEST_F(StunIPv6PortTest, TestPrepareAddressFail) {
CreateStunPort(kIPv6BadAddr);
PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
EXPECT_TRUE(error());
EXPECT_EQ(0U, port()->Candidates().size());
EXPECT_EQ_SIMULATED_WAIT(error_event_.error_code,
cricket::STUN_ERROR_SERVER_NOT_REACHABLE, kTimeoutMs,
fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return error_event_.error_code; },
Eq(cricket::STUN_ERROR_SERVER_NOT_REACHABLE),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
EXPECT_NE(error_event_.error_text.find('.'), std::string::npos);
EXPECT_NE(
error_event_.address.find(kIPv6LocalAddr.HostAsSensitiveURIString()),
@ -691,7 +808,11 @@ TEST_F(StunIPv6PortTest, TestPrepareAddressFail) {
TEST_F(StunIPv6PortTest, TestServerAddressFamilyMismatch) {
CreateStunPort(kStunAddr1);
PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
EXPECT_TRUE(error());
EXPECT_EQ(0U, port()->Candidates().size());
EXPECT_EQ(0, error_event_.error_code);
@ -701,11 +822,17 @@ TEST_F(StunIPv6PortTest, TestServerAddressFamilyMismatch) {
TEST_F(StunIPv6PortTestWithRealClock, TestPrepareAddressHostnameFail) {
CreateStunPort(kBadHostnameAddr);
PrepareAddress();
EXPECT_TRUE_WAIT(done(), kTimeoutMs);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs)}),
webrtc::IsRtcOk());
EXPECT_TRUE(error());
EXPECT_EQ(0U, port()->Candidates().size());
EXPECT_EQ_WAIT(error_event_.error_code,
cricket::STUN_ERROR_SERVER_NOT_REACHABLE, kTimeoutMs);
EXPECT_THAT(
webrtc::WaitUntil([&] { return error_event_.error_code; },
Eq(cricket::STUN_ERROR_SERVER_NOT_REACHABLE),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs)}),
webrtc::IsRtcOk());
}
class StunIPv6PortTestWithMockDnsResolver : public StunIPv6PortTest {
@ -745,7 +872,11 @@ TEST_F(StunIPv6PortTestWithMockDnsResolver, TestPrepareAddressHostname) {
});
CreateStunPort(kValidHostnameAddr);
PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
ASSERT_EQ(1U, port()->Candidates().size());
EXPECT_TRUE(kIPv6LocalAddr.EqualIPs(port()->Candidates()[0].address()));
EXPECT_EQ(kIPv6StunCandidatePriority, port()->Candidates()[0].priority());
@ -772,7 +903,11 @@ TEST_F(StunIPv6PortTestWithMockDnsResolver,
});
CreateStunPort(kValidHostnameAddr, &field_trials);
PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
EXPECT_THAT(
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs),
.clock = &fake_clock}),
webrtc::IsRtcOk());
ASSERT_EQ(1U, port()->Candidates().size());
EXPECT_TRUE(kIPv6LocalAddr.EqualIPs(port()->Candidates()[0].address()));
EXPECT_EQ(kIPv6StunCandidatePriority + (cricket::kMaxTurnServers << 8),

View File

@ -10,18 +10,28 @@
#include "p2p/base/stun_request.h"
#include <utility>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <vector>
#include "rtc_base/crypto_random.h"
#include "api/test/rtc_error_matchers.h"
#include "api/transport/stun.h"
#include "api/units/time_delta.h"
#include "rtc_base/fake_clock.h"
#include "rtc_base/gunit.h"
#include "rtc_base/logging.h"
#include "rtc_base/thread.h"
#include "rtc_base/time_utils.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/wait_until.h"
namespace cricket {
namespace {
using ::testing::Ne;
std::unique_ptr<StunMessage> CreateStunMessage(
StunMessageType type,
const StunMessage* req = nullptr) {
@ -149,8 +159,11 @@ TEST_F(StunRequestTest, TestBackoff) {
int64_t start = rtc::TimeMillis();
manager_.Send(request);
for (int i = 0; i < 9; ++i) {
EXPECT_TRUE_SIMULATED_WAIT(request_count_ != i, STUN_TOTAL_TIMEOUT,
fake_clock);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return request_count_; }, Ne(i),
{.timeout = webrtc::TimeDelta::Millis(STUN_TOTAL_TIMEOUT),
.clock = &fake_clock}),
webrtc::IsRtcOk());
int64_t elapsed = rtc::TimeMillis() - start;
RTC_DLOG(LS_INFO) << "STUN request #" << (i + 1) << " sent at " << elapsed
<< " ms";

View File

@ -10,23 +10,36 @@
#include "p2p/base/tcp_port.h"
#include <cstdint>
#include <list>
#include <memory>
#include <string>
#include <vector>
#include "api/candidate.h"
#include "api/test/rtc_error_matchers.h"
#include "api/units/time_delta.h"
#include "p2p/base/basic_packet_socket_factory.h"
#include "p2p/base/connection.h"
#include "p2p/base/p2p_constants.h"
#include "p2p/base/port.h"
#include "p2p/base/transport_description.h"
#include "rtc_base/async_packet_socket.h"
#include "rtc_base/checks.h"
#include "rtc_base/crypto_random.h"
#include "rtc_base/gunit.h"
#include "rtc_base/ip_address.h"
#include "rtc_base/network.h"
#include "rtc_base/network/sent_packet.h"
#include "rtc_base/socket.h"
#include "rtc_base/socket_address.h"
#include "rtc_base/third_party/sigslot/sigslot.h"
#include "rtc_base/thread.h"
#include "rtc_base/time_utils.h"
#include "rtc_base/virtual_socket_server.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/scoped_key_value_config.h"
#include "test/wait_until.h"
using cricket::Connection;
using cricket::ICE_PWD_LENGTH;
@ -34,6 +47,8 @@ using cricket::ICE_UFRAG_LENGTH;
using cricket::Port;
using cricket::TCPPort;
using rtc::SocketAddress;
using ::testing::Eq;
using ::testing::IsTrue;
static int kTimeout = 1000;
static const SocketAddress kLocalAddr("11.11.11.11", 0);
@ -135,7 +150,10 @@ TEST_F(TCPPortTest, TestTCPPortWithLocalhostAddress) {
remote_port->PrepareAddress();
Connection* conn = local_port->CreateConnection(remote_port->Candidates()[0],
Port::ORIGIN_MESSAGE);
EXPECT_TRUE_WAIT(conn->connected(), kTimeout);
EXPECT_THAT(
webrtc::WaitUntil([&] { return conn->connected(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
// Verify that the socket actually used localhost, otherwise this test isn't
// doing what it meant to.
ASSERT_EQ(local_address.ipaddr(),
@ -164,7 +182,10 @@ TEST_F(TCPPortTest, TCPPortDiscardedIfBoundAddressDoesNotMatchNetwork) {
Connection* conn = local_port->CreateConnection(remote_port->Candidates()[0],
Port::ORIGIN_MESSAGE);
ConnectionObserver observer(conn);
EXPECT_TRUE_WAIT(observer.connection_destroyed(), kTimeout);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return observer.connection_destroyed(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
}
// A caveat for the above logic: if the socket ends up bound to one of the IPs
@ -189,7 +210,10 @@ TEST_F(TCPPortTest, TCPPortNotDiscardedIfNotBoundToBestIP) {
// Expect connection to succeed.
Connection* conn = local_port->CreateConnection(remote_port->Candidates()[0],
Port::ORIGIN_MESSAGE);
EXPECT_TRUE_WAIT(conn->connected(), kTimeout);
EXPECT_THAT(
webrtc::WaitUntil([&] { return conn->connected(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
// Verify that the socket actually used the alternate address, otherwise this
// test isn't doing what it meant to.
@ -213,7 +237,10 @@ TEST_F(TCPPortTest, TCPPortNotDiscardedIfBoundToTemporaryIP) {
Connection* conn = local_port->CreateConnection(remote_port->Candidates()[0],
Port::ORIGIN_MESSAGE);
ASSERT_NE(nullptr, conn);
EXPECT_TRUE_WAIT(conn->connected(), kTimeout);
EXPECT_THAT(
webrtc::WaitUntil([&] { return conn->connected(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
}
class SentPacketCounter : public sigslot::has_slots<> {
@ -243,7 +270,10 @@ TEST_F(TCPPortTest, SignalSentPacket) {
Connection* client_conn =
client->CreateConnection(server->Candidates()[0], Port::ORIGIN_MESSAGE);
ASSERT_NE(nullptr, client_conn);
ASSERT_TRUE_WAIT(client_conn->connected(), kTimeout);
ASSERT_THAT(
webrtc::WaitUntil([&] { return client_conn->connected(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
// Need to get the port of the actual outgoing socket, not the server socket..
cricket::Candidate client_candidate = client->Candidates()[0];
@ -253,12 +283,21 @@ TEST_F(TCPPortTest, SignalSentPacket) {
Connection* server_conn =
server->CreateConnection(client_candidate, Port::ORIGIN_THIS_PORT);
ASSERT_NE(nullptr, server_conn);
ASSERT_TRUE_WAIT(server_conn->connected(), kTimeout);
ASSERT_THAT(
webrtc::WaitUntil([&] { return server_conn->connected(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
client_conn->Ping(rtc::TimeMillis());
server_conn->Ping(rtc::TimeMillis());
ASSERT_TRUE_WAIT(client_conn->writable(), kTimeout);
ASSERT_TRUE_WAIT(server_conn->writable(), kTimeout);
ASSERT_THAT(
webrtc::WaitUntil([&] { return client_conn->writable(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
ASSERT_THAT(
webrtc::WaitUntil([&] { return server_conn->writable(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
SentPacketCounter client_counter(client.get());
SentPacketCounter server_counter(server.get());
@ -267,8 +306,14 @@ TEST_F(TCPPortTest, SignalSentPacket) {
client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions());
server_conn->Send(&kData, sizeof(kData), rtc::PacketOptions());
}
EXPECT_EQ_WAIT(10, client_counter.sent_packets(), kTimeout);
EXPECT_EQ_WAIT(10, server_counter.sent_packets(), kTimeout);
EXPECT_THAT(
webrtc::WaitUntil([&] { return client_counter.sent_packets(); }, Eq(10),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
EXPECT_THAT(
webrtc::WaitUntil([&] { return server_counter.sent_packets(); }, Eq(10),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
}
// Test that SignalSentPacket is fired when a packet is successfully sent, even
@ -287,7 +332,10 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) {
Connection* client_conn =
client->CreateConnection(server->Candidates()[0], Port::ORIGIN_MESSAGE);
ASSERT_NE(nullptr, client_conn);
ASSERT_TRUE_WAIT(client_conn->connected(), kTimeout);
ASSERT_THAT(
webrtc::WaitUntil([&] { return client_conn->connected(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
// Need to get the port of the actual outgoing socket.
cricket::Candidate client_candidate = client->Candidates()[0];
@ -297,10 +345,16 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) {
client_candidate.set_tcptype("");
Connection* server_conn =
server->CreateConnection(client_candidate, Port::ORIGIN_THIS_PORT);
ASSERT_TRUE_WAIT(server_conn->connected(), kTimeout);
ASSERT_THAT(
webrtc::WaitUntil([&] { return server_conn->connected(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
EXPECT_FALSE(client_conn->writable());
client_conn->Ping(rtc::TimeMillis());
ASSERT_TRUE_WAIT(client_conn->writable(), kTimeout);
ASSERT_THAT(
webrtc::WaitUntil([&] { return client_conn->writable(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
SentPacketCounter client_counter(client.get());
static const char kData[] = "hello";
@ -310,7 +364,10 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) {
// Deleting the server port should break the current connection.
server = nullptr;
server_conn = nullptr;
ASSERT_TRUE_WAIT(!client_conn->connected(), kTimeout);
ASSERT_THAT(
webrtc::WaitUntil([&] { return !client_conn->connected(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
// Recreate the server port with the same port number.
server = CreateTCPPort(kRemoteAddr, /*allow_listen=*/true, kServerPort);
@ -321,7 +378,10 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) {
// packet will be discarded.
result = client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions());
EXPECT_EQ(result, SOCKET_ERROR);
ASSERT_TRUE_WAIT(client_conn->connected(), kTimeout);
ASSERT_THAT(
webrtc::WaitUntil([&] { return client_conn->connected(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
// For unknown reasons, connection is still supposed to be writable....
EXPECT_TRUE(client_conn->writable());
for (int i = 0; i < 10; ++i) {
@ -330,7 +390,10 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) {
SOCKET_ERROR);
}
// And are not reported as sent.
EXPECT_EQ_WAIT(client_counter.sent_packets(), 1, kTimeout);
EXPECT_THAT(
webrtc::WaitUntil([&] { return client_counter.sent_packets(); }, Eq(1),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
// Create the server connection again so server can reply to STUN pings.
// Client outgoing socket port will have changed since the client create a new
@ -342,13 +405,22 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) {
client_candidate.set_tcptype("");
server_conn =
server->CreateConnection(client_candidate, Port::ORIGIN_THIS_PORT);
ASSERT_TRUE_WAIT(server_conn->connected(), kTimeout);
EXPECT_EQ_WAIT(client_counter.sent_packets(), 1, kTimeout);
ASSERT_THAT(
webrtc::WaitUntil([&] { return server_conn->connected(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
EXPECT_THAT(
webrtc::WaitUntil([&] { return client_counter.sent_packets(); }, Eq(1),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
// Send Stun Binding request.
client_conn->Ping(rtc::TimeMillis());
// The Stun Binding request is reported as sent.
EXPECT_EQ_WAIT(client_counter.sent_packets(), 2, kTimeout);
EXPECT_THAT(
webrtc::WaitUntil([&] { return client_counter.sent_packets(); }, Eq(2),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
// Wait a bit for the Stun response to be received.
rtc::Thread::Current()->ProcessMessages(100);
@ -358,5 +430,8 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) {
EXPECT_EQ(client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions()),
6);
}
EXPECT_EQ_WAIT(client_counter.sent_packets(), 2 + 5, kTimeout);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return client_counter.sent_packets(); }, Eq(2 + 5),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
}

View File

@ -7,10 +7,29 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <cstddef>
#include <cstdint>
#include <string>
#include "absl/functional/any_invocable.h"
#include "api/array_view.h"
#include "api/candidate.h"
#include "api/test/mock_async_dns_resolver.h"
#include "api/test/rtc_error_matchers.h"
#include "api/transport/stun.h"
#include "p2p/base/connection_info.h"
#include "p2p/base/port.h"
#include "p2p/base/port_interface.h"
#include "p2p/base/stun_request.h"
#include "p2p/client/relay_port_factory_interface.h"
#include "rtc_base/async_packet_socket.h"
#include "rtc_base/ip_address.h"
#include "rtc_base/net_helpers.h"
#include "rtc_base/network.h"
#include "rtc_base/network/received_packet.h"
#include "rtc_base/third_party/sigslot/sigslot.h"
#include "test/gmock.h"
#include "test/wait_until.h"
#if defined(WEBRTC_POSIX)
#include <dirent.h>
@ -54,6 +73,9 @@ using rtc::SocketAddress;
using ::testing::_;
using ::testing::DoAll;
using ::testing::Eq;
using ::testing::IsTrue;
using ::testing::Ne;
using ::testing::Return;
using ::testing::ReturnPointee;
using ::testing::SetArgPointee;
@ -384,12 +406,19 @@ class TurnPortTest : public ::testing::Test,
// turn_port_ should have been created.
ASSERT_TRUE(turn_port_ != nullptr);
turn_port_->PrepareAddress();
ASSERT_TRUE_SIMULATED_WAIT(
turn_ready_, TimeToGetTurnCandidate(protocol_type), fake_clock_);
ASSERT_THAT(webrtc::WaitUntil([&] { return turn_ready_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(
TimeToGetTurnCandidate(protocol_type)),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
CreateUdpPort();
udp_port_->PrepareAddress();
ASSERT_TRUE_SIMULATED_WAIT(udp_ready_, kSimulatedRtt, fake_clock_);
ASSERT_THAT(
webrtc::WaitUntil([&] { return udp_ready_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
}
// Returns the fake clock time to establish a connection over the given
@ -453,7 +482,11 @@ class TurnPortTest : public ::testing::Test,
void TestTurnAllocateSucceeds(unsigned int timeout) {
ASSERT_TRUE(turn_port_);
turn_port_->PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, timeout, fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil([&] { return turn_ready_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(timeout),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
ASSERT_EQ(1U, turn_port_->Candidates().size());
EXPECT_EQ(kTurnUdpExtAddr.ipaddr(),
turn_port_->Candidates()[0].address().ipaddr());
@ -464,8 +497,11 @@ class TurnPortTest : public ::testing::Test,
absl::string_view expected_url) {
ASSERT_TRUE(turn_port_);
turn_port_->PrepareAddress();
ASSERT_TRUE_SIMULATED_WAIT(
turn_ready_, TimeToGetTurnCandidate(protocol_type), fake_clock_);
ASSERT_THAT(webrtc::WaitUntil([&] { return turn_ready_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(
TimeToGetTurnCandidate(protocol_type)),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
ASSERT_EQ(1U, turn_port_->Candidates().size());
EXPECT_EQ(turn_port_->Candidates()[0].url(), expected_url);
}
@ -486,9 +522,12 @@ class TurnPortTest : public ::testing::Test,
const SocketAddress old_addr = turn_port_->server_address().address;
turn_port_->PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(turn_ready_,
TimeToGetAlternateTurnCandidate(protocol_type),
fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil([&] { return turn_ready_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(
TimeToGetAlternateTurnCandidate(protocol_type)),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// Retrieve the address again, the turn port's address should be
// changed.
const SocketAddress new_addr = turn_port_->server_address().address;
@ -511,8 +550,12 @@ class TurnPortTest : public ::testing::Test,
turn_port_->PrepareAddress();
// Need time to connect to TURN server, send Allocate request and receive
// redirect notice.
EXPECT_TRUE_SIMULATED_WAIT(
turn_error_, kSimulatedRtt + TimeToConnect(protocol_type), fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil([&] { return turn_error_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(
kSimulatedRtt + TimeToConnect(protocol_type)),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
}
void TestTurnAlternateServerPingPong(ProtocolType protocol_type) {
@ -529,9 +572,12 @@ class TurnPortTest : public ::testing::Test,
ProtocolAddress(kTurnIntAddr, protocol_type));
turn_port_->PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(turn_error_,
TimeToGetAlternateTurnCandidate(protocol_type),
fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil([&] { return turn_error_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(
TimeToGetAlternateTurnCandidate(protocol_type)),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
ASSERT_EQ(0U, turn_port_->Candidates().size());
rtc::SocketAddress address;
// Verify that we have exhausted all alternate servers instead of
@ -553,9 +599,12 @@ class TurnPortTest : public ::testing::Test,
ProtocolAddress(kTurnIntAddr, protocol_type));
turn_port_->PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(turn_error_,
TimeToGetAlternateTurnCandidate(protocol_type),
fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil([&] { return turn_error_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(
TimeToGetAlternateTurnCandidate(protocol_type)),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
ASSERT_EQ(0U, turn_port_->Candidates().size());
}
@ -593,8 +642,11 @@ class TurnPortTest : public ::testing::Test,
ProtocolAddress(server_address, protocol_type));
turn_port_->PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(
turn_error_, TimeToGetTurnCandidate(protocol_type), fake_clock_);
EXPECT_THAT(webrtc::WaitUntil([&] { return turn_error_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(
TimeToGetTurnCandidate(protocol_type)),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// Wait for some extra time, and make sure no packets were received on the
// loopback port we created (or in the case of TCP, no connection attempt
@ -629,21 +681,32 @@ class TurnPortTest : public ::testing::Test,
Connection* conn2 = turn_port_->CreateConnection(udp_port_->Candidates()[0],
Port::ORIGIN_MESSAGE);
ASSERT_TRUE(conn2 != NULL);
ASSERT_TRUE_SIMULATED_WAIT(turn_create_permission_success_, kSimulatedRtt,
fake_clock_);
ASSERT_THAT(webrtc::WaitUntil(
[&] { return turn_create_permission_success_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
conn2->Ping(0);
// Two hops from TURN port to UDP port through TURN server, thus two RTTs.
EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn2->write_state(),
kSimulatedRtt * 2, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return conn2->write_state(); },
Eq(Connection::STATE_WRITABLE),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
EXPECT_TRUE(conn1->receiving());
EXPECT_TRUE(conn2->receiving());
EXPECT_EQ(Connection::STATE_WRITE_INIT, conn1->write_state());
// Send another ping from UDP to TURN.
conn1->Ping(0);
EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn1->write_state(),
kSimulatedRtt * 2, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return conn1->write_state(); },
Eq(Connection::STATE_WRITABLE),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
EXPECT_TRUE(conn2->receiving());
}
@ -661,12 +724,19 @@ class TurnPortTest : public ::testing::Test,
turn_port_->set_timeout_delay(10 * 60 * 1000);
ASSERT_TRUE(conn2 != NULL);
ASSERT_TRUE_SIMULATED_WAIT(turn_create_permission_success_, kSimulatedRtt,
fake_clock_);
ASSERT_THAT(webrtc::WaitUntil(
[&] { return turn_create_permission_success_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// Make sure turn connection can receive.
conn1->Ping(0);
EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn1->write_state(),
kSimulatedRtt * 2, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return conn1->write_state(); },
Eq(Connection::STATE_WRITABLE),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
EXPECT_FALSE(turn_unknown_address_);
// Destroy the connection on the TURN port. The TurnEntry still exists, so
@ -674,8 +744,11 @@ class TurnPortTest : public ::testing::Test,
turn_port_->DestroyConnection(conn2);
conn1->Ping(0);
EXPECT_TRUE_SIMULATED_WAIT(turn_unknown_address_, kSimulatedRtt,
fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil([&] { return turn_unknown_address_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// Wait for TurnEntry to expire. Timeout is 5 minutes.
// Expect that it still processes an incoming ping and signals the
@ -707,14 +780,21 @@ class TurnPortTest : public ::testing::Test,
conn1->set_remote_password_for_test(pwd);
conn1->Ping(0);
EXPECT_TRUE_SIMULATED_WAIT(turn_unknown_address_, kSimulatedRtt,
fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil([&] { return turn_unknown_address_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// If the connection is created again, it will start to receive pings.
conn2 = turn_port_->CreateConnection(udp_port_->Candidates()[0],
Port::ORIGIN_MESSAGE);
conn1->Ping(0);
EXPECT_TRUE_SIMULATED_WAIT(conn2->receiving(), kSimulatedRtt, fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil([&] { return conn2->receiving(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
}
void TestTurnSendData(ProtocolType protocol_type) {
@ -742,11 +822,19 @@ class TurnPortTest : public ::testing::Test,
conn2->SignalDestroyed.connect(this,
&TurnPortTest::OnConnectionSignalDestroyed);
conn1->Ping(0);
EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn1->write_state(),
kSimulatedRtt * 2, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return conn1->write_state(); },
Eq(Connection::STATE_WRITABLE),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
conn2->Ping(0);
EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn2->write_state(),
kSimulatedRtt * 2, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return conn2->write_state(); },
Eq(Connection::STATE_WRITABLE),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// Send some data.
size_t num_packets = 256;
@ -774,8 +862,12 @@ class TurnPortTest : public ::testing::Test,
void TestTurnReleaseAllocation(ProtocolType protocol_type) {
PrepareTurnAndUdpPorts(protocol_type);
turn_port_.reset();
EXPECT_EQ_SIMULATED_WAIT(0U, turn_server_.server()->allocations().size(),
kSimulatedRtt, fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil(
[&] { return turn_server_.server()->allocations().size(); }, Eq(0U),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
}
// Test that the TURN allocation is released by sending a refresh request
@ -806,11 +898,19 @@ class TurnPortTest : public ::testing::Test,
&TurnPortTest::OnConnectionSignalDestroyed);
conn1->Ping(0);
EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn1->write_state(),
kSimulatedRtt * 2, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return conn1->write_state(); },
Eq(Connection::STATE_WRITABLE),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
conn2->Ping(0);
EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn2->write_state(),
kSimulatedRtt * 2, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return conn2->write_state(); },
Eq(Connection::STATE_WRITABLE),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// Send some data from Udp to TurnPort.
unsigned char buf[256] = {0};
@ -821,7 +921,11 @@ class TurnPortTest : public ::testing::Test,
turn_port_->Release();
// Wait for the TurnPort to signal closed.
ASSERT_TRUE_SIMULATED_WAIT(turn_port_closed_, kSimulatedRtt, fake_clock_);
ASSERT_THAT(
webrtc::WaitUntil([&] { return turn_port_closed_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// But the data should have arrived first.
ASSERT_EQ(1ul, turn_packets_.size());
@ -908,7 +1012,10 @@ TEST_F(TurnPortTest, TestReconstructedServerUrlForHostname) {
// As VSS doesn't provide DNS resolution, name resolve will fail,
// the error will be set and contain the url.
turn_port_->PrepareAddress();
EXPECT_TRUE_WAIT(turn_error_, kResolverTimeout);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_error_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kResolverTimeout)}),
webrtc::IsRtcOk());
std::string server_url =
"turn:" + kTurnInvalidAddr.ToString() + "?transport=udp";
ASSERT_EQ(error_event_.url, server_url);
@ -963,10 +1070,18 @@ TEST_F(TurnPortTest, TestTurnAllocateWithoutLoggingId) {
TEST_F(TurnPortTest, TestTurnBadCredentials) {
CreateTurnPort(kTurnUsername, "bad", kTurnUdpProtoAddr);
turn_port_->PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(turn_error_, kSimulatedRtt * 3, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_error_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 3),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
ASSERT_EQ(0U, turn_port_->Candidates().size());
EXPECT_EQ_SIMULATED_WAIT(error_event_.error_code, STUN_ERROR_UNAUTHORIZED,
kSimulatedRtt * 3, fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil(
[&] { return error_event_.error_code; }, Eq(STUN_ERROR_UNAUTHORIZED),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 3),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
EXPECT_EQ(error_event_.error_text, "Unauthorized");
}
@ -975,7 +1090,11 @@ TEST_F(TurnPortTest, TestTurnBadCredentials) {
TEST_F(TurnPortTest, TestServerAddressFamilyMismatch) {
CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpIPv6ProtoAddr);
turn_port_->PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(turn_error_, kSimulatedRtt * 3, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_error_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 3),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
ASSERT_EQ(0U, turn_port_->Candidates().size());
EXPECT_EQ(0, error_event_.error_code);
}
@ -986,7 +1105,11 @@ TEST_F(TurnPortTest, TestServerAddressFamilyMismatch6) {
CreateTurnPort(kLocalIPv6Addr, kTurnUsername, kTurnPassword,
kTurnUdpProtoAddr);
turn_port_->PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(turn_error_, kSimulatedRtt * 3, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_error_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 3),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
ASSERT_EQ(0U, turn_port_->Candidates().size());
EXPECT_EQ(0, error_event_.error_code);
}
@ -1039,10 +1162,17 @@ TEST_F(TurnPortTest,
// Shouldn't take more than 1 RTT to realize the bound address isn't the one
// expected.
EXPECT_TRUE_SIMULATED_WAIT(turn_error_, kSimulatedRtt, fake_clock_);
EXPECT_EQ_SIMULATED_WAIT(error_event_.error_code,
STUN_ERROR_SERVER_NOT_REACHABLE, kSimulatedRtt,
fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil([&] { return turn_error_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
EXPECT_THAT(
webrtc::WaitUntil([&] { return error_event_.error_code; },
Eq(STUN_ERROR_SERVER_NOT_REACHABLE),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
EXPECT_NE(error_event_.error_text.find('.'), std::string::npos);
EXPECT_NE(error_event_.address.find(kLocalAddr2.HostAsSensitiveURIString()),
std::string::npos);
@ -1074,7 +1204,11 @@ TEST_F(TurnPortTest, TurnTcpAllocationNotDiscardedIfNotBoundToBestIP) {
turn_port_->PrepareAddress();
// Candidate should be gathered as normally.
EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 3, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_ready_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 3),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
ASSERT_EQ(1U, turn_port_->Candidates().size());
// Verify that the socket actually used the alternate address, otherwise this
@ -1101,7 +1235,11 @@ TEST_F(TurnPortTest, TCPPortNotDiscardedIfBoundToTemporaryIP) {
turn_port_->PrepareAddress();
// Candidate should be gathered as normally.
EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 3, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_ready_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 3),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
ASSERT_EQ(1U, turn_port_->Candidates().size());
}
@ -1112,14 +1250,20 @@ TEST_F(TurnPortTest, TestTurnTcpOnAddressResolveFailure) {
CreateTurnPort(kTurnUsername, kTurnPassword,
ProtocolAddress(kTurnInvalidAddr, PROTO_TCP));
turn_port_->PrepareAddress();
EXPECT_TRUE_WAIT(turn_error_, kResolverTimeout);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_error_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kResolverTimeout)}),
webrtc::IsRtcOk());
// As VSS doesn't provide DNS resolution, name resolve will fail. TurnPort
// will proceed in creating a TCP socket which will fail as there is no
// server on the above domain and error will be set to SOCKET_ERROR.
EXPECT_EQ(SOCKET_ERROR, turn_port_->error());
EXPECT_EQ_SIMULATED_WAIT(error_event_.error_code,
STUN_ERROR_SERVER_NOT_REACHABLE, kSimulatedRtt,
fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil([&] { return error_event_.error_code; },
Eq(STUN_ERROR_SERVER_NOT_REACHABLE),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
std::string server_url =
"turn:" + kTurnInvalidAddr.ToString() + "?transport=tcp";
ASSERT_EQ(error_event_.url, server_url);
@ -1132,7 +1276,10 @@ TEST_F(TurnPortTest, TestTurnTlsOnAddressResolveFailure) {
CreateTurnPort(kTurnUsername, kTurnPassword,
ProtocolAddress(kTurnInvalidAddr, PROTO_TLS));
turn_port_->PrepareAddress();
EXPECT_TRUE_WAIT(turn_error_, kResolverTimeout);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_error_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kResolverTimeout)}),
webrtc::IsRtcOk());
EXPECT_EQ(SOCKET_ERROR, turn_port_->error());
}
@ -1142,7 +1289,10 @@ TEST_F(TurnPortTest, TestTurnUdpOnAddressResolveFailure) {
CreateTurnPort(kTurnUsername, kTurnPassword,
ProtocolAddress(kTurnInvalidAddr, PROTO_UDP));
turn_port_->PrepareAddress();
EXPECT_TRUE_WAIT(turn_error_, kResolverTimeout);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_error_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kResolverTimeout)}),
webrtc::IsRtcOk());
// Error from turn port will not be socket error.
EXPECT_NE(SOCKET_ERROR, turn_port_->error());
}
@ -1151,7 +1301,11 @@ TEST_F(TurnPortTest, TestTurnUdpOnAddressResolveFailure) {
TEST_F(TurnPortTest, TestTurnAllocateBadPassword) {
CreateTurnPort(kTurnUsername, "bad", kTurnUdpProtoAddr);
turn_port_->PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(turn_error_, kSimulatedRtt * 2, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_error_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
ASSERT_EQ(0U, turn_port_->Candidates().size());
}
@ -1161,7 +1315,11 @@ TEST_F(TurnPortTest, TestTurnAllocateNonceResetAfterAllocateMismatch) {
// Do a normal allocation first.
CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
turn_port_->PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 2, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_ready_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
rtc::SocketAddress first_addr(turn_port_->socket()->GetLocalAddress());
// Destroy the turnport while keeping the drop probability to 1 to
// suppress the release of the allocation at the server.
@ -1187,7 +1345,11 @@ TEST_F(TurnPortTest, TestTurnAllocateNonceResetAfterAllocateMismatch) {
// Four round trips; first we'll get "stale nonce", then
// "allocate mismatch", then "stale nonce" again, then finally it will
// succeed.
EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 4, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_ready_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 4),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
EXPECT_NE(first_nonce, turn_port_->nonce());
}
@ -1197,7 +1359,11 @@ TEST_F(TurnPortTest, TestTurnAllocateMismatch) {
// Do a normal allocation first.
CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
turn_port_->PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 2, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_ready_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
rtc::SocketAddress first_addr(turn_port_->socket()->GetLocalAddress());
// Clear connected_ flag on turnport to suppress the release of
@ -1217,7 +1383,11 @@ TEST_F(TurnPortTest, TestTurnAllocateMismatch) {
// Four round trips; first we'll get "stale nonce", then
// "allocate mismatch", then "stale nonce" again, then finally it will
// succeed.
EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 4, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_ready_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 4),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// Verifies that the new port has a different address now.
EXPECT_NE(first_addr, turn_port_->socket()->GetLocalAddress());
@ -1237,7 +1407,11 @@ TEST_F(TurnPortTest, TestSharedSocketAllocateMismatch) {
// Do a normal allocation first.
CreateSharedTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
turn_port_->PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 2, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_ready_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
rtc::SocketAddress first_addr(turn_port_->socket()->GetLocalAddress());
// Clear connected_ flag on turnport to suppress the release of
@ -1253,7 +1427,11 @@ TEST_F(TurnPortTest, TestSharedSocketAllocateMismatch) {
turn_port_->PrepareAddress();
// Extra 2 round trips due to allocate mismatch.
EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 4, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_ready_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 4),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// Verifies that the new port has a different address now.
EXPECT_NE(first_addr, turn_port_->socket()->GetLocalAddress());
@ -1266,7 +1444,11 @@ TEST_F(TurnPortTest, TestTurnTcpAllocateMismatch) {
// Do a normal allocation first.
turn_port_->PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 3, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_ready_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 3),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
rtc::SocketAddress first_addr(turn_port_->socket()->GetLocalAddress());
// Clear connected_ flag on turnport to suppress the release of
@ -1284,7 +1466,11 @@ TEST_F(TurnPortTest, TestTurnTcpAllocateMismatch) {
EXPECT_EQ(first_addr, turn_port_->socket()->GetLocalAddress());
// Extra 2 round trips due to allocate mismatch.
EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 5, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_ready_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 5),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// Verifies that the new port has a different address now.
EXPECT_NE(first_addr, turn_port_->socket()->GetLocalAddress());
@ -1303,11 +1489,18 @@ TEST_F(TurnPortTest, TestRefreshRequestGetsErrorResponse) {
// When this succeeds, it will schedule a new RefreshRequest with the bad
// credential.
turn_port_->request_manager().FlushForTest(TURN_REFRESH_REQUEST);
EXPECT_TRUE_SIMULATED_WAIT(turn_refresh_success_, kSimulatedRtt, fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil([&] { return turn_refresh_success_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// Flush it again, it will receive a bad response.
turn_port_->request_manager().FlushForTest(TURN_REFRESH_REQUEST);
EXPECT_TRUE_SIMULATED_WAIT(!turn_refresh_success_, kSimulatedRtt,
fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil([&] { return !turn_refresh_success_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
EXPECT_FALSE(turn_port_->connected());
EXPECT_TRUE(CheckAllConnectionsFailedAndPruned());
EXPECT_FALSE(turn_port_->HasRequests());
@ -1326,8 +1519,12 @@ TEST_F(TurnPortTest, TestStopProcessingPacketsAfterClosed) {
ASSERT_TRUE(conn2 != NULL);
// Make sure conn2 is writable.
conn2->Ping(0);
EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn2->write_state(),
kSimulatedRtt * 2, fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil(
[&] { return conn2->write_state(); }, Eq(Connection::STATE_WRITABLE),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
turn_port_->CloseForTest();
SIMULATED_WAIT(false, kSimulatedRtt, fake_clock_);
@ -1367,8 +1564,12 @@ TEST_F(TurnPortTest, TestSocketCloseWillDestroyConnection) {
EXPECT_NE(nullptr, conn);
EXPECT_TRUE(!turn_port_->connections().empty());
turn_port_->socket()->NotifyClosedForTest(1);
EXPECT_TRUE_SIMULATED_WAIT(turn_port_->connections().empty(),
kConnectionDestructionDelay, fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil(
[&] { return turn_port_->connections().empty(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kConnectionDestructionDelay),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
}
// Test try-alternate-server feature.
@ -1511,8 +1712,11 @@ TEST_F(TurnPortTest, TestRefreshCreatePermissionRequest) {
Connection* conn = turn_port_->CreateConnection(udp_port_->Candidates()[0],
Port::ORIGIN_MESSAGE);
ASSERT_TRUE(conn != NULL);
EXPECT_TRUE_SIMULATED_WAIT(turn_create_permission_success_, kSimulatedRtt,
fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_create_permission_success_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
turn_create_permission_success_ = false;
// A create-permission-request should be pending.
// After the next create-permission-response is received, it will schedule
@ -1520,12 +1724,18 @@ TEST_F(TurnPortTest, TestRefreshCreatePermissionRequest) {
RelayCredentials bad_credentials("bad_user", "bad_pwd");
turn_port_->set_credentials(bad_credentials);
turn_port_->request_manager().FlushForTest(kAllRequestsForTest);
EXPECT_TRUE_SIMULATED_WAIT(turn_create_permission_success_, kSimulatedRtt,
fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_create_permission_success_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// Flush the requests again; the create-permission-request will fail.
turn_port_->request_manager().FlushForTest(kAllRequestsForTest);
EXPECT_TRUE_SIMULATED_WAIT(!turn_create_permission_success_, kSimulatedRtt,
fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return !turn_create_permission_success_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
EXPECT_TRUE(CheckConnectionFailedAndPruned(conn));
}
@ -1540,7 +1750,11 @@ TEST_F(TurnPortTest, TestChannelBindGetErrorResponse) {
ASSERT_TRUE(conn2 != nullptr);
conn1->Ping(0);
EXPECT_TRUE_SIMULATED_WAIT(conn1->writable(), kSimulatedRtt * 2, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return conn1->writable(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// Tell the TURN server to reject all bind requests from now on.
turn_server_.server()->set_reject_bind_requests(true);
@ -1548,8 +1762,12 @@ TEST_F(TurnPortTest, TestChannelBindGetErrorResponse) {
std::string data = "ABC";
conn1->Send(data.data(), data.length(), options);
EXPECT_TRUE_SIMULATED_WAIT(CheckConnectionFailedAndPruned(conn1),
kSimulatedRtt, fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil([&] { return CheckConnectionFailedAndPruned(conn1); },
IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// Verify that packets are allowed to be sent after a bind request error.
// They'll just use a send indication instead.
@ -1561,7 +1779,11 @@ TEST_F(TurnPortTest, TestChannelBindGetErrorResponse) {
rtc::Buffer(packet.payload().data(), packet.payload().size()));
});
conn1->Send(data.data(), data.length(), options);
EXPECT_TRUE_SIMULATED_WAIT(!udp_packets_.empty(), kSimulatedRtt, fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil([&] { return !udp_packets_.empty(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
conn2->DeregisterReceivedPacketCallback();
}
@ -1597,7 +1819,11 @@ TEST_F(TurnPortTest, TestTurnLocalIPv6AddressServerIPv4) {
CreateTurnPort(kLocalIPv6Addr, kTurnUsername, kTurnPassword,
kTurnUdpProtoAddr);
turn_port_->PrepareAddress();
ASSERT_TRUE_SIMULATED_WAIT(turn_error_, kSimulatedRtt, fake_clock_);
ASSERT_THAT(
webrtc::WaitUntil([&] { return turn_error_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
EXPECT_TRUE(turn_port_->Candidates().empty());
}
@ -1621,7 +1847,11 @@ TEST_F(TurnPortTest, TestCandidateAddressFamilyMatch) {
CreateTurnPort(kLocalIPv6Addr, kTurnUsername, kTurnPassword,
kTurnUdpIPv6ProtoAddr);
turn_port_->PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 2, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_ready_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
ASSERT_EQ(1U, turn_port_->Candidates().size());
// Create an IPv4 candidate. It will match the TURN candidate.
@ -1647,11 +1877,19 @@ TEST_F(TurnPortTest, TestConnectionFailedAndPrunedOnCreatePermissionFailure) {
turn_server_.server()->set_reject_private_addresses(true);
CreateTurnPort(kTurnUsername, kTurnPassword, kTurnTcpProtoAddr);
turn_port_->PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 3, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return turn_ready_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 3),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
CreateUdpPort(SocketAddress("10.0.0.10", 0));
udp_port_->PrepareAddress();
EXPECT_TRUE_SIMULATED_WAIT(udp_ready_, kSimulatedRtt, fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil([&] { return udp_ready_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// Create a connection.
TestConnectionWrapper conn(turn_port_->CreateConnection(
udp_port_->Candidates()[0], Port::ORIGIN_MESSAGE));
@ -1659,10 +1897,18 @@ TEST_F(TurnPortTest, TestConnectionFailedAndPrunedOnCreatePermissionFailure) {
// Asynchronously, CreatePermission request should be sent and fail, which
// will make the connection pruned and failed.
EXPECT_TRUE_SIMULATED_WAIT(CheckConnectionFailedAndPruned(conn.connection()),
kSimulatedRtt, fake_clock_);
EXPECT_TRUE_SIMULATED_WAIT(!turn_create_permission_success_, kSimulatedRtt,
fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil(
[&] { return CheckConnectionFailedAndPruned(conn.connection()); },
IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
EXPECT_THAT(webrtc::WaitUntil(
[&] { return !turn_create_permission_success_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// Check that the connection is not deleted asynchronously.
SIMULATED_WAIT(conn.connection() == nullptr, kConnectionDestructionDelay,
fake_clock_);
@ -1730,12 +1976,17 @@ TEST_F(TurnPortTest, TestResolverShutdown) {
CreateTurnPort(kLocalIPv6Addr, kTurnUsername, kTurnPassword,
ProtocolAddress(kTurnInvalidAddr, PROTO_UDP));
turn_port_->PrepareAddress();
ASSERT_TRUE_WAIT(turn_error_, kResolverTimeout);
ASSERT_THAT(webrtc::WaitUntil(
[&] { return turn_error_; }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kResolverTimeout)}),
webrtc::IsRtcOk());
EXPECT_TRUE(turn_port_->Candidates().empty());
turn_port_.reset();
rtc::Thread::Current()->PostTask([this] { test_finish_ = true; });
// Waiting for above message to be processed.
ASSERT_TRUE_SIMULATED_WAIT(test_finish_, 1, fake_clock_);
ASSERT_THAT(webrtc::WaitUntil([&] { return test_finish_; }, IsTrue(),
{.clock = &fake_clock_}),
webrtc::IsRtcOk());
EXPECT_EQ(last_fd_count, GetFDCount());
}
#endif
@ -1924,9 +2175,12 @@ TEST_F(TurnPortTest, TestTurnDangerousAlternateServer) {
turn_port_->PrepareAddress();
// This should result in an error event.
EXPECT_TRUE_SIMULATED_WAIT(error_event_.error_code != 0,
TimeToGetAlternateTurnCandidate(protocol_type),
fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil([&] { return error_event_.error_code; }, Ne(0),
{.timeout = webrtc::TimeDelta::Millis(
TimeToGetAlternateTurnCandidate(protocol_type)),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// but should NOT result in the port turning ready, and no candidates
// should be gathered.
EXPECT_FALSE(turn_ready_);

File diff suppressed because it is too large Load Diff

View File

@ -28,6 +28,7 @@
#include "api/crypto/crypto_options.h"
#include "api/dtls_transport_interface.h"
#include "api/scoped_refptr.h"
#include "api/test/rtc_error_matchers.h"
#include "api/units/time_delta.h"
#include "p2p/base/fake_ice_transport.h"
#include "p2p/base/packet_transport_internal.h"
@ -39,7 +40,6 @@
#include "rtc_base/checks.h"
#include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/fake_clock.h"
#include "rtc_base/gunit.h"
#include "rtc_base/logging.h"
#include "rtc_base/network/received_packet.h"
#include "rtc_base/rtc_certificate.h"
@ -48,7 +48,9 @@
#include "rtc_base/ssl_stream_adapter.h"
#include "rtc_base/third_party/sigslot/sigslot.h"
#include "rtc_base/thread.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/wait_until.h"
#define MAYBE_SKIP_TEST(feature) \
if (!(rtc::SSLStreamAdapter::feature())) { \
@ -58,6 +60,9 @@
namespace cricket {
using ::testing::Eq;
using ::testing::IsTrue;
static const size_t kPacketNumOffset = 8;
static const size_t kPacketHeaderLen = 12;
static const int kFakePacketId = 0x1234;
@ -380,9 +385,15 @@ class DtlsTransportTestBase {
Negotiate(client1_server);
EXPECT_TRUE(client1_.Connect(&client2_, false));
EXPECT_TRUE_SIMULATED_WAIT(client1_.dtls_transport()->writable() &&
client2_.dtls_transport()->writable(),
kTimeout, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] {
return client1_.dtls_transport()->writable() &&
client2_.dtls_transport()->writable();
},
IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
if (!client1_.dtls_transport()->writable() ||
!client2_.dtls_transport()->writable())
return false;
@ -432,8 +443,11 @@ class DtlsTransportTestBase {
RTC_LOG(LS_INFO) << "Expect packets, size=" << size;
client2_.ExpectPackets(size);
client1_.SendPackets(size, count, srtp);
EXPECT_EQ_SIMULATED_WAIT(count, client2_.NumPacketsReceived(), kTimeout,
fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return client2_.NumPacketsReceived(); }, Eq(count),
{.timeout = webrtc::TimeDelta::Millis(kTimeout),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
}
protected:
@ -630,9 +644,15 @@ class DtlsTransportVersionTest
EXPECT_TRUE(client1_.Connect(&client2_, false));
EXPECT_TRUE_SIMULATED_WAIT(client1_.dtls_transport()->writable() &&
client2_.dtls_transport()->writable(),
kTimeout, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] {
return client1_.dtls_transport()->writable() &&
client2_.dtls_transport()->writable();
},
IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
client1_.fake_ice_transport()->set_packet_send_filter(nullptr);
client2_.fake_ice_transport()->set_packet_send_filter(nullptr);
@ -842,9 +862,15 @@ TEST_F(DtlsTransportTest, TestRenegotiateBeforeConnect) {
Negotiate();
Negotiate();
EXPECT_TRUE(client1_.Connect(&client2_, false));
EXPECT_TRUE_SIMULATED_WAIT(client1_.dtls_transport()->writable() &&
client2_.dtls_transport()->writable(),
kTimeout, fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] {
return client1_.dtls_transport()->writable() &&
client2_.dtls_transport()->writable();
},
IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
TestTransfer(1000, 100, true);
}
@ -905,11 +931,18 @@ TEST_F(DtlsTransportTest, TestRetransmissionSchedule) {
// Make client2_ writable, but not client1_.
// This means client1_ will send DTLS client hellos but get no response.
EXPECT_TRUE(client2_.Connect(&client1_, true));
EXPECT_TRUE_SIMULATED_WAIT(client2_.fake_ice_transport()->writable(),
kTimeout, fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil(
[&] { return client2_.fake_ice_transport()->writable(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// Wait for the first client hello to be sent.
EXPECT_EQ_WAIT(1, client1_.received_dtls_client_hellos(), kTimeout);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return client1_.received_dtls_client_hellos(); }, Eq(1),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
EXPECT_FALSE(client1_.fake_ice_transport()->writable());
static int timeout_schedule_ms[] = {50, 100, 200, 400, 800, 1600,
@ -992,29 +1025,49 @@ class DtlsEventOrderingTest
break;
case CALLER_WRITABLE:
EXPECT_TRUE(client1_.Connect(&client2_, true));
EXPECT_TRUE_SIMULATED_WAIT(client1_.fake_ice_transport()->writable(),
kTimeout, fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil(
[&] { return client1_.fake_ice_transport()->writable(); },
IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
break;
case CALLER_RECEIVES_CLIENTHELLO:
// Sanity check that a ClientHello hasn't already been received.
EXPECT_EQ(0, client1_.received_dtls_client_hellos());
// Making client2_ writable will cause it to send the ClientHello.
EXPECT_TRUE(client2_.Connect(&client1_, true));
EXPECT_TRUE_SIMULATED_WAIT(client2_.fake_ice_transport()->writable(),
kTimeout, fake_clock_);
EXPECT_EQ_SIMULATED_WAIT(1, client1_.received_dtls_client_hellos(),
kTimeout, fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil(
[&] { return client2_.fake_ice_transport()->writable(); },
IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
EXPECT_THAT(
webrtc::WaitUntil(
[&] { return client1_.received_dtls_client_hellos(); }, Eq(1),
{.timeout = webrtc::TimeDelta::Millis(kTimeout),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
break;
case HANDSHAKE_FINISHES:
// Sanity check that the handshake hasn't already finished.
EXPECT_FALSE(client1_.dtls_transport()->IsDtlsConnected() ||
client1_.dtls_transport()->dtls_state() ==
webrtc::DtlsTransportState::kFailed);
EXPECT_TRUE_SIMULATED_WAIT(
client1_.dtls_transport()->IsDtlsConnected() ||
client1_.dtls_transport()->dtls_state() ==
webrtc::DtlsTransportState::kFailed,
kTimeout, fake_clock_);
EXPECT_THAT(
webrtc::WaitUntil(
[&] {
return client1_.dtls_transport()->IsDtlsConnected() ||
client1_.dtls_transport()->dtls_state() ==
webrtc::DtlsTransportState::kFailed;
},
IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
break;
}
}
@ -1022,12 +1075,18 @@ class DtlsEventOrderingTest
webrtc::DtlsTransportState expected_final_state =
valid_fingerprint ? webrtc::DtlsTransportState::kConnected
: webrtc::DtlsTransportState::kFailed;
EXPECT_EQ_SIMULATED_WAIT(expected_final_state,
client1_.dtls_transport()->dtls_state(), kTimeout,
fake_clock_);
EXPECT_EQ_SIMULATED_WAIT(expected_final_state,
client2_.dtls_transport()->dtls_state(), kTimeout,
fake_clock_);
EXPECT_THAT(webrtc::WaitUntil(
[&] { return client1_.dtls_transport()->dtls_state(); },
Eq(expected_final_state),
{.timeout = webrtc::TimeDelta::Millis(kTimeout),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
EXPECT_THAT(webrtc::WaitUntil(
[&] { return client2_.dtls_transport()->dtls_state(); },
Eq(expected_final_state),
{.timeout = webrtc::TimeDelta::Millis(kTimeout),
.clock = &fake_clock_}),
webrtc::IsRtcOk());
// Transports should be writable iff there was a valid fingerprint.
EXPECT_EQ(valid_fingerprint, client1_.dtls_transport()->writable());