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:
parent
d9593037dd
commit
b0038dd14a
@ -1206,6 +1206,7 @@ if (rtc_include_tests) {
|
|||||||
":p2p_server_utils",
|
":p2p_server_utils",
|
||||||
":p2p_test_utils",
|
":p2p_test_utils",
|
||||||
":p2p_transport_channel",
|
":p2p_transport_channel",
|
||||||
|
":p2p_transport_channel_ice_field_trials",
|
||||||
":packet_transport_internal",
|
":packet_transport_internal",
|
||||||
":port",
|
":port",
|
||||||
":port_allocator",
|
":port_allocator",
|
||||||
@ -1230,6 +1231,8 @@ if (rtc_include_tests) {
|
|||||||
"../api:libjingle_peerconnection_api",
|
"../api:libjingle_peerconnection_api",
|
||||||
"../api:mock_async_dns_resolver",
|
"../api:mock_async_dns_resolver",
|
||||||
"../api:packet_socket_factory",
|
"../api:packet_socket_factory",
|
||||||
|
"../api:rtc_error",
|
||||||
|
"../api:rtc_error_matchers",
|
||||||
"../api:scoped_refptr",
|
"../api:scoped_refptr",
|
||||||
"../api/crypto:options",
|
"../api/crypto:options",
|
||||||
"../api/task_queue",
|
"../api/task_queue",
|
||||||
@ -1265,6 +1268,7 @@ if (rtc_include_tests) {
|
|||||||
"../rtc_base:socket_server",
|
"../rtc_base:socket_server",
|
||||||
"../rtc_base:ssl",
|
"../rtc_base:ssl",
|
||||||
"../rtc_base:ssl_adapter",
|
"../rtc_base:ssl_adapter",
|
||||||
|
"../rtc_base:stream",
|
||||||
"../rtc_base:stringutils",
|
"../rtc_base:stringutils",
|
||||||
"../rtc_base:testclient",
|
"../rtc_base:testclient",
|
||||||
"../rtc_base:threading",
|
"../rtc_base:threading",
|
||||||
@ -1277,6 +1281,7 @@ if (rtc_include_tests) {
|
|||||||
"../test:rtc_expect_death",
|
"../test:rtc_expect_death",
|
||||||
"../test:scoped_key_value_config",
|
"../test:scoped_key_value_config",
|
||||||
"../test:test_support",
|
"../test:test_support",
|
||||||
|
"../test:wait_until",
|
||||||
"//testing/gtest",
|
"//testing/gtest",
|
||||||
"//third_party/abseil-cpp/absl/algorithm:container",
|
"//third_party/abseil-cpp/absl/algorithm:container",
|
||||||
"//third_party/abseil-cpp/absl/functional:any_invocable",
|
"//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
@ -14,21 +14,28 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "api/array_view.h"
|
||||||
#include "api/task_queue/pending_task_safety_flag.h"
|
#include "api/task_queue/pending_task_safety_flag.h"
|
||||||
#include "api/task_queue/task_queue_base.h"
|
#include "api/task_queue/task_queue_base.h"
|
||||||
|
#include "api/test/rtc_error_matchers.h"
|
||||||
#include "api/units/time_delta.h"
|
#include "api/units/time_delta.h"
|
||||||
#include "rtc_base/crypto_random.h"
|
#include "rtc_base/crypto_random.h"
|
||||||
#include "rtc_base/gunit.h"
|
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "rtc_base/memory_stream.h"
|
#include "rtc_base/memory_stream.h"
|
||||||
|
#include "rtc_base/stream.h"
|
||||||
|
#include "rtc_base/thread.h"
|
||||||
#include "rtc_base/time_utils.h"
|
#include "rtc_base/time_utils.h"
|
||||||
|
#include "test/gmock.h"
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
|
#include "test/wait_until.h"
|
||||||
|
|
||||||
using ::cricket::PseudoTcp;
|
using ::cricket::PseudoTcp;
|
||||||
|
using ::testing::IsTrue;
|
||||||
using ::webrtc::ScopedTaskSafety;
|
using ::webrtc::ScopedTaskSafety;
|
||||||
using ::webrtc::TaskQueueBase;
|
using ::webrtc::TaskQueueBase;
|
||||||
using ::webrtc::TimeDelta;
|
using ::webrtc::TimeDelta;
|
||||||
@ -243,10 +250,16 @@ class PseudoTcpTest : public PseudoTcpTestBase {
|
|||||||
// Connect and wait until connected.
|
// Connect and wait until connected.
|
||||||
start = rtc::Time32();
|
start = rtc::Time32();
|
||||||
EXPECT_EQ(0, Connect());
|
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
|
// Sending will start from OnTcpWriteable and complete when all data has
|
||||||
// been received.
|
// 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;
|
elapsed = rtc::Time32() - start;
|
||||||
recv_stream_.GetSize(&received);
|
recv_stream_.GetSize(&received);
|
||||||
// Ensure we closed down OK and we got the right data.
|
// Ensure we closed down OK and we got the right data.
|
||||||
@ -366,10 +379,16 @@ class PseudoTcpTestPingPong : public PseudoTcpTestBase {
|
|||||||
// Connect and wait until connected.
|
// Connect and wait until connected.
|
||||||
start = rtc::Time32();
|
start = rtc::Time32();
|
||||||
EXPECT_EQ(0, Connect());
|
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
|
// Sending will start from OnTcpWriteable and stop when the required
|
||||||
// number of iterations have completed.
|
// 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);
|
elapsed = rtc::TimeSince(start);
|
||||||
RTC_LOG(LS_INFO) << "Performed " << iterations << " pings in " << elapsed
|
RTC_LOG(LS_INFO) << "Performed " << iterations << " pings in " << elapsed
|
||||||
<< " ms";
|
<< " ms";
|
||||||
@ -488,10 +507,16 @@ class PseudoTcpTestReceiveWindow : public PseudoTcpTestBase {
|
|||||||
|
|
||||||
// Connect and wait until connected.
|
// Connect and wait until connected.
|
||||||
EXPECT_EQ(0, Connect());
|
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(); });
|
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, send_position_.size());
|
||||||
ASSERT_EQ(2u, recv_position_.size());
|
ASSERT_EQ(2u, recv_position_.size());
|
||||||
|
|||||||
@ -10,21 +10,45 @@
|
|||||||
|
|
||||||
#include "p2p/base/stun_port.h"
|
#include "p2p/base/stun_port.h"
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
#include <memory>
|
#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/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/basic_packet_socket_factory.h"
|
||||||
#include "p2p/base/mock_dns_resolving_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 "p2p/base/test_stun_server.h"
|
||||||
#include "rtc_base/async_packet_socket.h"
|
#include "rtc_base/async_packet_socket.h"
|
||||||
#include "rtc_base/crypto_random.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/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/received_packet.h"
|
||||||
|
#include "rtc_base/network_constants.h"
|
||||||
|
#include "rtc_base/socket.h"
|
||||||
#include "rtc_base/socket_address.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 "rtc_base/virtual_socket_server.h"
|
||||||
#include "test/gmock.h"
|
#include "test/gmock.h"
|
||||||
|
#include "test/gtest.h"
|
||||||
#include "test/scoped_key_value_config.h"
|
#include "test/scoped_key_value_config.h"
|
||||||
|
#include "test/wait_until.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@ -32,6 +56,8 @@ using cricket::ServerAddresses;
|
|||||||
using rtc::SocketAddress;
|
using rtc::SocketAddress;
|
||||||
using ::testing::_;
|
using ::testing::_;
|
||||||
using ::testing::DoAll;
|
using ::testing::DoAll;
|
||||||
|
using ::testing::Eq;
|
||||||
|
using ::testing::IsTrue;
|
||||||
using ::testing::Return;
|
using ::testing::Return;
|
||||||
using ::testing::ReturnPointee;
|
using ::testing::ReturnPointee;
|
||||||
using ::testing::SetArgPointee;
|
using ::testing::SetArgPointee;
|
||||||
@ -286,7 +312,11 @@ TEST_F(StunPortTest, TestCreateUdpPort) {
|
|||||||
TEST_F(StunPortTest, TestPrepareAddress) {
|
TEST_F(StunPortTest, TestPrepareAddress) {
|
||||||
CreateStunPort(kStunAddr1);
|
CreateStunPort(kStunAddr1);
|
||||||
PrepareAddress();
|
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());
|
ASSERT_EQ(1U, port()->Candidates().size());
|
||||||
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
|
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
|
||||||
std::string expected_server_url = "stun:127.0.0.1:5000";
|
std::string expected_server_url = "stun:127.0.0.1:5000";
|
||||||
@ -297,12 +327,19 @@ TEST_F(StunPortTest, TestPrepareAddress) {
|
|||||||
TEST_F(StunPortTest, TestPrepareAddressFail) {
|
TEST_F(StunPortTest, TestPrepareAddressFail) {
|
||||||
CreateStunPort(kBadAddr);
|
CreateStunPort(kBadAddr);
|
||||||
PrepareAddress();
|
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_TRUE(error());
|
||||||
EXPECT_EQ(0U, port()->Candidates().size());
|
EXPECT_EQ(0U, port()->Candidates().size());
|
||||||
EXPECT_EQ_SIMULATED_WAIT(error_event_.error_code,
|
EXPECT_THAT(
|
||||||
cricket::STUN_ERROR_SERVER_NOT_REACHABLE, kTimeoutMs,
|
webrtc::WaitUntil([&] { return error_event_.error_code; },
|
||||||
fake_clock);
|
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_.error_text.find('.'), std::string::npos);
|
||||||
EXPECT_NE(error_event_.address.find(kLocalAddr.HostAsSensitiveURIString()),
|
EXPECT_NE(error_event_.address.find(kLocalAddr.HostAsSensitiveURIString()),
|
||||||
std::string::npos);
|
std::string::npos);
|
||||||
@ -315,7 +352,11 @@ TEST_F(StunPortTest, TestPrepareAddressFail) {
|
|||||||
TEST_F(StunPortTest, TestServerAddressFamilyMismatch) {
|
TEST_F(StunPortTest, TestServerAddressFamilyMismatch) {
|
||||||
CreateStunPort(kIPv6StunAddr1);
|
CreateStunPort(kIPv6StunAddr1);
|
||||||
PrepareAddress();
|
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_TRUE(error());
|
||||||
EXPECT_EQ(0U, port()->Candidates().size());
|
EXPECT_EQ(0U, port()->Candidates().size());
|
||||||
EXPECT_EQ(0, error_event_.error_code);
|
EXPECT_EQ(0, error_event_.error_code);
|
||||||
@ -356,7 +397,11 @@ TEST_F(StunPortWithMockDnsResolverTest, TestPrepareAddressHostname) {
|
|||||||
});
|
});
|
||||||
CreateStunPort(kValidHostnameAddr);
|
CreateStunPort(kValidHostnameAddr);
|
||||||
PrepareAddress();
|
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());
|
ASSERT_EQ(1U, port()->Candidates().size());
|
||||||
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
|
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
|
||||||
EXPECT_EQ(kStunCandidatePriority, port()->Candidates()[0].priority());
|
EXPECT_EQ(kStunCandidatePriority, port()->Candidates()[0].priority());
|
||||||
@ -381,7 +426,11 @@ TEST_F(StunPortWithMockDnsResolverTest,
|
|||||||
});
|
});
|
||||||
CreateStunPort(kValidHostnameAddr);
|
CreateStunPort(kValidHostnameAddr);
|
||||||
PrepareAddress();
|
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());
|
ASSERT_EQ(1U, port()->Candidates().size());
|
||||||
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
|
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
|
||||||
EXPECT_EQ(kStunCandidatePriority + (cricket::kMaxTurnServers << 8),
|
EXPECT_EQ(kStunCandidatePriority + (cricket::kMaxTurnServers << 8),
|
||||||
@ -392,11 +441,17 @@ TEST_F(StunPortWithMockDnsResolverTest,
|
|||||||
TEST_F(StunPortTestWithRealClock, TestPrepareAddressHostnameFail) {
|
TEST_F(StunPortTestWithRealClock, TestPrepareAddressHostnameFail) {
|
||||||
CreateStunPort(kBadHostnameAddr);
|
CreateStunPort(kBadHostnameAddr);
|
||||||
PrepareAddress();
|
PrepareAddress();
|
||||||
EXPECT_TRUE_WAIT(done(), kTimeoutMs);
|
EXPECT_THAT(
|
||||||
|
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
|
||||||
|
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs)}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
EXPECT_TRUE(error());
|
EXPECT_TRUE(error());
|
||||||
EXPECT_EQ(0U, port()->Candidates().size());
|
EXPECT_EQ(0U, port()->Candidates().size());
|
||||||
EXPECT_EQ_WAIT(error_event_.error_code,
|
EXPECT_THAT(
|
||||||
cricket::STUN_ERROR_SERVER_NOT_REACHABLE, kTimeoutMs);
|
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
|
// This test verifies keepalive response messages don't result in
|
||||||
@ -405,7 +460,11 @@ TEST_F(StunPortTest, TestKeepAliveResponse) {
|
|||||||
SetKeepaliveDelay(500); // 500ms of keepalive delay.
|
SetKeepaliveDelay(500); // 500ms of keepalive delay.
|
||||||
CreateStunPort(kStunAddr1);
|
CreateStunPort(kStunAddr1);
|
||||||
PrepareAddress();
|
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());
|
ASSERT_EQ(1U, port()->Candidates().size());
|
||||||
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
|
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
|
||||||
SIMULATED_WAIT(false, 1000, fake_clock);
|
SIMULATED_WAIT(false, 1000, fake_clock);
|
||||||
@ -416,7 +475,11 @@ TEST_F(StunPortTest, TestKeepAliveResponse) {
|
|||||||
TEST_F(StunPortTest, TestSharedSocketPrepareAddress) {
|
TEST_F(StunPortTest, TestSharedSocketPrepareAddress) {
|
||||||
CreateSharedUdpPort(kStunAddr1, nullptr);
|
CreateSharedUdpPort(kStunAddr1, nullptr);
|
||||||
PrepareAddress();
|
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());
|
ASSERT_EQ(1U, port()->Candidates().size());
|
||||||
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
|
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
|
||||||
}
|
}
|
||||||
@ -428,7 +491,10 @@ TEST_F(StunPortTestWithRealClock,
|
|||||||
TestSharedSocketPrepareAddressInvalidHostname) {
|
TestSharedSocketPrepareAddressInvalidHostname) {
|
||||||
CreateSharedUdpPort(kBadHostnameAddr, nullptr);
|
CreateSharedUdpPort(kBadHostnameAddr, nullptr);
|
||||||
PrepareAddress();
|
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());
|
ASSERT_EQ(1U, port()->Candidates().size());
|
||||||
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
|
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
|
||||||
|
|
||||||
@ -444,7 +510,11 @@ TEST_F(StunPortTestWithRealClock,
|
|||||||
TEST_F(StunPortTest, TestStunCandidateDiscardedWithMdnsObfuscationNotEnabled) {
|
TEST_F(StunPortTest, TestStunCandidateDiscardedWithMdnsObfuscationNotEnabled) {
|
||||||
CreateSharedUdpPort(kStunAddr1, nullptr);
|
CreateSharedUdpPort(kStunAddr1, nullptr);
|
||||||
PrepareAddress();
|
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());
|
ASSERT_EQ(1U, port()->Candidates().size());
|
||||||
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
|
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
|
||||||
EXPECT_TRUE(port()->Candidates()[0].is_local());
|
EXPECT_TRUE(port()->Candidates()[0].is_local());
|
||||||
@ -456,7 +526,11 @@ TEST_F(StunPortTest, TestStunCandidateGeneratedWithMdnsObfuscationEnabled) {
|
|||||||
EnableMdnsObfuscation();
|
EnableMdnsObfuscation();
|
||||||
CreateSharedUdpPort(kStunAddr1, nullptr);
|
CreateSharedUdpPort(kStunAddr1, nullptr);
|
||||||
PrepareAddress();
|
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());
|
ASSERT_EQ(2U, port()->Candidates().size());
|
||||||
|
|
||||||
// The addresses of the candidates are both equal to kLocalAddr.
|
// The addresses of the candidates are both equal to kLocalAddr.
|
||||||
@ -483,7 +557,11 @@ TEST_F(StunPortTest, TestNoDuplicatedAddressWithTwoStunServers) {
|
|||||||
CreateStunPort(stun_servers);
|
CreateStunPort(stun_servers);
|
||||||
EXPECT_EQ(IceCandidateType::kSrflx, port()->Type());
|
EXPECT_EQ(IceCandidateType::kSrflx, port()->Type());
|
||||||
PrepareAddress();
|
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(1U, port()->Candidates().size());
|
||||||
EXPECT_EQ(port()->Candidates()[0].relay_protocol(), "");
|
EXPECT_EQ(port()->Candidates()[0].relay_protocol(), "");
|
||||||
}
|
}
|
||||||
@ -497,11 +575,18 @@ TEST_F(StunPortTest, TestMultipleStunServersWithBadServer) {
|
|||||||
CreateStunPort(stun_servers);
|
CreateStunPort(stun_servers);
|
||||||
EXPECT_EQ(IceCandidateType::kSrflx, port()->Type());
|
EXPECT_EQ(IceCandidateType::kSrflx, port()->Type());
|
||||||
PrepareAddress();
|
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(1U, port()->Candidates().size());
|
||||||
std::string server_url = "stun:" + kBadAddr.ToString();
|
std::string server_url = "stun:" + kBadAddr.ToString();
|
||||||
ASSERT_EQ_SIMULATED_WAIT(error_event_.url, server_url, kTimeoutMs,
|
ASSERT_THAT(
|
||||||
fake_clock);
|
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
|
// Test that two candidates are allocated if the two STUN servers return
|
||||||
@ -518,7 +603,11 @@ TEST_F(StunPortTest, TestTwoCandidatesWithTwoStunServersAcrossNat) {
|
|||||||
CreateStunPort(stun_servers);
|
CreateStunPort(stun_servers);
|
||||||
EXPECT_EQ(IceCandidateType::kSrflx, port()->Type());
|
EXPECT_EQ(IceCandidateType::kSrflx, port()->Type());
|
||||||
PrepareAddress();
|
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(2U, port()->Candidates().size());
|
||||||
EXPECT_EQ(port()->Candidates()[0].relay_protocol(), "");
|
EXPECT_EQ(port()->Candidates()[0].relay_protocol(), "");
|
||||||
EXPECT_EQ(port()->Candidates()[1].relay_protocol(), "");
|
EXPECT_EQ(port()->Candidates()[1].relay_protocol(), "");
|
||||||
@ -567,9 +656,16 @@ TEST_F(StunPortTest, TestStunBindingRequestShortLifetime) {
|
|||||||
SetKeepaliveLifetime(100);
|
SetKeepaliveLifetime(100);
|
||||||
CreateStunPort(kStunAddr1);
|
CreateStunPort(kStunAddr1);
|
||||||
PrepareAddress();
|
PrepareAddress();
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
|
EXPECT_THAT(
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(!HasPendingRequest(cricket::STUN_BINDING_REQUEST),
|
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
|
||||||
2000, fake_clock);
|
{.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.
|
// Test that by default, the STUN binding requests will last for a long time.
|
||||||
@ -577,9 +673,16 @@ TEST_F(StunPortTest, TestStunBindingRequestLongLifetime) {
|
|||||||
SetKeepaliveDelay(101);
|
SetKeepaliveDelay(101);
|
||||||
CreateStunPort(kStunAddr1);
|
CreateStunPort(kStunAddr1);
|
||||||
PrepareAddress();
|
PrepareAddress();
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
|
EXPECT_THAT(
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(HasPendingRequest(cricket::STUN_BINDING_REQUEST),
|
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
|
||||||
1000, fake_clock);
|
{.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 {
|
class MockAsyncPacketSocket : public rtc::AsyncPacketSocket {
|
||||||
@ -621,10 +724,9 @@ TEST_F(StunPortTest, TestStunPacketsHaveDscpPacketOption) {
|
|||||||
EXPECT_CALL(*socket, SetOption(_, _)).WillRepeatedly(Return(0));
|
EXPECT_CALL(*socket, SetOption(_, _)).WillRepeatedly(Return(0));
|
||||||
|
|
||||||
// If DSCP is not set on the socket, stun packets should have no value.
|
// If DSCP is not set on the socket, stun packets should have no value.
|
||||||
EXPECT_CALL(*socket,
|
EXPECT_CALL(*socket, SendTo(_, _, _,
|
||||||
SendTo(_, _, _,
|
::testing::Field(&rtc::PacketOptions::dscp,
|
||||||
::testing::Field(&rtc::PacketOptions::dscp,
|
Eq(rtc::DSCP_NO_CHANGE))))
|
||||||
::testing::Eq(rtc::DSCP_NO_CHANGE))))
|
|
||||||
.WillOnce(Return(100));
|
.WillOnce(Return(100));
|
||||||
PrepareAddress();
|
PrepareAddress();
|
||||||
|
|
||||||
@ -632,9 +734,13 @@ TEST_F(StunPortTest, TestStunPacketsHaveDscpPacketOption) {
|
|||||||
port()->SetOption(rtc::Socket::OPT_DSCP, rtc::DSCP_AF41);
|
port()->SetOption(rtc::Socket::OPT_DSCP, rtc::DSCP_AF41);
|
||||||
EXPECT_CALL(*socket, SendTo(_, _, _,
|
EXPECT_CALL(*socket, SendTo(_, _, _,
|
||||||
::testing::Field(&rtc::PacketOptions::dscp,
|
::testing::Field(&rtc::PacketOptions::dscp,
|
||||||
::testing::Eq(rtc::DSCP_AF41))))
|
Eq(rtc::DSCP_AF41))))
|
||||||
.WillRepeatedly(Return(100));
|
.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 {
|
class StunIPv6PortTestBase : public StunPortTestBase {
|
||||||
@ -661,7 +767,11 @@ class StunIPv6PortTest : public FakeClockBase, public StunIPv6PortTestBase {};
|
|||||||
TEST_F(StunIPv6PortTest, TestPrepareAddress) {
|
TEST_F(StunIPv6PortTest, TestPrepareAddress) {
|
||||||
CreateStunPort(kIPv6StunAddr1);
|
CreateStunPort(kIPv6StunAddr1);
|
||||||
PrepareAddress();
|
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());
|
ASSERT_EQ(1U, port()->Candidates().size());
|
||||||
EXPECT_TRUE(kIPv6LocalAddr.EqualIPs(port()->Candidates()[0].address()));
|
EXPECT_TRUE(kIPv6LocalAddr.EqualIPs(port()->Candidates()[0].address()));
|
||||||
std::string expected_server_url = "stun:::1:5000";
|
std::string expected_server_url = "stun:::1:5000";
|
||||||
@ -672,12 +782,19 @@ TEST_F(StunIPv6PortTest, TestPrepareAddress) {
|
|||||||
TEST_F(StunIPv6PortTest, TestPrepareAddressFail) {
|
TEST_F(StunIPv6PortTest, TestPrepareAddressFail) {
|
||||||
CreateStunPort(kIPv6BadAddr);
|
CreateStunPort(kIPv6BadAddr);
|
||||||
PrepareAddress();
|
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_TRUE(error());
|
||||||
EXPECT_EQ(0U, port()->Candidates().size());
|
EXPECT_EQ(0U, port()->Candidates().size());
|
||||||
EXPECT_EQ_SIMULATED_WAIT(error_event_.error_code,
|
EXPECT_THAT(
|
||||||
cricket::STUN_ERROR_SERVER_NOT_REACHABLE, kTimeoutMs,
|
webrtc::WaitUntil([&] { return error_event_.error_code; },
|
||||||
fake_clock);
|
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_.error_text.find('.'), std::string::npos);
|
||||||
EXPECT_NE(
|
EXPECT_NE(
|
||||||
error_event_.address.find(kIPv6LocalAddr.HostAsSensitiveURIString()),
|
error_event_.address.find(kIPv6LocalAddr.HostAsSensitiveURIString()),
|
||||||
@ -691,7 +808,11 @@ TEST_F(StunIPv6PortTest, TestPrepareAddressFail) {
|
|||||||
TEST_F(StunIPv6PortTest, TestServerAddressFamilyMismatch) {
|
TEST_F(StunIPv6PortTest, TestServerAddressFamilyMismatch) {
|
||||||
CreateStunPort(kStunAddr1);
|
CreateStunPort(kStunAddr1);
|
||||||
PrepareAddress();
|
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_TRUE(error());
|
||||||
EXPECT_EQ(0U, port()->Candidates().size());
|
EXPECT_EQ(0U, port()->Candidates().size());
|
||||||
EXPECT_EQ(0, error_event_.error_code);
|
EXPECT_EQ(0, error_event_.error_code);
|
||||||
@ -701,11 +822,17 @@ TEST_F(StunIPv6PortTest, TestServerAddressFamilyMismatch) {
|
|||||||
TEST_F(StunIPv6PortTestWithRealClock, TestPrepareAddressHostnameFail) {
|
TEST_F(StunIPv6PortTestWithRealClock, TestPrepareAddressHostnameFail) {
|
||||||
CreateStunPort(kBadHostnameAddr);
|
CreateStunPort(kBadHostnameAddr);
|
||||||
PrepareAddress();
|
PrepareAddress();
|
||||||
EXPECT_TRUE_WAIT(done(), kTimeoutMs);
|
EXPECT_THAT(
|
||||||
|
webrtc::WaitUntil([&] { return done(); }, IsTrue(),
|
||||||
|
{.timeout = webrtc::TimeDelta::Millis(kTimeoutMs)}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
EXPECT_TRUE(error());
|
EXPECT_TRUE(error());
|
||||||
EXPECT_EQ(0U, port()->Candidates().size());
|
EXPECT_EQ(0U, port()->Candidates().size());
|
||||||
EXPECT_EQ_WAIT(error_event_.error_code,
|
EXPECT_THAT(
|
||||||
cricket::STUN_ERROR_SERVER_NOT_REACHABLE, kTimeoutMs);
|
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 {
|
class StunIPv6PortTestWithMockDnsResolver : public StunIPv6PortTest {
|
||||||
@ -745,7 +872,11 @@ TEST_F(StunIPv6PortTestWithMockDnsResolver, TestPrepareAddressHostname) {
|
|||||||
});
|
});
|
||||||
CreateStunPort(kValidHostnameAddr);
|
CreateStunPort(kValidHostnameAddr);
|
||||||
PrepareAddress();
|
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());
|
ASSERT_EQ(1U, port()->Candidates().size());
|
||||||
EXPECT_TRUE(kIPv6LocalAddr.EqualIPs(port()->Candidates()[0].address()));
|
EXPECT_TRUE(kIPv6LocalAddr.EqualIPs(port()->Candidates()[0].address()));
|
||||||
EXPECT_EQ(kIPv6StunCandidatePriority, port()->Candidates()[0].priority());
|
EXPECT_EQ(kIPv6StunCandidatePriority, port()->Candidates()[0].priority());
|
||||||
@ -772,7 +903,11 @@ TEST_F(StunIPv6PortTestWithMockDnsResolver,
|
|||||||
});
|
});
|
||||||
CreateStunPort(kValidHostnameAddr, &field_trials);
|
CreateStunPort(kValidHostnameAddr, &field_trials);
|
||||||
PrepareAddress();
|
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());
|
ASSERT_EQ(1U, port()->Candidates().size());
|
||||||
EXPECT_TRUE(kIPv6LocalAddr.EqualIPs(port()->Candidates()[0].address()));
|
EXPECT_TRUE(kIPv6LocalAddr.EqualIPs(port()->Candidates()[0].address()));
|
||||||
EXPECT_EQ(kIPv6StunCandidatePriority + (cricket::kMaxTurnServers << 8),
|
EXPECT_EQ(kIPv6StunCandidatePriority + (cricket::kMaxTurnServers << 8),
|
||||||
|
|||||||
@ -10,18 +10,28 @@
|
|||||||
|
|
||||||
#include "p2p/base/stun_request.h"
|
#include "p2p/base/stun_request.h"
|
||||||
|
|
||||||
#include <utility>
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <memory>
|
||||||
#include <vector>
|
#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/fake_clock.h"
|
||||||
#include "rtc_base/gunit.h"
|
#include "rtc_base/gunit.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
|
#include "rtc_base/thread.h"
|
||||||
#include "rtc_base/time_utils.h"
|
#include "rtc_base/time_utils.h"
|
||||||
|
#include "test/gmock.h"
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
|
#include "test/wait_until.h"
|
||||||
|
|
||||||
namespace cricket {
|
namespace cricket {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using ::testing::Ne;
|
||||||
|
|
||||||
std::unique_ptr<StunMessage> CreateStunMessage(
|
std::unique_ptr<StunMessage> CreateStunMessage(
|
||||||
StunMessageType type,
|
StunMessageType type,
|
||||||
const StunMessage* req = nullptr) {
|
const StunMessage* req = nullptr) {
|
||||||
@ -149,8 +159,11 @@ TEST_F(StunRequestTest, TestBackoff) {
|
|||||||
int64_t start = rtc::TimeMillis();
|
int64_t start = rtc::TimeMillis();
|
||||||
manager_.Send(request);
|
manager_.Send(request);
|
||||||
for (int i = 0; i < 9; ++i) {
|
for (int i = 0; i < 9; ++i) {
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(request_count_ != i, STUN_TOTAL_TIMEOUT,
|
EXPECT_THAT(webrtc::WaitUntil(
|
||||||
fake_clock);
|
[&] { return request_count_; }, Ne(i),
|
||||||
|
{.timeout = webrtc::TimeDelta::Millis(STUN_TOTAL_TIMEOUT),
|
||||||
|
.clock = &fake_clock}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
int64_t elapsed = rtc::TimeMillis() - start;
|
int64_t elapsed = rtc::TimeMillis() - start;
|
||||||
RTC_DLOG(LS_INFO) << "STUN request #" << (i + 1) << " sent at " << elapsed
|
RTC_DLOG(LS_INFO) << "STUN request #" << (i + 1) << " sent at " << elapsed
|
||||||
<< " ms";
|
<< " ms";
|
||||||
|
|||||||
@ -10,23 +10,36 @@
|
|||||||
|
|
||||||
#include "p2p/base/tcp_port.h"
|
#include "p2p/base/tcp_port.h"
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#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/basic_packet_socket_factory.h"
|
||||||
|
#include "p2p/base/connection.h"
|
||||||
#include "p2p/base/p2p_constants.h"
|
#include "p2p/base/p2p_constants.h"
|
||||||
|
#include "p2p/base/port.h"
|
||||||
#include "p2p/base/transport_description.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/crypto_random.h"
|
||||||
#include "rtc_base/gunit.h"
|
|
||||||
#include "rtc_base/ip_address.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/socket_address.h"
|
||||||
#include "rtc_base/third_party/sigslot/sigslot.h"
|
#include "rtc_base/third_party/sigslot/sigslot.h"
|
||||||
#include "rtc_base/thread.h"
|
#include "rtc_base/thread.h"
|
||||||
#include "rtc_base/time_utils.h"
|
#include "rtc_base/time_utils.h"
|
||||||
#include "rtc_base/virtual_socket_server.h"
|
#include "rtc_base/virtual_socket_server.h"
|
||||||
|
#include "test/gmock.h"
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
#include "test/scoped_key_value_config.h"
|
#include "test/scoped_key_value_config.h"
|
||||||
|
#include "test/wait_until.h"
|
||||||
|
|
||||||
using cricket::Connection;
|
using cricket::Connection;
|
||||||
using cricket::ICE_PWD_LENGTH;
|
using cricket::ICE_PWD_LENGTH;
|
||||||
@ -34,6 +47,8 @@ using cricket::ICE_UFRAG_LENGTH;
|
|||||||
using cricket::Port;
|
using cricket::Port;
|
||||||
using cricket::TCPPort;
|
using cricket::TCPPort;
|
||||||
using rtc::SocketAddress;
|
using rtc::SocketAddress;
|
||||||
|
using ::testing::Eq;
|
||||||
|
using ::testing::IsTrue;
|
||||||
|
|
||||||
static int kTimeout = 1000;
|
static int kTimeout = 1000;
|
||||||
static const SocketAddress kLocalAddr("11.11.11.11", 0);
|
static const SocketAddress kLocalAddr("11.11.11.11", 0);
|
||||||
@ -135,7 +150,10 @@ TEST_F(TCPPortTest, TestTCPPortWithLocalhostAddress) {
|
|||||||
remote_port->PrepareAddress();
|
remote_port->PrepareAddress();
|
||||||
Connection* conn = local_port->CreateConnection(remote_port->Candidates()[0],
|
Connection* conn = local_port->CreateConnection(remote_port->Candidates()[0],
|
||||||
Port::ORIGIN_MESSAGE);
|
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
|
// Verify that the socket actually used localhost, otherwise this test isn't
|
||||||
// doing what it meant to.
|
// doing what it meant to.
|
||||||
ASSERT_EQ(local_address.ipaddr(),
|
ASSERT_EQ(local_address.ipaddr(),
|
||||||
@ -164,7 +182,10 @@ TEST_F(TCPPortTest, TCPPortDiscardedIfBoundAddressDoesNotMatchNetwork) {
|
|||||||
Connection* conn = local_port->CreateConnection(remote_port->Candidates()[0],
|
Connection* conn = local_port->CreateConnection(remote_port->Candidates()[0],
|
||||||
Port::ORIGIN_MESSAGE);
|
Port::ORIGIN_MESSAGE);
|
||||||
ConnectionObserver observer(conn);
|
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
|
// 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.
|
// Expect connection to succeed.
|
||||||
Connection* conn = local_port->CreateConnection(remote_port->Candidates()[0],
|
Connection* conn = local_port->CreateConnection(remote_port->Candidates()[0],
|
||||||
Port::ORIGIN_MESSAGE);
|
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
|
// Verify that the socket actually used the alternate address, otherwise this
|
||||||
// test isn't doing what it meant to.
|
// 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],
|
Connection* conn = local_port->CreateConnection(remote_port->Candidates()[0],
|
||||||
Port::ORIGIN_MESSAGE);
|
Port::ORIGIN_MESSAGE);
|
||||||
ASSERT_NE(nullptr, conn);
|
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<> {
|
class SentPacketCounter : public sigslot::has_slots<> {
|
||||||
@ -243,7 +270,10 @@ TEST_F(TCPPortTest, SignalSentPacket) {
|
|||||||
Connection* client_conn =
|
Connection* client_conn =
|
||||||
client->CreateConnection(server->Candidates()[0], Port::ORIGIN_MESSAGE);
|
client->CreateConnection(server->Candidates()[0], Port::ORIGIN_MESSAGE);
|
||||||
ASSERT_NE(nullptr, client_conn);
|
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..
|
// Need to get the port of the actual outgoing socket, not the server socket..
|
||||||
cricket::Candidate client_candidate = client->Candidates()[0];
|
cricket::Candidate client_candidate = client->Candidates()[0];
|
||||||
@ -253,12 +283,21 @@ TEST_F(TCPPortTest, SignalSentPacket) {
|
|||||||
Connection* server_conn =
|
Connection* server_conn =
|
||||||
server->CreateConnection(client_candidate, Port::ORIGIN_THIS_PORT);
|
server->CreateConnection(client_candidate, Port::ORIGIN_THIS_PORT);
|
||||||
ASSERT_NE(nullptr, server_conn);
|
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());
|
client_conn->Ping(rtc::TimeMillis());
|
||||||
server_conn->Ping(rtc::TimeMillis());
|
server_conn->Ping(rtc::TimeMillis());
|
||||||
ASSERT_TRUE_WAIT(client_conn->writable(), kTimeout);
|
ASSERT_THAT(
|
||||||
ASSERT_TRUE_WAIT(server_conn->writable(), kTimeout);
|
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 client_counter(client.get());
|
||||||
SentPacketCounter server_counter(server.get());
|
SentPacketCounter server_counter(server.get());
|
||||||
@ -267,8 +306,14 @@ TEST_F(TCPPortTest, SignalSentPacket) {
|
|||||||
client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions());
|
client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions());
|
||||||
server_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_THAT(
|
||||||
EXPECT_EQ_WAIT(10, server_counter.sent_packets(), kTimeout);
|
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
|
// Test that SignalSentPacket is fired when a packet is successfully sent, even
|
||||||
@ -287,7 +332,10 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) {
|
|||||||
Connection* client_conn =
|
Connection* client_conn =
|
||||||
client->CreateConnection(server->Candidates()[0], Port::ORIGIN_MESSAGE);
|
client->CreateConnection(server->Candidates()[0], Port::ORIGIN_MESSAGE);
|
||||||
ASSERT_NE(nullptr, client_conn);
|
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.
|
// Need to get the port of the actual outgoing socket.
|
||||||
cricket::Candidate client_candidate = client->Candidates()[0];
|
cricket::Candidate client_candidate = client->Candidates()[0];
|
||||||
@ -297,10 +345,16 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) {
|
|||||||
client_candidate.set_tcptype("");
|
client_candidate.set_tcptype("");
|
||||||
Connection* server_conn =
|
Connection* server_conn =
|
||||||
server->CreateConnection(client_candidate, Port::ORIGIN_THIS_PORT);
|
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());
|
EXPECT_FALSE(client_conn->writable());
|
||||||
client_conn->Ping(rtc::TimeMillis());
|
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());
|
SentPacketCounter client_counter(client.get());
|
||||||
static const char kData[] = "hello";
|
static const char kData[] = "hello";
|
||||||
@ -310,7 +364,10 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) {
|
|||||||
// Deleting the server port should break the current connection.
|
// Deleting the server port should break the current connection.
|
||||||
server = nullptr;
|
server = nullptr;
|
||||||
server_conn = 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.
|
// Recreate the server port with the same port number.
|
||||||
server = CreateTCPPort(kRemoteAddr, /*allow_listen=*/true, kServerPort);
|
server = CreateTCPPort(kRemoteAddr, /*allow_listen=*/true, kServerPort);
|
||||||
@ -321,7 +378,10 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) {
|
|||||||
// packet will be discarded.
|
// packet will be discarded.
|
||||||
result = client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions());
|
result = client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions());
|
||||||
EXPECT_EQ(result, SOCKET_ERROR);
|
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....
|
// For unknown reasons, connection is still supposed to be writable....
|
||||||
EXPECT_TRUE(client_conn->writable());
|
EXPECT_TRUE(client_conn->writable());
|
||||||
for (int i = 0; i < 10; ++i) {
|
for (int i = 0; i < 10; ++i) {
|
||||||
@ -330,7 +390,10 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) {
|
|||||||
SOCKET_ERROR);
|
SOCKET_ERROR);
|
||||||
}
|
}
|
||||||
// And are not reported as sent.
|
// 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.
|
// 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
|
// 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("");
|
client_candidate.set_tcptype("");
|
||||||
server_conn =
|
server_conn =
|
||||||
server->CreateConnection(client_candidate, Port::ORIGIN_THIS_PORT);
|
server->CreateConnection(client_candidate, Port::ORIGIN_THIS_PORT);
|
||||||
ASSERT_TRUE_WAIT(server_conn->connected(), kTimeout);
|
ASSERT_THAT(
|
||||||
EXPECT_EQ_WAIT(client_counter.sent_packets(), 1, kTimeout);
|
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.
|
// Send Stun Binding request.
|
||||||
client_conn->Ping(rtc::TimeMillis());
|
client_conn->Ping(rtc::TimeMillis());
|
||||||
// The Stun Binding request is reported as sent.
|
// 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.
|
// Wait a bit for the Stun response to be received.
|
||||||
rtc::Thread::Current()->ProcessMessages(100);
|
rtc::Thread::Current()->ProcessMessages(100);
|
||||||
|
|
||||||
@ -358,5 +430,8 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) {
|
|||||||
EXPECT_EQ(client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions()),
|
EXPECT_EQ(client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions()),
|
||||||
6);
|
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());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,10 +7,29 @@
|
|||||||
* in the file PATENTS. All contributing project authors may
|
* in the file PATENTS. All contributing project authors may
|
||||||
* 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 <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/functional/any_invocable.h"
|
||||||
#include "api/array_view.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/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)
|
#if defined(WEBRTC_POSIX)
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
@ -54,6 +73,9 @@ using rtc::SocketAddress;
|
|||||||
|
|
||||||
using ::testing::_;
|
using ::testing::_;
|
||||||
using ::testing::DoAll;
|
using ::testing::DoAll;
|
||||||
|
using ::testing::Eq;
|
||||||
|
using ::testing::IsTrue;
|
||||||
|
using ::testing::Ne;
|
||||||
using ::testing::Return;
|
using ::testing::Return;
|
||||||
using ::testing::ReturnPointee;
|
using ::testing::ReturnPointee;
|
||||||
using ::testing::SetArgPointee;
|
using ::testing::SetArgPointee;
|
||||||
@ -384,12 +406,19 @@ class TurnPortTest : public ::testing::Test,
|
|||||||
// turn_port_ should have been created.
|
// turn_port_ should have been created.
|
||||||
ASSERT_TRUE(turn_port_ != nullptr);
|
ASSERT_TRUE(turn_port_ != nullptr);
|
||||||
turn_port_->PrepareAddress();
|
turn_port_->PrepareAddress();
|
||||||
ASSERT_TRUE_SIMULATED_WAIT(
|
ASSERT_THAT(webrtc::WaitUntil([&] { return turn_ready_; }, IsTrue(),
|
||||||
turn_ready_, TimeToGetTurnCandidate(protocol_type), fake_clock_);
|
{.timeout = webrtc::TimeDelta::Millis(
|
||||||
|
TimeToGetTurnCandidate(protocol_type)),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
|
|
||||||
CreateUdpPort();
|
CreateUdpPort();
|
||||||
udp_port_->PrepareAddress();
|
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
|
// 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) {
|
void TestTurnAllocateSucceeds(unsigned int timeout) {
|
||||||
ASSERT_TRUE(turn_port_);
|
ASSERT_TRUE(turn_port_);
|
||||||
turn_port_->PrepareAddress();
|
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());
|
ASSERT_EQ(1U, turn_port_->Candidates().size());
|
||||||
EXPECT_EQ(kTurnUdpExtAddr.ipaddr(),
|
EXPECT_EQ(kTurnUdpExtAddr.ipaddr(),
|
||||||
turn_port_->Candidates()[0].address().ipaddr());
|
turn_port_->Candidates()[0].address().ipaddr());
|
||||||
@ -464,8 +497,11 @@ class TurnPortTest : public ::testing::Test,
|
|||||||
absl::string_view expected_url) {
|
absl::string_view expected_url) {
|
||||||
ASSERT_TRUE(turn_port_);
|
ASSERT_TRUE(turn_port_);
|
||||||
turn_port_->PrepareAddress();
|
turn_port_->PrepareAddress();
|
||||||
ASSERT_TRUE_SIMULATED_WAIT(
|
ASSERT_THAT(webrtc::WaitUntil([&] { return turn_ready_; }, IsTrue(),
|
||||||
turn_ready_, TimeToGetTurnCandidate(protocol_type), fake_clock_);
|
{.timeout = webrtc::TimeDelta::Millis(
|
||||||
|
TimeToGetTurnCandidate(protocol_type)),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
ASSERT_EQ(1U, turn_port_->Candidates().size());
|
ASSERT_EQ(1U, turn_port_->Candidates().size());
|
||||||
EXPECT_EQ(turn_port_->Candidates()[0].url(), expected_url);
|
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;
|
const SocketAddress old_addr = turn_port_->server_address().address;
|
||||||
|
|
||||||
turn_port_->PrepareAddress();
|
turn_port_->PrepareAddress();
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(turn_ready_,
|
EXPECT_THAT(
|
||||||
TimeToGetAlternateTurnCandidate(protocol_type),
|
webrtc::WaitUntil([&] { return turn_ready_; }, IsTrue(),
|
||||||
fake_clock_);
|
{.timeout = webrtc::TimeDelta::Millis(
|
||||||
|
TimeToGetAlternateTurnCandidate(protocol_type)),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
// Retrieve the address again, the turn port's address should be
|
// Retrieve the address again, the turn port's address should be
|
||||||
// changed.
|
// changed.
|
||||||
const SocketAddress new_addr = turn_port_->server_address().address;
|
const SocketAddress new_addr = turn_port_->server_address().address;
|
||||||
@ -511,8 +550,12 @@ class TurnPortTest : public ::testing::Test,
|
|||||||
turn_port_->PrepareAddress();
|
turn_port_->PrepareAddress();
|
||||||
// Need time to connect to TURN server, send Allocate request and receive
|
// Need time to connect to TURN server, send Allocate request and receive
|
||||||
// redirect notice.
|
// redirect notice.
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(
|
EXPECT_THAT(
|
||||||
turn_error_, kSimulatedRtt + TimeToConnect(protocol_type), fake_clock_);
|
webrtc::WaitUntil([&] { return turn_error_; }, IsTrue(),
|
||||||
|
{.timeout = webrtc::TimeDelta::Millis(
|
||||||
|
kSimulatedRtt + TimeToConnect(protocol_type)),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestTurnAlternateServerPingPong(ProtocolType protocol_type) {
|
void TestTurnAlternateServerPingPong(ProtocolType protocol_type) {
|
||||||
@ -529,9 +572,12 @@ class TurnPortTest : public ::testing::Test,
|
|||||||
ProtocolAddress(kTurnIntAddr, protocol_type));
|
ProtocolAddress(kTurnIntAddr, protocol_type));
|
||||||
|
|
||||||
turn_port_->PrepareAddress();
|
turn_port_->PrepareAddress();
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(turn_error_,
|
EXPECT_THAT(
|
||||||
TimeToGetAlternateTurnCandidate(protocol_type),
|
webrtc::WaitUntil([&] { return turn_error_; }, IsTrue(),
|
||||||
fake_clock_);
|
{.timeout = webrtc::TimeDelta::Millis(
|
||||||
|
TimeToGetAlternateTurnCandidate(protocol_type)),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
ASSERT_EQ(0U, turn_port_->Candidates().size());
|
ASSERT_EQ(0U, turn_port_->Candidates().size());
|
||||||
rtc::SocketAddress address;
|
rtc::SocketAddress address;
|
||||||
// Verify that we have exhausted all alternate servers instead of
|
// Verify that we have exhausted all alternate servers instead of
|
||||||
@ -553,9 +599,12 @@ class TurnPortTest : public ::testing::Test,
|
|||||||
ProtocolAddress(kTurnIntAddr, protocol_type));
|
ProtocolAddress(kTurnIntAddr, protocol_type));
|
||||||
|
|
||||||
turn_port_->PrepareAddress();
|
turn_port_->PrepareAddress();
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(turn_error_,
|
EXPECT_THAT(
|
||||||
TimeToGetAlternateTurnCandidate(protocol_type),
|
webrtc::WaitUntil([&] { return turn_error_; }, IsTrue(),
|
||||||
fake_clock_);
|
{.timeout = webrtc::TimeDelta::Millis(
|
||||||
|
TimeToGetAlternateTurnCandidate(protocol_type)),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
ASSERT_EQ(0U, turn_port_->Candidates().size());
|
ASSERT_EQ(0U, turn_port_->Candidates().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -593,8 +642,11 @@ class TurnPortTest : public ::testing::Test,
|
|||||||
ProtocolAddress(server_address, protocol_type));
|
ProtocolAddress(server_address, protocol_type));
|
||||||
|
|
||||||
turn_port_->PrepareAddress();
|
turn_port_->PrepareAddress();
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(
|
EXPECT_THAT(webrtc::WaitUntil([&] { return turn_error_; }, IsTrue(),
|
||||||
turn_error_, TimeToGetTurnCandidate(protocol_type), fake_clock_);
|
{.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
|
// 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
|
// 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],
|
Connection* conn2 = turn_port_->CreateConnection(udp_port_->Candidates()[0],
|
||||||
Port::ORIGIN_MESSAGE);
|
Port::ORIGIN_MESSAGE);
|
||||||
ASSERT_TRUE(conn2 != NULL);
|
ASSERT_TRUE(conn2 != NULL);
|
||||||
ASSERT_TRUE_SIMULATED_WAIT(turn_create_permission_success_, kSimulatedRtt,
|
ASSERT_THAT(webrtc::WaitUntil(
|
||||||
fake_clock_);
|
[&] { return turn_create_permission_success_; }, IsTrue(),
|
||||||
|
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
conn2->Ping(0);
|
conn2->Ping(0);
|
||||||
|
|
||||||
// Two hops from TURN port to UDP port through TURN server, thus two RTTs.
|
// Two hops from TURN port to UDP port through TURN server, thus two RTTs.
|
||||||
EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn2->write_state(),
|
EXPECT_THAT(webrtc::WaitUntil(
|
||||||
kSimulatedRtt * 2, fake_clock_);
|
[&] { 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(conn1->receiving());
|
||||||
EXPECT_TRUE(conn2->receiving());
|
EXPECT_TRUE(conn2->receiving());
|
||||||
EXPECT_EQ(Connection::STATE_WRITE_INIT, conn1->write_state());
|
EXPECT_EQ(Connection::STATE_WRITE_INIT, conn1->write_state());
|
||||||
|
|
||||||
// Send another ping from UDP to TURN.
|
// Send another ping from UDP to TURN.
|
||||||
conn1->Ping(0);
|
conn1->Ping(0);
|
||||||
EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn1->write_state(),
|
EXPECT_THAT(webrtc::WaitUntil(
|
||||||
kSimulatedRtt * 2, fake_clock_);
|
[&] { return conn1->write_state(); },
|
||||||
|
Eq(Connection::STATE_WRITABLE),
|
||||||
|
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
EXPECT_TRUE(conn2->receiving());
|
EXPECT_TRUE(conn2->receiving());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -661,12 +724,19 @@ class TurnPortTest : public ::testing::Test,
|
|||||||
turn_port_->set_timeout_delay(10 * 60 * 1000);
|
turn_port_->set_timeout_delay(10 * 60 * 1000);
|
||||||
|
|
||||||
ASSERT_TRUE(conn2 != NULL);
|
ASSERT_TRUE(conn2 != NULL);
|
||||||
ASSERT_TRUE_SIMULATED_WAIT(turn_create_permission_success_, kSimulatedRtt,
|
ASSERT_THAT(webrtc::WaitUntil(
|
||||||
fake_clock_);
|
[&] { return turn_create_permission_success_; }, IsTrue(),
|
||||||
|
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
// Make sure turn connection can receive.
|
// Make sure turn connection can receive.
|
||||||
conn1->Ping(0);
|
conn1->Ping(0);
|
||||||
EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn1->write_state(),
|
EXPECT_THAT(webrtc::WaitUntil(
|
||||||
kSimulatedRtt * 2, fake_clock_);
|
[&] { return conn1->write_state(); },
|
||||||
|
Eq(Connection::STATE_WRITABLE),
|
||||||
|
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
EXPECT_FALSE(turn_unknown_address_);
|
EXPECT_FALSE(turn_unknown_address_);
|
||||||
|
|
||||||
// Destroy the connection on the TURN port. The TurnEntry still exists, so
|
// 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);
|
turn_port_->DestroyConnection(conn2);
|
||||||
|
|
||||||
conn1->Ping(0);
|
conn1->Ping(0);
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(turn_unknown_address_, kSimulatedRtt,
|
EXPECT_THAT(
|
||||||
fake_clock_);
|
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.
|
// Wait for TurnEntry to expire. Timeout is 5 minutes.
|
||||||
// Expect that it still processes an incoming ping and signals the
|
// 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->set_remote_password_for_test(pwd);
|
||||||
|
|
||||||
conn1->Ping(0);
|
conn1->Ping(0);
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(turn_unknown_address_, kSimulatedRtt,
|
EXPECT_THAT(
|
||||||
fake_clock_);
|
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.
|
// If the connection is created again, it will start to receive pings.
|
||||||
conn2 = turn_port_->CreateConnection(udp_port_->Candidates()[0],
|
conn2 = turn_port_->CreateConnection(udp_port_->Candidates()[0],
|
||||||
Port::ORIGIN_MESSAGE);
|
Port::ORIGIN_MESSAGE);
|
||||||
conn1->Ping(0);
|
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) {
|
void TestTurnSendData(ProtocolType protocol_type) {
|
||||||
@ -742,11 +822,19 @@ class TurnPortTest : public ::testing::Test,
|
|||||||
conn2->SignalDestroyed.connect(this,
|
conn2->SignalDestroyed.connect(this,
|
||||||
&TurnPortTest::OnConnectionSignalDestroyed);
|
&TurnPortTest::OnConnectionSignalDestroyed);
|
||||||
conn1->Ping(0);
|
conn1->Ping(0);
|
||||||
EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn1->write_state(),
|
EXPECT_THAT(webrtc::WaitUntil(
|
||||||
kSimulatedRtt * 2, fake_clock_);
|
[&] { return conn1->write_state(); },
|
||||||
|
Eq(Connection::STATE_WRITABLE),
|
||||||
|
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
conn2->Ping(0);
|
conn2->Ping(0);
|
||||||
EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn2->write_state(),
|
EXPECT_THAT(webrtc::WaitUntil(
|
||||||
kSimulatedRtt * 2, fake_clock_);
|
[&] { return conn2->write_state(); },
|
||||||
|
Eq(Connection::STATE_WRITABLE),
|
||||||
|
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
|
|
||||||
// Send some data.
|
// Send some data.
|
||||||
size_t num_packets = 256;
|
size_t num_packets = 256;
|
||||||
@ -774,8 +862,12 @@ class TurnPortTest : public ::testing::Test,
|
|||||||
void TestTurnReleaseAllocation(ProtocolType protocol_type) {
|
void TestTurnReleaseAllocation(ProtocolType protocol_type) {
|
||||||
PrepareTurnAndUdpPorts(protocol_type);
|
PrepareTurnAndUdpPorts(protocol_type);
|
||||||
turn_port_.reset();
|
turn_port_.reset();
|
||||||
EXPECT_EQ_SIMULATED_WAIT(0U, turn_server_.server()->allocations().size(),
|
EXPECT_THAT(
|
||||||
kSimulatedRtt, fake_clock_);
|
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
|
// Test that the TURN allocation is released by sending a refresh request
|
||||||
@ -806,11 +898,19 @@ class TurnPortTest : public ::testing::Test,
|
|||||||
&TurnPortTest::OnConnectionSignalDestroyed);
|
&TurnPortTest::OnConnectionSignalDestroyed);
|
||||||
|
|
||||||
conn1->Ping(0);
|
conn1->Ping(0);
|
||||||
EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn1->write_state(),
|
EXPECT_THAT(webrtc::WaitUntil(
|
||||||
kSimulatedRtt * 2, fake_clock_);
|
[&] { return conn1->write_state(); },
|
||||||
|
Eq(Connection::STATE_WRITABLE),
|
||||||
|
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
conn2->Ping(0);
|
conn2->Ping(0);
|
||||||
EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn2->write_state(),
|
EXPECT_THAT(webrtc::WaitUntil(
|
||||||
kSimulatedRtt * 2, fake_clock_);
|
[&] { 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.
|
// Send some data from Udp to TurnPort.
|
||||||
unsigned char buf[256] = {0};
|
unsigned char buf[256] = {0};
|
||||||
@ -821,7 +921,11 @@ class TurnPortTest : public ::testing::Test,
|
|||||||
turn_port_->Release();
|
turn_port_->Release();
|
||||||
|
|
||||||
// Wait for the TurnPort to signal closed.
|
// 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.
|
// But the data should have arrived first.
|
||||||
ASSERT_EQ(1ul, turn_packets_.size());
|
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,
|
// As VSS doesn't provide DNS resolution, name resolve will fail,
|
||||||
// the error will be set and contain the url.
|
// the error will be set and contain the url.
|
||||||
turn_port_->PrepareAddress();
|
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 =
|
std::string server_url =
|
||||||
"turn:" + kTurnInvalidAddr.ToString() + "?transport=udp";
|
"turn:" + kTurnInvalidAddr.ToString() + "?transport=udp";
|
||||||
ASSERT_EQ(error_event_.url, server_url);
|
ASSERT_EQ(error_event_.url, server_url);
|
||||||
@ -963,10 +1070,18 @@ TEST_F(TurnPortTest, TestTurnAllocateWithoutLoggingId) {
|
|||||||
TEST_F(TurnPortTest, TestTurnBadCredentials) {
|
TEST_F(TurnPortTest, TestTurnBadCredentials) {
|
||||||
CreateTurnPort(kTurnUsername, "bad", kTurnUdpProtoAddr);
|
CreateTurnPort(kTurnUsername, "bad", kTurnUdpProtoAddr);
|
||||||
turn_port_->PrepareAddress();
|
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());
|
ASSERT_EQ(0U, turn_port_->Candidates().size());
|
||||||
EXPECT_EQ_SIMULATED_WAIT(error_event_.error_code, STUN_ERROR_UNAUTHORIZED,
|
EXPECT_THAT(
|
||||||
kSimulatedRtt * 3, fake_clock_);
|
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");
|
EXPECT_EQ(error_event_.error_text, "Unauthorized");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -975,7 +1090,11 @@ TEST_F(TurnPortTest, TestTurnBadCredentials) {
|
|||||||
TEST_F(TurnPortTest, TestServerAddressFamilyMismatch) {
|
TEST_F(TurnPortTest, TestServerAddressFamilyMismatch) {
|
||||||
CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpIPv6ProtoAddr);
|
CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpIPv6ProtoAddr);
|
||||||
turn_port_->PrepareAddress();
|
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());
|
ASSERT_EQ(0U, turn_port_->Candidates().size());
|
||||||
EXPECT_EQ(0, error_event_.error_code);
|
EXPECT_EQ(0, error_event_.error_code);
|
||||||
}
|
}
|
||||||
@ -986,7 +1105,11 @@ TEST_F(TurnPortTest, TestServerAddressFamilyMismatch6) {
|
|||||||
CreateTurnPort(kLocalIPv6Addr, kTurnUsername, kTurnPassword,
|
CreateTurnPort(kLocalIPv6Addr, kTurnUsername, kTurnPassword,
|
||||||
kTurnUdpProtoAddr);
|
kTurnUdpProtoAddr);
|
||||||
turn_port_->PrepareAddress();
|
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());
|
ASSERT_EQ(0U, turn_port_->Candidates().size());
|
||||||
EXPECT_EQ(0, error_event_.error_code);
|
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
|
// Shouldn't take more than 1 RTT to realize the bound address isn't the one
|
||||||
// expected.
|
// expected.
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(turn_error_, kSimulatedRtt, fake_clock_);
|
EXPECT_THAT(
|
||||||
EXPECT_EQ_SIMULATED_WAIT(error_event_.error_code,
|
webrtc::WaitUntil([&] { return turn_error_; }, IsTrue(),
|
||||||
STUN_ERROR_SERVER_NOT_REACHABLE, kSimulatedRtt,
|
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
|
||||||
fake_clock_);
|
.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_.error_text.find('.'), std::string::npos);
|
||||||
EXPECT_NE(error_event_.address.find(kLocalAddr2.HostAsSensitiveURIString()),
|
EXPECT_NE(error_event_.address.find(kLocalAddr2.HostAsSensitiveURIString()),
|
||||||
std::string::npos);
|
std::string::npos);
|
||||||
@ -1074,7 +1204,11 @@ TEST_F(TurnPortTest, TurnTcpAllocationNotDiscardedIfNotBoundToBestIP) {
|
|||||||
turn_port_->PrepareAddress();
|
turn_port_->PrepareAddress();
|
||||||
|
|
||||||
// Candidate should be gathered as normally.
|
// 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());
|
ASSERT_EQ(1U, turn_port_->Candidates().size());
|
||||||
|
|
||||||
// Verify that the socket actually used the alternate address, otherwise this
|
// Verify that the socket actually used the alternate address, otherwise this
|
||||||
@ -1101,7 +1235,11 @@ TEST_F(TurnPortTest, TCPPortNotDiscardedIfBoundToTemporaryIP) {
|
|||||||
turn_port_->PrepareAddress();
|
turn_port_->PrepareAddress();
|
||||||
|
|
||||||
// Candidate should be gathered as normally.
|
// 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());
|
ASSERT_EQ(1U, turn_port_->Candidates().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1112,14 +1250,20 @@ TEST_F(TurnPortTest, TestTurnTcpOnAddressResolveFailure) {
|
|||||||
CreateTurnPort(kTurnUsername, kTurnPassword,
|
CreateTurnPort(kTurnUsername, kTurnPassword,
|
||||||
ProtocolAddress(kTurnInvalidAddr, PROTO_TCP));
|
ProtocolAddress(kTurnInvalidAddr, PROTO_TCP));
|
||||||
turn_port_->PrepareAddress();
|
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
|
// 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
|
// 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.
|
// server on the above domain and error will be set to SOCKET_ERROR.
|
||||||
EXPECT_EQ(SOCKET_ERROR, turn_port_->error());
|
EXPECT_EQ(SOCKET_ERROR, turn_port_->error());
|
||||||
EXPECT_EQ_SIMULATED_WAIT(error_event_.error_code,
|
EXPECT_THAT(
|
||||||
STUN_ERROR_SERVER_NOT_REACHABLE, kSimulatedRtt,
|
webrtc::WaitUntil([&] { return error_event_.error_code; },
|
||||||
fake_clock_);
|
Eq(STUN_ERROR_SERVER_NOT_REACHABLE),
|
||||||
|
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
std::string server_url =
|
std::string server_url =
|
||||||
"turn:" + kTurnInvalidAddr.ToString() + "?transport=tcp";
|
"turn:" + kTurnInvalidAddr.ToString() + "?transport=tcp";
|
||||||
ASSERT_EQ(error_event_.url, server_url);
|
ASSERT_EQ(error_event_.url, server_url);
|
||||||
@ -1132,7 +1276,10 @@ TEST_F(TurnPortTest, TestTurnTlsOnAddressResolveFailure) {
|
|||||||
CreateTurnPort(kTurnUsername, kTurnPassword,
|
CreateTurnPort(kTurnUsername, kTurnPassword,
|
||||||
ProtocolAddress(kTurnInvalidAddr, PROTO_TLS));
|
ProtocolAddress(kTurnInvalidAddr, PROTO_TLS));
|
||||||
turn_port_->PrepareAddress();
|
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());
|
EXPECT_EQ(SOCKET_ERROR, turn_port_->error());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1142,7 +1289,10 @@ TEST_F(TurnPortTest, TestTurnUdpOnAddressResolveFailure) {
|
|||||||
CreateTurnPort(kTurnUsername, kTurnPassword,
|
CreateTurnPort(kTurnUsername, kTurnPassword,
|
||||||
ProtocolAddress(kTurnInvalidAddr, PROTO_UDP));
|
ProtocolAddress(kTurnInvalidAddr, PROTO_UDP));
|
||||||
turn_port_->PrepareAddress();
|
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.
|
// Error from turn port will not be socket error.
|
||||||
EXPECT_NE(SOCKET_ERROR, turn_port_->error());
|
EXPECT_NE(SOCKET_ERROR, turn_port_->error());
|
||||||
}
|
}
|
||||||
@ -1151,7 +1301,11 @@ TEST_F(TurnPortTest, TestTurnUdpOnAddressResolveFailure) {
|
|||||||
TEST_F(TurnPortTest, TestTurnAllocateBadPassword) {
|
TEST_F(TurnPortTest, TestTurnAllocateBadPassword) {
|
||||||
CreateTurnPort(kTurnUsername, "bad", kTurnUdpProtoAddr);
|
CreateTurnPort(kTurnUsername, "bad", kTurnUdpProtoAddr);
|
||||||
turn_port_->PrepareAddress();
|
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());
|
ASSERT_EQ(0U, turn_port_->Candidates().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1161,7 +1315,11 @@ TEST_F(TurnPortTest, TestTurnAllocateNonceResetAfterAllocateMismatch) {
|
|||||||
// Do a normal allocation first.
|
// Do a normal allocation first.
|
||||||
CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
|
CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
|
||||||
turn_port_->PrepareAddress();
|
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());
|
rtc::SocketAddress first_addr(turn_port_->socket()->GetLocalAddress());
|
||||||
// Destroy the turnport while keeping the drop probability to 1 to
|
// Destroy the turnport while keeping the drop probability to 1 to
|
||||||
// suppress the release of the allocation at the server.
|
// 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
|
// Four round trips; first we'll get "stale nonce", then
|
||||||
// "allocate mismatch", then "stale nonce" again, then finally it will
|
// "allocate mismatch", then "stale nonce" again, then finally it will
|
||||||
// succeed.
|
// 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());
|
EXPECT_NE(first_nonce, turn_port_->nonce());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1197,7 +1359,11 @@ TEST_F(TurnPortTest, TestTurnAllocateMismatch) {
|
|||||||
// Do a normal allocation first.
|
// Do a normal allocation first.
|
||||||
CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
|
CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
|
||||||
turn_port_->PrepareAddress();
|
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());
|
rtc::SocketAddress first_addr(turn_port_->socket()->GetLocalAddress());
|
||||||
|
|
||||||
// Clear connected_ flag on turnport to suppress the release of
|
// 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
|
// Four round trips; first we'll get "stale nonce", then
|
||||||
// "allocate mismatch", then "stale nonce" again, then finally it will
|
// "allocate mismatch", then "stale nonce" again, then finally it will
|
||||||
// succeed.
|
// 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.
|
// Verifies that the new port has a different address now.
|
||||||
EXPECT_NE(first_addr, turn_port_->socket()->GetLocalAddress());
|
EXPECT_NE(first_addr, turn_port_->socket()->GetLocalAddress());
|
||||||
@ -1237,7 +1407,11 @@ TEST_F(TurnPortTest, TestSharedSocketAllocateMismatch) {
|
|||||||
// Do a normal allocation first.
|
// Do a normal allocation first.
|
||||||
CreateSharedTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
|
CreateSharedTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
|
||||||
turn_port_->PrepareAddress();
|
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());
|
rtc::SocketAddress first_addr(turn_port_->socket()->GetLocalAddress());
|
||||||
|
|
||||||
// Clear connected_ flag on turnport to suppress the release of
|
// Clear connected_ flag on turnport to suppress the release of
|
||||||
@ -1253,7 +1427,11 @@ TEST_F(TurnPortTest, TestSharedSocketAllocateMismatch) {
|
|||||||
|
|
||||||
turn_port_->PrepareAddress();
|
turn_port_->PrepareAddress();
|
||||||
// Extra 2 round trips due to allocate mismatch.
|
// 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.
|
// Verifies that the new port has a different address now.
|
||||||
EXPECT_NE(first_addr, turn_port_->socket()->GetLocalAddress());
|
EXPECT_NE(first_addr, turn_port_->socket()->GetLocalAddress());
|
||||||
@ -1266,7 +1444,11 @@ TEST_F(TurnPortTest, TestTurnTcpAllocateMismatch) {
|
|||||||
|
|
||||||
// Do a normal allocation first.
|
// Do a normal allocation first.
|
||||||
turn_port_->PrepareAddress();
|
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());
|
rtc::SocketAddress first_addr(turn_port_->socket()->GetLocalAddress());
|
||||||
|
|
||||||
// Clear connected_ flag on turnport to suppress the release of
|
// 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());
|
EXPECT_EQ(first_addr, turn_port_->socket()->GetLocalAddress());
|
||||||
|
|
||||||
// Extra 2 round trips due to allocate mismatch.
|
// 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.
|
// Verifies that the new port has a different address now.
|
||||||
EXPECT_NE(first_addr, turn_port_->socket()->GetLocalAddress());
|
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
|
// When this succeeds, it will schedule a new RefreshRequest with the bad
|
||||||
// credential.
|
// credential.
|
||||||
turn_port_->request_manager().FlushForTest(TURN_REFRESH_REQUEST);
|
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.
|
// Flush it again, it will receive a bad response.
|
||||||
turn_port_->request_manager().FlushForTest(TURN_REFRESH_REQUEST);
|
turn_port_->request_manager().FlushForTest(TURN_REFRESH_REQUEST);
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(!turn_refresh_success_, kSimulatedRtt,
|
EXPECT_THAT(
|
||||||
fake_clock_);
|
webrtc::WaitUntil([&] { return !turn_refresh_success_; }, IsTrue(),
|
||||||
|
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
EXPECT_FALSE(turn_port_->connected());
|
EXPECT_FALSE(turn_port_->connected());
|
||||||
EXPECT_TRUE(CheckAllConnectionsFailedAndPruned());
|
EXPECT_TRUE(CheckAllConnectionsFailedAndPruned());
|
||||||
EXPECT_FALSE(turn_port_->HasRequests());
|
EXPECT_FALSE(turn_port_->HasRequests());
|
||||||
@ -1326,8 +1519,12 @@ TEST_F(TurnPortTest, TestStopProcessingPacketsAfterClosed) {
|
|||||||
ASSERT_TRUE(conn2 != NULL);
|
ASSERT_TRUE(conn2 != NULL);
|
||||||
// Make sure conn2 is writable.
|
// Make sure conn2 is writable.
|
||||||
conn2->Ping(0);
|
conn2->Ping(0);
|
||||||
EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE, conn2->write_state(),
|
EXPECT_THAT(
|
||||||
kSimulatedRtt * 2, fake_clock_);
|
webrtc::WaitUntil(
|
||||||
|
[&] { return conn2->write_state(); }, Eq(Connection::STATE_WRITABLE),
|
||||||
|
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt * 2),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
|
|
||||||
turn_port_->CloseForTest();
|
turn_port_->CloseForTest();
|
||||||
SIMULATED_WAIT(false, kSimulatedRtt, fake_clock_);
|
SIMULATED_WAIT(false, kSimulatedRtt, fake_clock_);
|
||||||
@ -1367,8 +1564,12 @@ TEST_F(TurnPortTest, TestSocketCloseWillDestroyConnection) {
|
|||||||
EXPECT_NE(nullptr, conn);
|
EXPECT_NE(nullptr, conn);
|
||||||
EXPECT_TRUE(!turn_port_->connections().empty());
|
EXPECT_TRUE(!turn_port_->connections().empty());
|
||||||
turn_port_->socket()->NotifyClosedForTest(1);
|
turn_port_->socket()->NotifyClosedForTest(1);
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(turn_port_->connections().empty(),
|
EXPECT_THAT(
|
||||||
kConnectionDestructionDelay, fake_clock_);
|
webrtc::WaitUntil(
|
||||||
|
[&] { return turn_port_->connections().empty(); }, IsTrue(),
|
||||||
|
{.timeout = webrtc::TimeDelta::Millis(kConnectionDestructionDelay),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test try-alternate-server feature.
|
// Test try-alternate-server feature.
|
||||||
@ -1511,8 +1712,11 @@ TEST_F(TurnPortTest, TestRefreshCreatePermissionRequest) {
|
|||||||
Connection* conn = turn_port_->CreateConnection(udp_port_->Candidates()[0],
|
Connection* conn = turn_port_->CreateConnection(udp_port_->Candidates()[0],
|
||||||
Port::ORIGIN_MESSAGE);
|
Port::ORIGIN_MESSAGE);
|
||||||
ASSERT_TRUE(conn != NULL);
|
ASSERT_TRUE(conn != NULL);
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(turn_create_permission_success_, kSimulatedRtt,
|
EXPECT_THAT(webrtc::WaitUntil(
|
||||||
fake_clock_);
|
[&] { return turn_create_permission_success_; }, IsTrue(),
|
||||||
|
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
turn_create_permission_success_ = false;
|
turn_create_permission_success_ = false;
|
||||||
// A create-permission-request should be pending.
|
// A create-permission-request should be pending.
|
||||||
// After the next create-permission-response is received, it will schedule
|
// 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");
|
RelayCredentials bad_credentials("bad_user", "bad_pwd");
|
||||||
turn_port_->set_credentials(bad_credentials);
|
turn_port_->set_credentials(bad_credentials);
|
||||||
turn_port_->request_manager().FlushForTest(kAllRequestsForTest);
|
turn_port_->request_manager().FlushForTest(kAllRequestsForTest);
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(turn_create_permission_success_, kSimulatedRtt,
|
EXPECT_THAT(webrtc::WaitUntil(
|
||||||
fake_clock_);
|
[&] { 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.
|
// Flush the requests again; the create-permission-request will fail.
|
||||||
turn_port_->request_manager().FlushForTest(kAllRequestsForTest);
|
turn_port_->request_manager().FlushForTest(kAllRequestsForTest);
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(!turn_create_permission_success_, kSimulatedRtt,
|
EXPECT_THAT(webrtc::WaitUntil(
|
||||||
fake_clock_);
|
[&] { return !turn_create_permission_success_; }, IsTrue(),
|
||||||
|
{.timeout = webrtc::TimeDelta::Millis(kSimulatedRtt),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
EXPECT_TRUE(CheckConnectionFailedAndPruned(conn));
|
EXPECT_TRUE(CheckConnectionFailedAndPruned(conn));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1540,7 +1750,11 @@ TEST_F(TurnPortTest, TestChannelBindGetErrorResponse) {
|
|||||||
|
|
||||||
ASSERT_TRUE(conn2 != nullptr);
|
ASSERT_TRUE(conn2 != nullptr);
|
||||||
conn1->Ping(0);
|
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.
|
// Tell the TURN server to reject all bind requests from now on.
|
||||||
turn_server_.server()->set_reject_bind_requests(true);
|
turn_server_.server()->set_reject_bind_requests(true);
|
||||||
@ -1548,8 +1762,12 @@ TEST_F(TurnPortTest, TestChannelBindGetErrorResponse) {
|
|||||||
std::string data = "ABC";
|
std::string data = "ABC";
|
||||||
conn1->Send(data.data(), data.length(), options);
|
conn1->Send(data.data(), data.length(), options);
|
||||||
|
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(CheckConnectionFailedAndPruned(conn1),
|
EXPECT_THAT(
|
||||||
kSimulatedRtt, fake_clock_);
|
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.
|
// Verify that packets are allowed to be sent after a bind request error.
|
||||||
// They'll just use a send indication instead.
|
// They'll just use a send indication instead.
|
||||||
|
|
||||||
@ -1561,7 +1779,11 @@ TEST_F(TurnPortTest, TestChannelBindGetErrorResponse) {
|
|||||||
rtc::Buffer(packet.payload().data(), packet.payload().size()));
|
rtc::Buffer(packet.payload().data(), packet.payload().size()));
|
||||||
});
|
});
|
||||||
conn1->Send(data.data(), data.length(), options);
|
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();
|
conn2->DeregisterReceivedPacketCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1597,7 +1819,11 @@ TEST_F(TurnPortTest, TestTurnLocalIPv6AddressServerIPv4) {
|
|||||||
CreateTurnPort(kLocalIPv6Addr, kTurnUsername, kTurnPassword,
|
CreateTurnPort(kLocalIPv6Addr, kTurnUsername, kTurnPassword,
|
||||||
kTurnUdpProtoAddr);
|
kTurnUdpProtoAddr);
|
||||||
turn_port_->PrepareAddress();
|
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());
|
EXPECT_TRUE(turn_port_->Candidates().empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1621,7 +1847,11 @@ TEST_F(TurnPortTest, TestCandidateAddressFamilyMatch) {
|
|||||||
CreateTurnPort(kLocalIPv6Addr, kTurnUsername, kTurnPassword,
|
CreateTurnPort(kLocalIPv6Addr, kTurnUsername, kTurnPassword,
|
||||||
kTurnUdpIPv6ProtoAddr);
|
kTurnUdpIPv6ProtoAddr);
|
||||||
turn_port_->PrepareAddress();
|
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());
|
ASSERT_EQ(1U, turn_port_->Candidates().size());
|
||||||
|
|
||||||
// Create an IPv4 candidate. It will match the TURN candidate.
|
// 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);
|
turn_server_.server()->set_reject_private_addresses(true);
|
||||||
CreateTurnPort(kTurnUsername, kTurnPassword, kTurnTcpProtoAddr);
|
CreateTurnPort(kTurnUsername, kTurnPassword, kTurnTcpProtoAddr);
|
||||||
turn_port_->PrepareAddress();
|
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));
|
CreateUdpPort(SocketAddress("10.0.0.10", 0));
|
||||||
udp_port_->PrepareAddress();
|
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.
|
// Create a connection.
|
||||||
TestConnectionWrapper conn(turn_port_->CreateConnection(
|
TestConnectionWrapper conn(turn_port_->CreateConnection(
|
||||||
udp_port_->Candidates()[0], Port::ORIGIN_MESSAGE));
|
udp_port_->Candidates()[0], Port::ORIGIN_MESSAGE));
|
||||||
@ -1659,10 +1897,18 @@ TEST_F(TurnPortTest, TestConnectionFailedAndPrunedOnCreatePermissionFailure) {
|
|||||||
|
|
||||||
// Asynchronously, CreatePermission request should be sent and fail, which
|
// Asynchronously, CreatePermission request should be sent and fail, which
|
||||||
// will make the connection pruned and failed.
|
// will make the connection pruned and failed.
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(CheckConnectionFailedAndPruned(conn.connection()),
|
EXPECT_THAT(
|
||||||
kSimulatedRtt, fake_clock_);
|
webrtc::WaitUntil(
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(!turn_create_permission_success_, kSimulatedRtt,
|
[&] { return CheckConnectionFailedAndPruned(conn.connection()); },
|
||||||
fake_clock_);
|
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.
|
// Check that the connection is not deleted asynchronously.
|
||||||
SIMULATED_WAIT(conn.connection() == nullptr, kConnectionDestructionDelay,
|
SIMULATED_WAIT(conn.connection() == nullptr, kConnectionDestructionDelay,
|
||||||
fake_clock_);
|
fake_clock_);
|
||||||
@ -1730,12 +1976,17 @@ TEST_F(TurnPortTest, TestResolverShutdown) {
|
|||||||
CreateTurnPort(kLocalIPv6Addr, kTurnUsername, kTurnPassword,
|
CreateTurnPort(kLocalIPv6Addr, kTurnUsername, kTurnPassword,
|
||||||
ProtocolAddress(kTurnInvalidAddr, PROTO_UDP));
|
ProtocolAddress(kTurnInvalidAddr, PROTO_UDP));
|
||||||
turn_port_->PrepareAddress();
|
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());
|
EXPECT_TRUE(turn_port_->Candidates().empty());
|
||||||
turn_port_.reset();
|
turn_port_.reset();
|
||||||
rtc::Thread::Current()->PostTask([this] { test_finish_ = true; });
|
rtc::Thread::Current()->PostTask([this] { test_finish_ = true; });
|
||||||
// Waiting for above message to be processed.
|
// 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());
|
EXPECT_EQ(last_fd_count, GetFDCount());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1924,9 +2175,12 @@ TEST_F(TurnPortTest, TestTurnDangerousAlternateServer) {
|
|||||||
|
|
||||||
turn_port_->PrepareAddress();
|
turn_port_->PrepareAddress();
|
||||||
// This should result in an error event.
|
// This should result in an error event.
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(error_event_.error_code != 0,
|
EXPECT_THAT(
|
||||||
TimeToGetAlternateTurnCandidate(protocol_type),
|
webrtc::WaitUntil([&] { return error_event_.error_code; }, Ne(0),
|
||||||
fake_clock_);
|
{.timeout = webrtc::TimeDelta::Millis(
|
||||||
|
TimeToGetAlternateTurnCandidate(protocol_type)),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
// but should NOT result in the port turning ready, and no candidates
|
// but should NOT result in the port turning ready, and no candidates
|
||||||
// should be gathered.
|
// should be gathered.
|
||||||
EXPECT_FALSE(turn_ready_);
|
EXPECT_FALSE(turn_ready_);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -28,6 +28,7 @@
|
|||||||
#include "api/crypto/crypto_options.h"
|
#include "api/crypto/crypto_options.h"
|
||||||
#include "api/dtls_transport_interface.h"
|
#include "api/dtls_transport_interface.h"
|
||||||
#include "api/scoped_refptr.h"
|
#include "api/scoped_refptr.h"
|
||||||
|
#include "api/test/rtc_error_matchers.h"
|
||||||
#include "api/units/time_delta.h"
|
#include "api/units/time_delta.h"
|
||||||
#include "p2p/base/fake_ice_transport.h"
|
#include "p2p/base/fake_ice_transport.h"
|
||||||
#include "p2p/base/packet_transport_internal.h"
|
#include "p2p/base/packet_transport_internal.h"
|
||||||
@ -39,7 +40,6 @@
|
|||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/copy_on_write_buffer.h"
|
#include "rtc_base/copy_on_write_buffer.h"
|
||||||
#include "rtc_base/fake_clock.h"
|
#include "rtc_base/fake_clock.h"
|
||||||
#include "rtc_base/gunit.h"
|
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "rtc_base/network/received_packet.h"
|
#include "rtc_base/network/received_packet.h"
|
||||||
#include "rtc_base/rtc_certificate.h"
|
#include "rtc_base/rtc_certificate.h"
|
||||||
@ -48,7 +48,9 @@
|
|||||||
#include "rtc_base/ssl_stream_adapter.h"
|
#include "rtc_base/ssl_stream_adapter.h"
|
||||||
#include "rtc_base/third_party/sigslot/sigslot.h"
|
#include "rtc_base/third_party/sigslot/sigslot.h"
|
||||||
#include "rtc_base/thread.h"
|
#include "rtc_base/thread.h"
|
||||||
|
#include "test/gmock.h"
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
|
#include "test/wait_until.h"
|
||||||
|
|
||||||
#define MAYBE_SKIP_TEST(feature) \
|
#define MAYBE_SKIP_TEST(feature) \
|
||||||
if (!(rtc::SSLStreamAdapter::feature())) { \
|
if (!(rtc::SSLStreamAdapter::feature())) { \
|
||||||
@ -58,6 +60,9 @@
|
|||||||
|
|
||||||
namespace cricket {
|
namespace cricket {
|
||||||
|
|
||||||
|
using ::testing::Eq;
|
||||||
|
using ::testing::IsTrue;
|
||||||
|
|
||||||
static const size_t kPacketNumOffset = 8;
|
static const size_t kPacketNumOffset = 8;
|
||||||
static const size_t kPacketHeaderLen = 12;
|
static const size_t kPacketHeaderLen = 12;
|
||||||
static const int kFakePacketId = 0x1234;
|
static const int kFakePacketId = 0x1234;
|
||||||
@ -380,9 +385,15 @@ class DtlsTransportTestBase {
|
|||||||
Negotiate(client1_server);
|
Negotiate(client1_server);
|
||||||
EXPECT_TRUE(client1_.Connect(&client2_, false));
|
EXPECT_TRUE(client1_.Connect(&client2_, false));
|
||||||
|
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(client1_.dtls_transport()->writable() &&
|
EXPECT_THAT(webrtc::WaitUntil(
|
||||||
client2_.dtls_transport()->writable(),
|
[&] {
|
||||||
kTimeout, fake_clock_);
|
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() ||
|
if (!client1_.dtls_transport()->writable() ||
|
||||||
!client2_.dtls_transport()->writable())
|
!client2_.dtls_transport()->writable())
|
||||||
return false;
|
return false;
|
||||||
@ -432,8 +443,11 @@ class DtlsTransportTestBase {
|
|||||||
RTC_LOG(LS_INFO) << "Expect packets, size=" << size;
|
RTC_LOG(LS_INFO) << "Expect packets, size=" << size;
|
||||||
client2_.ExpectPackets(size);
|
client2_.ExpectPackets(size);
|
||||||
client1_.SendPackets(size, count, srtp);
|
client1_.SendPackets(size, count, srtp);
|
||||||
EXPECT_EQ_SIMULATED_WAIT(count, client2_.NumPacketsReceived(), kTimeout,
|
EXPECT_THAT(webrtc::WaitUntil(
|
||||||
fake_clock_);
|
[&] { return client2_.NumPacketsReceived(); }, Eq(count),
|
||||||
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -630,9 +644,15 @@ class DtlsTransportVersionTest
|
|||||||
|
|
||||||
EXPECT_TRUE(client1_.Connect(&client2_, false));
|
EXPECT_TRUE(client1_.Connect(&client2_, false));
|
||||||
|
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(client1_.dtls_transport()->writable() &&
|
EXPECT_THAT(webrtc::WaitUntil(
|
||||||
client2_.dtls_transport()->writable(),
|
[&] {
|
||||||
kTimeout, fake_clock_);
|
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);
|
client1_.fake_ice_transport()->set_packet_send_filter(nullptr);
|
||||||
client2_.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();
|
||||||
Negotiate();
|
Negotiate();
|
||||||
EXPECT_TRUE(client1_.Connect(&client2_, false));
|
EXPECT_TRUE(client1_.Connect(&client2_, false));
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(client1_.dtls_transport()->writable() &&
|
EXPECT_THAT(webrtc::WaitUntil(
|
||||||
client2_.dtls_transport()->writable(),
|
[&] {
|
||||||
kTimeout, fake_clock_);
|
return client1_.dtls_transport()->writable() &&
|
||||||
|
client2_.dtls_transport()->writable();
|
||||||
|
},
|
||||||
|
IsTrue(),
|
||||||
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
TestTransfer(1000, 100, true);
|
TestTransfer(1000, 100, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -905,11 +931,18 @@ TEST_F(DtlsTransportTest, TestRetransmissionSchedule) {
|
|||||||
// Make client2_ writable, but not client1_.
|
// Make client2_ writable, but not client1_.
|
||||||
// This means client1_ will send DTLS client hellos but get no response.
|
// This means client1_ will send DTLS client hellos but get no response.
|
||||||
EXPECT_TRUE(client2_.Connect(&client1_, true));
|
EXPECT_TRUE(client2_.Connect(&client1_, true));
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(client2_.fake_ice_transport()->writable(),
|
EXPECT_THAT(
|
||||||
kTimeout, fake_clock_);
|
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.
|
// 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());
|
EXPECT_FALSE(client1_.fake_ice_transport()->writable());
|
||||||
|
|
||||||
static int timeout_schedule_ms[] = {50, 100, 200, 400, 800, 1600,
|
static int timeout_schedule_ms[] = {50, 100, 200, 400, 800, 1600,
|
||||||
@ -992,29 +1025,49 @@ class DtlsEventOrderingTest
|
|||||||
break;
|
break;
|
||||||
case CALLER_WRITABLE:
|
case CALLER_WRITABLE:
|
||||||
EXPECT_TRUE(client1_.Connect(&client2_, true));
|
EXPECT_TRUE(client1_.Connect(&client2_, true));
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(client1_.fake_ice_transport()->writable(),
|
EXPECT_THAT(
|
||||||
kTimeout, fake_clock_);
|
webrtc::WaitUntil(
|
||||||
|
[&] { return client1_.fake_ice_transport()->writable(); },
|
||||||
|
IsTrue(),
|
||||||
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
break;
|
break;
|
||||||
case CALLER_RECEIVES_CLIENTHELLO:
|
case CALLER_RECEIVES_CLIENTHELLO:
|
||||||
// Sanity check that a ClientHello hasn't already been received.
|
// Sanity check that a ClientHello hasn't already been received.
|
||||||
EXPECT_EQ(0, client1_.received_dtls_client_hellos());
|
EXPECT_EQ(0, client1_.received_dtls_client_hellos());
|
||||||
// Making client2_ writable will cause it to send the ClientHello.
|
// Making client2_ writable will cause it to send the ClientHello.
|
||||||
EXPECT_TRUE(client2_.Connect(&client1_, true));
|
EXPECT_TRUE(client2_.Connect(&client1_, true));
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(client2_.fake_ice_transport()->writable(),
|
EXPECT_THAT(
|
||||||
kTimeout, fake_clock_);
|
webrtc::WaitUntil(
|
||||||
EXPECT_EQ_SIMULATED_WAIT(1, client1_.received_dtls_client_hellos(),
|
[&] { return client2_.fake_ice_transport()->writable(); },
|
||||||
kTimeout, fake_clock_);
|
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;
|
break;
|
||||||
case HANDSHAKE_FINISHES:
|
case HANDSHAKE_FINISHES:
|
||||||
// Sanity check that the handshake hasn't already finished.
|
// Sanity check that the handshake hasn't already finished.
|
||||||
EXPECT_FALSE(client1_.dtls_transport()->IsDtlsConnected() ||
|
EXPECT_FALSE(client1_.dtls_transport()->IsDtlsConnected() ||
|
||||||
client1_.dtls_transport()->dtls_state() ==
|
client1_.dtls_transport()->dtls_state() ==
|
||||||
webrtc::DtlsTransportState::kFailed);
|
webrtc::DtlsTransportState::kFailed);
|
||||||
EXPECT_TRUE_SIMULATED_WAIT(
|
EXPECT_THAT(
|
||||||
client1_.dtls_transport()->IsDtlsConnected() ||
|
webrtc::WaitUntil(
|
||||||
client1_.dtls_transport()->dtls_state() ==
|
[&] {
|
||||||
webrtc::DtlsTransportState::kFailed,
|
return client1_.dtls_transport()->IsDtlsConnected() ||
|
||||||
kTimeout, fake_clock_);
|
client1_.dtls_transport()->dtls_state() ==
|
||||||
|
webrtc::DtlsTransportState::kFailed;
|
||||||
|
},
|
||||||
|
IsTrue(),
|
||||||
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout),
|
||||||
|
.clock = &fake_clock_}),
|
||||||
|
webrtc::IsRtcOk());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1022,12 +1075,18 @@ class DtlsEventOrderingTest
|
|||||||
webrtc::DtlsTransportState expected_final_state =
|
webrtc::DtlsTransportState expected_final_state =
|
||||||
valid_fingerprint ? webrtc::DtlsTransportState::kConnected
|
valid_fingerprint ? webrtc::DtlsTransportState::kConnected
|
||||||
: webrtc::DtlsTransportState::kFailed;
|
: webrtc::DtlsTransportState::kFailed;
|
||||||
EXPECT_EQ_SIMULATED_WAIT(expected_final_state,
|
EXPECT_THAT(webrtc::WaitUntil(
|
||||||
client1_.dtls_transport()->dtls_state(), kTimeout,
|
[&] { return client1_.dtls_transport()->dtls_state(); },
|
||||||
fake_clock_);
|
Eq(expected_final_state),
|
||||||
EXPECT_EQ_SIMULATED_WAIT(expected_final_state,
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout),
|
||||||
client2_.dtls_transport()->dtls_state(), kTimeout,
|
.clock = &fake_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.
|
// Transports should be writable iff there was a valid fingerprint.
|
||||||
EXPECT_EQ(valid_fingerprint, client1_.dtls_transport()->writable());
|
EXPECT_EQ(valid_fingerprint, client1_.dtls_transport()->writable());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user