Fix parallelization in libjingle_p2p_unittest.

Adding VirtualSocketServers to SessionTest and RelayServerTest to avoid
contention on real ports.

R=juberti@webrtc.org
BUG=2597
TEST=third_party/gtest-parallel/gtest-parallel -w 64 out/Debug/libjingle_p2p_unittest

Review URL: https://webrtc-codereview.appspot.com/26679004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7355 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
pbos@webrtc.org 2014-10-01 12:31:31 +00:00
parent c86e45d7c4
commit fd29205e6e
2 changed files with 24 additions and 10 deletions

View File

@ -36,6 +36,7 @@
#include "webrtc/base/ssladapter.h"
#include "webrtc/base/testclient.h"
#include "webrtc/base/thread.h"
#include "webrtc/base/virtualsocketserver.h"
using rtc::SocketAddress;
using namespace cricket;
@ -54,23 +55,25 @@ static const char* msg2 = "Lobster Thermidor a Crevette with a mornay sauce...";
class RelayServerTest : public testing::Test {
public:
RelayServerTest()
: main_(rtc::Thread::Current()), ss_(main_->socketserver()),
: pss_(new rtc::PhysicalSocketServer),
ss_(new rtc::VirtualSocketServer(pss_.get())),
ss_scope_(ss_.get()),
username_(rtc::CreateRandomString(12)),
password_(rtc::CreateRandomString(12)) {
}
password_(rtc::CreateRandomString(12)) {}
protected:
virtual void SetUp() {
server_.reset(new RelayServer(main_));
server_.reset(new RelayServer(rtc::Thread::Current()));
server_->AddInternalSocket(
rtc::AsyncUDPSocket::Create(ss_, server_int_addr));
rtc::AsyncUDPSocket::Create(ss_.get(), server_int_addr));
server_->AddExternalSocket(
rtc::AsyncUDPSocket::Create(ss_, server_ext_addr));
rtc::AsyncUDPSocket::Create(ss_.get(), server_ext_addr));
client1_.reset(new rtc::TestClient(
rtc::AsyncUDPSocket::Create(ss_, client1_addr)));
rtc::AsyncUDPSocket::Create(ss_.get(), client1_addr)));
client2_.reset(new rtc::TestClient(
rtc::AsyncUDPSocket::Create(ss_, client2_addr)));
rtc::AsyncUDPSocket::Create(ss_.get(), client2_addr)));
}
void Allocate() {
@ -176,8 +179,9 @@ class RelayServerTest : public testing::Test {
msg->AddAttribute(attr);
}
rtc::Thread* main_;
rtc::SocketServer* ss_;
rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
rtc::scoped_ptr<rtc::VirtualSocketServer> ss_;
rtc::SocketServerScope ss_scope_;
rtc::scoped_ptr<RelayServer> server_;
rtc::scoped_ptr<rtc::TestClient> client1_;
rtc::scoped_ptr<rtc::TestClient> client2_;

View File

@ -54,7 +54,9 @@
#include "webrtc/base/logging.h"
#include "webrtc/base/natserver.h"
#include "webrtc/base/natsocketfactory.h"
#include "webrtc/base/physicalsocketserver.h"
#include "webrtc/base/stringencode.h"
#include "webrtc/base/virtualsocketserver.h"
using cricket::SignalingProtocol;
using cricket::PROTOCOL_HYBRID;
@ -1121,6 +1123,10 @@ class TestClient : public sigslot::has_slots<> {
class SessionTest : public testing::Test {
protected:
SessionTest()
: pss_(new rtc::PhysicalSocketServer),
ss_(new rtc::VirtualSocketServer(pss_.get())),
ss_scope_(ss_.get()) {}
virtual void SetUp() {
// Seed needed for each test to satisfy expectations.
rtc::SetRandomTestMode(true);
@ -2276,6 +2282,10 @@ class SessionTest : public testing::Test {
EXPECT_EQ(2ul, stats.proxy_to_transport.size());
EXPECT_EQ(2ul, stats.transport_stats.size());
}
rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
rtc::scoped_ptr<rtc::VirtualSocketServer> ss_;
rtc::SocketServerScope ss_scope_;
};
// For each of these, "X => Y = Z" means "if a client with protocol X