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
2.0
Zack Weinberg 2014-09-16 21:00:52 +00:00
parent 3d4f89b41e
commit 4d4aa42c94
1 changed files with 9 additions and 3 deletions

View File

@ -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