From 4d4aa42c9426989f4a36cbcd320ba0f56905391f Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Tue, 16 Sep 2014 21:00:52 +0000 Subject: [PATCH] Set SO_REUSEADDR on the test server's listening port. This means you don't have to wait 30 seconds in between invocations of run-tests.py. Also, if the test server fails to bind its port, print the actual OS-level error message rather than guessing what the problem is. issue #12439 --- test/run-tests.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/run-tests.py b/test/run-tests.py index bf6b78ac..3dcda116 100755 --- a/test/run-tests.py +++ b/test/run-tests.py @@ -140,6 +140,12 @@ class FileHandler(SimpleHTTPServer.SimpleHTTPRequestHandler, object): self._cached_translated_path = path return path +# This is how you are officially supposed to set SO_REUSEADDR per +# https://docs.python.org/2/library/socketserver.html#SocketServer.BaseServer.allow_reuse_address + +class TCPServer(SocketServer.TCPServer): + allow_reuse_address = True + def run_httpd(): global http_running handler = FileHandler @@ -151,12 +157,12 @@ def run_httpd(): '.json': 'application/json' }) try: - httpd = SocketServer.TCPServer(('', HTTP_PORT), handler) + httpd = TCPServer(('', HTTP_PORT), handler) while http_running: httpd.handle_request() - except socket.error: + except socket.error as e: print 'Fatal error: unable to launch a test server at port', HTTP_PORT - print 'Check that the port is not already used!' + print str(e) http_running = False sys.exit(1) return