Intermediate step: Move ownership of rtc::NetworkManager to test code from PC E2E framework

Bug: webrtc:10138
Change-Id: I9b751a1c28d8533cce238d64b8f8c76eabdab5eb
Reviewed-on: https://webrtc-review.googlesource.com/c/125182
Reviewed-by: Peter Slatala <psla@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26927}
This commit is contained in:
Artem Titov 2019-03-01 15:12:22 +01:00 committed by Commit Bot
parent 547a1dceef
commit 4765013541
4 changed files with 23 additions and 37 deletions

View File

@ -73,7 +73,12 @@ class PeerConnectionE2EQualityTestFixture {
// so client can't inject its own. Also only network manager can be overridden
// inside port allocator.
struct PeerConnectionComponents {
std::unique_ptr<rtc::NetworkManager> network_manager;
PeerConnectionComponents(rtc::NetworkManager* network_manager)
: network_manager(network_manager) {
RTC_CHECK(network_manager);
}
rtc::NetworkManager* const network_manager;
std::unique_ptr<webrtc::AsyncResolverFactory> async_resolver_factory;
std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier;
@ -82,11 +87,13 @@ class PeerConnectionE2EQualityTestFixture {
// Contains all components, that can be overridden in peer connection. Also
// has a network thread, that will be used to communicate with another peers.
struct InjectableComponents {
explicit InjectableComponents(rtc::Thread* network_thread)
explicit InjectableComponents(rtc::Thread* network_thread,
rtc::NetworkManager* network_manager)
: network_thread(network_thread),
pcf_dependencies(
absl::make_unique<PeerConnectionFactoryComponents>()),
pc_dependencies(absl::make_unique<PeerConnectionComponents>()) {
pc_dependencies(
absl::make_unique<PeerConnectionComponents>(network_manager)) {
RTC_CHECK(network_thread);
}

View File

@ -96,14 +96,14 @@ TEST(PeerConnectionE2EQualityTestSmokeTest, RunWithEmulatedNetwork) {
// Setup components. We need to provide rtc::NetworkManager compatible with
// emulated network layer.
auto alice_components =
absl::make_unique<InjectableComponents>(alice_network_thread);
alice_components->pc_dependencies->network_manager =
std::unique_ptr<rtc::NetworkManager> alice_network_manager =
CreateFakeNetworkManager({alice_endpoint});
auto bob_components =
absl::make_unique<InjectableComponents>(bob_network_thread);
bob_components->pc_dependencies->network_manager =
auto alice_components = absl::make_unique<InjectableComponents>(
alice_network_thread, alice_network_manager.get());
std::unique_ptr<rtc::NetworkManager> bob_network_manager =
CreateFakeNetworkManager({bob_endpoint});
auto bob_components = absl::make_unique<InjectableComponents>(
bob_network_thread, bob_network_manager.get());
// Create analyzers.
std::unique_ptr<VideoQualityAnalyzerInterface> video_quality_analyzer =

View File

@ -47,13 +47,8 @@ using AudioConfig = PeerConnectionE2EQualityTestFixture::AudioConfig;
// dependencies, that won't be specially provided by factory and will be just
// transferred to peer connection creation code.
void SetMandatoryEntities(InjectableComponents* components) {
if (components->pcf_dependencies == nullptr) {
components->pcf_dependencies =
absl::make_unique<PeerConnectionFactoryComponents>();
}
if (components->pc_dependencies == nullptr) {
components->pc_dependencies = absl::make_unique<PeerConnectionComponents>();
}
RTC_DCHECK(components->pcf_dependencies);
RTC_DCHECK(components->pc_dependencies);
// Setup required peer connection factory dependencies.
if (components->pcf_dependencies->call_factory == nullptr) {
@ -209,16 +204,8 @@ PeerConnectionDependencies CreatePCDependencies(
PeerConnectionObserver* observer) {
PeerConnectionDependencies pc_deps(observer);
// We need to create network manager, because it is required for port
// allocator. TestPeer will take ownership of this object and will store it
// until the end of the test.
if (pc_dependencies->network_manager == nullptr) {
pc_dependencies->network_manager =
// Use real network (on the loopback interface)
absl::make_unique<rtc::BasicNetworkManager>();
}
auto port_allocator = absl::make_unique<cricket::BasicPortAllocator>(
pc_dependencies->network_manager.get());
pc_dependencies->network_manager);
// This test does not support TCP
int flags = cricket::PORTALLOCATOR_DISABLE_TCP;
@ -281,8 +268,7 @@ std::unique_ptr<TestPeer> TestPeer::CreateTestPeer(
pcf->CreatePeerConnection(params->rtc_configuration, std::move(pc_deps));
return absl::WrapUnique(
new TestPeer(pcf, pc, std::move(observer), std::move(params),
std::move(components->pc_dependencies->network_manager)));
new TestPeer(pcf, pc, std::move(observer), std::move(params)));
}
bool TestPeer::AddIceCandidates(
@ -305,13 +291,11 @@ TestPeer::TestPeer(
rtc::scoped_refptr<PeerConnectionFactoryInterface> pc_factory,
rtc::scoped_refptr<PeerConnectionInterface> pc,
std::unique_ptr<MockPeerConnectionObserver> observer,
std::unique_ptr<Params> params,
std::unique_ptr<rtc::NetworkManager> network_manager)
std::unique_ptr<Params> params)
: PeerConnectionWrapper::PeerConnectionWrapper(std::move(pc_factory),
std::move(pc),
std::move(observer)),
params_(std::move(params)),
network_manager_(std::move(network_manager)) {}
params_(std::move(params)) {}
} // namespace test
} // namespace webrtc

View File

@ -67,14 +67,9 @@ class TestPeer final : public PeerConnectionWrapper {
TestPeer(rtc::scoped_refptr<PeerConnectionFactoryInterface> pc_factory,
rtc::scoped_refptr<PeerConnectionInterface> pc,
std::unique_ptr<MockPeerConnectionObserver> observer,
std::unique_ptr<Params> params,
std::unique_ptr<rtc::NetworkManager> network_manager);
std::unique_ptr<Params> params);
std::unique_ptr<Params> params_;
// Test peer will take ownership of network manager and keep it during the
// call. Network manager will be deleted before peer connection, but
// connection will be closed before destruction, so it should be ok.
std::unique_ptr<rtc::NetworkManager> network_manager_;
};
} // namespace test