From f43de5f6119376b0114c89e1e9faf8d8fafa1f45 Mon Sep 17 00:00:00 2001 From: John Sirois Date: Fri, 12 Feb 2016 16:15:43 -0700 Subject: [PATCH] THRIFT-3621 Fix lib/cpp/test/SecurityTest.cpp to use ephemeral ports Instead of using a fixed port, use an ephemeral port to improve robustness and make way for parallelizability. --- lib/cpp/test/SecurityTest.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/cpp/test/SecurityTest.cpp b/lib/cpp/test/SecurityTest.cpp index 5e9dfe47549..9968e2c4785 100644 --- a/lib/cpp/test/SecurityTest.cpp +++ b/lib/cpp/test/SecurityTest.cpp @@ -29,7 +29,6 @@ #include #include #include -#include "TestPortFixture.h" #include #ifdef __linux__ #include @@ -95,7 +94,7 @@ BOOST_GLOBAL_FIXTURE(GlobalFixture); BOOST_GLOBAL_FIXTURE(GlobalFixture) #endif -struct SecurityFixture : public TestPortFixture +struct SecurityFixture { void server(apache::thrift::transport::SSLProtocol protocol) { @@ -111,12 +110,13 @@ struct SecurityFixture : public TestPortFixture pServerSocketFactory->loadCertificate(certFile("server.crt").string().c_str()); pServerSocketFactory->loadPrivateKey(certFile("server.key").string().c_str()); pServerSocketFactory->server(true); - pServerSocket.reset(new TSSLServerSocket("localhost", m_serverPort, pServerSocketFactory)); + pServerSocket.reset(new TSSLServerSocket("localhost", 0, pServerSocketFactory)); boost::shared_ptr connectedClient; try { pServerSocket->listen(); + mPort = pServerSocket->getPort(); mCVar.notify_one(); lock.unlock(); @@ -163,7 +163,7 @@ struct SecurityFixture : public TestPortFixture pClientSocketFactory->loadCertificate(certFile("client.crt").string().c_str()); pClientSocketFactory->loadPrivateKey(certFile("client.key").string().c_str()); pClientSocketFactory->loadTrustedCertificates(certFile("CA.pem").string().c_str()); - pClientSocket = pClientSocketFactory->createSocket("localhost", m_serverPort); + pClientSocket = pClientSocketFactory->createSocket("localhost", mPort); pClientSocket->open(); uint8_t buf[3]; @@ -207,6 +207,7 @@ struct SecurityFixture : public TestPortFixture boost::mutex mMutex; boost::condition_variable mCVar; + int mPort; bool mConnected; };