THRIFT-3624 Fix lib/cpp/test/TServerSocketTest.cpp to use ephemeral ports.
Client: Test (C++)
Patch: John Sirois

Instead of using a fixed port, use an ephemeral port to improve
robustness and make way for parallelizability.

This closes #855
diff --git a/lib/cpp/test/TServerSocketTest.cpp b/lib/cpp/test/TServerSocketTest.cpp
index ae87ba8..1da5d36 100644
--- a/lib/cpp/test/TServerSocketTest.cpp
+++ b/lib/cpp/test/TServerSocketTest.cpp
@@ -20,7 +20,6 @@
 #include <boost/test/auto_unit_test.hpp>
 #include <thrift/transport/TSocket.h>
 #include <thrift/transport/TServerSocket.h>
-#include "TestPortFixture.h"
 #include "TTransportCheckThrow.h"
 #include <iostream>
 
@@ -29,19 +28,20 @@
 using apache::thrift::transport::TTransport;
 using apache::thrift::transport::TTransportException;
 
-BOOST_FIXTURE_TEST_SUITE(TServerSocketTest, TestPortFixture)
+BOOST_AUTO_TEST_SUITE(TServerSocketTest)
 
 BOOST_AUTO_TEST_CASE(test_bind_to_address) {
-  TServerSocket sock1("localhost", m_serverPort);
+  TServerSocket sock1("localhost", 0);
   sock1.listen();
-  TSocket clientSock("localhost", m_serverPort);
+  int port = sock1.getPort();
+  TSocket clientSock("localhost", port);
   clientSock.open();
   boost::shared_ptr<TTransport> accepted = sock1.accept();
   accepted->close();
   sock1.close();
 
   std::cout << "An error message from getaddrinfo on the console is expected:" << std::endl;
-  TServerSocket sock2("257.258.259.260", m_serverPort);
+  TServerSocket sock2("257.258.259.260", 0);
   BOOST_CHECK_THROW(sock2.listen(), TTransportException);
   sock2.close();
 }
@@ -55,7 +55,7 @@
 }
 
 BOOST_AUTO_TEST_CASE(test_close_before_listen) {
-  TServerSocket sock1("localhost", m_serverPort);
+  TServerSocket sock1("localhost", 0);
   sock1.close();
 }