Fix TestTurnServer to not depend on rtc::Thread::socketserver() accessor

Updated all calls to constructor to pass appropriate
rtc::SocketFactory explicitly.

Bug: webrtc:13145
Change-Id: Ibaa764c7eaffbdb8dd6825fd518c54b37316ecb8
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/238807
Auto-Submit: Niels Moller <nisse@webrtc.org>
Commit-Queue: Taylor Brandstetter <deadbeef@webrtc.org>
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35436}
This commit is contained in:
Niels Möller 2021-11-24 14:05:55 +01:00 committed by WebRTC LUCI CQ
parent bf7532116b
commit 6dd4997950
7 changed files with 29 additions and 22 deletions

View File

@ -265,7 +265,7 @@ class P2PTransportChannelTestBase : public ::testing::Test,
ss_(new rtc::FirewallSocketServer(nss_.get())),
main_(ss_.get()),
stun_server_(TestStunServer::Create(ss_.get(), kStunAddr)),
turn_server_(&main_, kTurnUdpIntAddr, kTurnUdpExtAddr),
turn_server_(&main_, ss_.get(), kTurnUdpIntAddr, kTurnUdpExtAddr),
socks_server1_(ss_.get(),
kSocksProxyAddrs[0],
ss_.get(),
@ -3498,6 +3498,8 @@ class P2PTransportChannelPingTest : public ::testing::Test,
}
}
rtc::SocketServer* ss() const { return vss_.get(); }
private:
std::unique_ptr<rtc::VirtualSocketServer> vss_;
rtc::AutoSocketServerThread thread_;
@ -4825,7 +4827,10 @@ class P2PTransportChannelMostLikelyToWorkFirstTest
: public P2PTransportChannelPingTest {
public:
P2PTransportChannelMostLikelyToWorkFirstTest()
: turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) {
: turn_server_(rtc::Thread::Current(),
ss(),
kTurnUdpIntAddr,
kTurnUdpExtAddr) {
network_manager_.AddInterface(kPublicAddrs[0]);
allocator_.reset(
CreateBasicPortAllocator(&network_manager_, ServerAddresses(),

View File

@ -402,7 +402,7 @@ class PortTest : public ::testing::Test, public sigslot::has_slots<> {
nat_socket_factory1_(&nat_factory1_),
nat_socket_factory2_(&nat_factory2_),
stun_server_(TestStunServer::Create(ss_.get(), kStunAddr)),
turn_server_(&main_, kTurnUdpIntAddr, kTurnUdpExtAddr),
turn_server_(&main_, ss_.get(), kTurnUdpIntAddr, kTurnUdpExtAddr),
username_(rtc::CreateRandomString(ICE_UFRAG_LENGTH)),
password_(rtc::CreateRandomString(ICE_PWD_LENGTH)),
role_conflict_(false),
@ -2591,7 +2591,7 @@ TEST_F(PortTest, TestCandidateFoundation) {
// Running a second turn server, to get different base IP address.
SocketAddress kTurnUdpIntAddr2("99.99.98.4", STUN_SERVER_PORT);
SocketAddress kTurnUdpExtAddr2("99.99.98.5", 0);
TestTurnServer turn_server2(rtc::Thread::Current(), kTurnUdpIntAddr2,
TestTurnServer turn_server2(rtc::Thread::Current(), vss(), kTurnUdpIntAddr2,
kTurnUdpExtAddr2);
auto turnport3 = CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP,
PROTO_UDP, kTurnUdpIntAddr2);
@ -2602,7 +2602,7 @@ TEST_F(PortTest, TestCandidateFoundation) {
// Start a TCP turn server, and check that two turn candidates have
// different foundations if their relay protocols are different.
TestTurnServer turn_server3(rtc::Thread::Current(), kTurnTcpIntAddr,
TestTurnServer turn_server3(rtc::Thread::Current(), vss(), kTurnTcpIntAddr,
kTurnUdpExtAddr, PROTO_TCP);
auto turnport4 =
CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_TCP, PROTO_UDP);

View File

@ -53,18 +53,16 @@ class TestTurnRedirector : public TurnRedirectInterface {
class TestTurnServer : public TurnAuthInterface {
public:
TestTurnServer(rtc::Thread* thread,
rtc::SocketFactory* socket_factory,
const rtc::SocketAddress& int_addr,
const rtc::SocketAddress& udp_ext_addr,
ProtocolType int_protocol = PROTO_UDP,
bool ignore_bad_cert = true,
const std::string& common_name = "test turn server")
: server_(thread), thread_(thread) {
: server_(thread), socket_factory_(socket_factory) {
AddInternalSocket(int_addr, int_protocol, ignore_bad_cert, common_name);
// TODO(bugs.webrtc.org/13145): Take a SocketFactory as argument, so we
// don't need thread_->socketserver().
server_.SetExternalSocketFactory(
new rtc::BasicPacketSocketFactory(thread_->socketserver()),
udp_ext_addr);
new rtc::BasicPacketSocketFactory(socket_factory), udp_ext_addr);
server_.set_realm(kTestRealm);
server_.set_software(kTestSoftware);
server_.set_auth_hook(this);
@ -99,13 +97,11 @@ class TestTurnServer : public TurnAuthInterface {
RTC_DCHECK(thread_checker_.IsCurrent());
if (proto == cricket::PROTO_UDP) {
server_.AddInternalSocket(
rtc::AsyncUDPSocket::Create(thread_->socketserver(), int_addr),
proto);
rtc::AsyncUDPSocket::Create(socket_factory_, int_addr), proto);
} else if (proto == cricket::PROTO_TCP || proto == cricket::PROTO_TLS) {
// For TCP we need to create a server socket which can listen for incoming
// new connections.
rtc::Socket* socket =
thread_->socketserver()->CreateSocket(AF_INET, SOCK_STREAM);
rtc::Socket* socket = socket_factory_->CreateSocket(AF_INET, SOCK_STREAM);
socket->Bind(int_addr);
socket->Listen(5);
if (proto == cricket::PROTO_TLS) {
@ -154,7 +150,7 @@ class TestTurnServer : public TurnAuthInterface {
}
TurnServer server_;
rtc::Thread* thread_;
rtc::SocketFactory* socket_factory_;
webrtc::SequenceChecker thread_checker_;
};

View File

@ -172,7 +172,7 @@ class TurnPortTest : public ::testing::Test,
: ss_(new TurnPortTestVirtualSocketServer()),
main_(ss_.get()),
socket_factory_(ss_.get()),
turn_server_(&main_, kTurnUdpIntAddr, kTurnUdpExtAddr),
turn_server_(&main_, ss_.get(), kTurnUdpIntAddr, kTurnUdpExtAddr),
turn_ready_(false),
turn_error_(false),
turn_unknown_address_(false),

View File

@ -153,7 +153,10 @@ class BasicPortAllocatorTestBase : public ::testing::Test,
nat_factory_(vss_.get(), kNatUdpAddr, kNatTcpAddr),
nat_socket_factory_(new rtc::BasicPacketSocketFactory(&nat_factory_)),
stun_server_(TestStunServer::Create(fss_.get(), kStunAddr)),
turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
turn_server_(rtc::Thread::Current(),
fss_.get(),
kTurnUdpIntAddr,
kTurnUdpExtAddr),
candidate_allocation_done_(false) {
ServerAddresses stun_servers;
stun_servers.insert(kStunAddr);

View File

@ -233,15 +233,16 @@ class PeerConnectionRampUpTest : public ::testing::Test {
void CreateTurnServer(cricket::ProtocolType type,
const std::string& common_name = "test turn server") {
rtc::Thread* thread = network_thread();
rtc::SocketFactory* factory = firewall_socket_server_.get();
std::unique_ptr<cricket::TestTurnServer> turn_server =
network_thread_->Invoke<std::unique_ptr<cricket::TestTurnServer>>(
RTC_FROM_HERE, [thread, type, common_name] {
RTC_FROM_HERE, [thread, factory, type, common_name] {
static const rtc::SocketAddress turn_server_internal_address{
kTurnInternalAddress, kTurnInternalPort};
static const rtc::SocketAddress turn_server_external_address{
kTurnExternalAddress, kTurnExternalPort};
return std::make_unique<cricket::TestTurnServer>(
thread, turn_server_internal_address,
thread, factory, turn_server_internal_address,
turn_server_external_address, type,
true /*ignore_bad_certs=*/, common_name);
});

View File

@ -1548,12 +1548,14 @@ class PeerConnectionIntegrationBaseTest : public ::testing::Test {
cricket::ProtocolType type = cricket::ProtocolType::PROTO_UDP,
const std::string& common_name = "test turn server") {
rtc::Thread* thread = network_thread();
rtc::SocketFactory* socket_factory = fss_.get();
std::unique_ptr<cricket::TestTurnServer> turn_server =
network_thread()->Invoke<std::unique_ptr<cricket::TestTurnServer>>(
RTC_FROM_HERE,
[thread, internal_address, external_address, type, common_name] {
RTC_FROM_HERE, [thread, socket_factory, internal_address,
external_address, type, common_name] {
return std::make_unique<cricket::TestTurnServer>(
thread, internal_address, external_address, type,
thread, socket_factory, internal_address, external_address,
type,
/*ignore_bad_certs=*/true, common_name);
});
turn_servers_.push_back(std::move(turn_server));