IMPALA-8501: Fix race condition on port in RpcMgrTest

RpcMgrTest previously would choose a random, unused port when starting
and then eventually start a krpc service on the port. This resulted in
a race condition where the port could be taken by another process
between when it was chosen and when RpcMgrTest actually used it,
causing RpcMgrTest to fail.

This patch significantly reduces the probability of such an error
happening by choosing the port immediately before it is used.

Change-Id: I841196f8557f29816f5f2960f36fc7772233b975
Reviewed-on: http://gerrit.cloudera.org:8080/14997
Reviewed-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
diff --git a/be/src/rpc/rpc-mgr-test.h b/be/src/rpc/rpc-mgr-test.h
index f559409..8f4871a 100644
--- a/be/src/rpc/rpc-mgr-test.h
+++ b/be/src/rpc/rpc-mgr-test.h
@@ -67,8 +67,6 @@
 
 namespace impala {
 
-static int32_t SERVICE_PORT = FindUnusedEphemeralPort();
-
 const static string IMPALA_HOME(getenv("IMPALA_HOME"));
 const string& SERVER_CERT =
     Substitute("$0/be/src/testutil/server-cert.pem", IMPALA_HOME);
@@ -137,7 +135,7 @@
   virtual void SetUp() {
     IpAddr ip;
     ASSERT_OK(HostnameToIpAddr(FLAGS_hostname, &ip));
-    krpc_address_ = MakeNetworkAddress(ip, SERVICE_PORT);
+    krpc_address_ = MakeNetworkAddress(ip, FindUnusedEphemeralPort());
     exec_env_.reset(new ExecEnv());
     ASSERT_OK(rpc_mgr_.Init(krpc_address_));
   }