Apache DataFusion SQL Query Engine
ARROW-8176: [FlightRPC] bind to a free port for integration tests
David Licfd731172996
diff --git a/dev/archery/archery/integration/runner.py b/dev/archery/archery/integration/runner.pyindex e6d3c42f6a..1395868054 100644--- a/dev/archery/archery/integration/runner.py+++ b/dev/archery/archery/integration/runner.py@@ -31,7 +31,7 @@ from .tester_go import GoTesterfrom .tester_java import JavaTesterfrom .tester_js import JSTesterfrom .util import (ARROW_ROOT_DEFAULT, guid, SKIP_ARROW, SKIP_FLIGHT,- find_unused_port, printer)+ printer)from . import datagen@@ -280,8 +280,7 @@ class IntegrationRunner(object):else:try:- port = find_unused_port()- with producer.flight_server(port):+ with producer.flight_server() as port:# Have the client upload the file, then download and# compareconsumer.flight_request(port, json_path)diff --git a/dev/archery/archery/integration/tester.py b/dev/archery/archery/integration/tester.pyindex 85ed2214d4..298298e4ef 100644--- a/dev/archery/archery/integration/tester.py+++ b/dev/archery/archery/integration/tester.py@@ -50,7 +50,12 @@ class Tester(object):def validate(self, json_path, arrow_path):raise NotImplementedError- def flight_server(self, port):+ def flight_server(self):+ """Start the Flight server on a free port.++ This should be a context manager that returns the port as the+ managed object, and cleans up the server on exit.+ """raise NotImplementedErrordef flight_request(self, port, json_path):diff --git a/dev/archery/archery/integration/tester_cpp.py b/dev/archery/archery/integration/tester_cpp.pyindex f0fd3fc286..fed3f0904a 100644--- a/dev/archery/archery/integration/tester_cpp.py+++ b/dev/archery/archery/integration/tester_cpp.py@@ -76,8 +76,8 @@ class CPPTester(Tester):self.run_shell_command(cmd)@contextlib.contextmanager- def flight_server(self, port):- cmd = self.FLIGHT_SERVER_CMD + ['-port=' + str(port)]+ def flight_server(self):+ cmd = self.FLIGHT_SERVER_CMD + ['-port=0']if self.debug:log(' '.join(cmd))server = subprocess.Popen(cmd,@@ -85,14 +85,15 @@ class CPPTester(Tester):stderr=subprocess.PIPE)try:output = server.stdout.readline().decode()- if not output.startswith("Server listening on localhost"):+ if not output.startswith("Server listening on localhost:"):server.kill()out, err = server.communicate()raise RuntimeError("Flight-C++ server did not start properly, ""stdout:\n{}\n\nstderr:\n{}\n".format(output + out.decode(), err.decode()))- yield+ port = int(output.split(":")[1])+ yield portfinally:server.kill()server.wait(5)diff --git a/dev/archery/archery/integration/tester_java.py b/dev/archery/archery/integration/tester_java.pyindex bdfe3429ce..1c8e960cd9 100644--- a/dev/archery/archery/integration/tester_java.py+++ b/dev/archery/archery/integration/tester_java.py@@ -105,24 +105,25 @@ class JavaTester(Tester):run_cmd(cmd)@contextlib.contextmanager- def flight_server(self, port):+ def flight_server(self):cmd = ['java'] + self.JAVA_OPTS + \['-cp', self.ARROW_FLIGHT_JAR, self.ARROW_FLIGHT_SERVER,- '-port', str(port)]+ '-port', '0']if self.debug:log(' '.join(cmd))server = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE)try:output = server.stdout.readline().decode()- if not output.startswith("Server listening on localhost"):+ if not output.startswith("Server listening on localhost:"):server.kill()out, err = server.communicate()raise RuntimeError("Flight-Java server did not start properly, ""stdout:\n{}\n\nstderr:\n{}\n".format(output + out.decode(), err.decode()))- yield+ port = int(output.split(":")[1])+ yield portfinally:server.kill()server.wait(5)