Skip to content
Snippets Groups Projects
Commit b67ed000 authored by Craig Tiller's avatar Craig Tiller Committed by GitHub
Browse files

Merge pull request #11012 from ctiller/fps

Fix port server on Windows
parents 20f2c431 e21d2c1c
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python #!/usr/bin/env python2.7
# Copyright 2015, Google Inc. # Copyright 2015, Google Inc.
# All rights reserved. # All rights reserved.
# #
...@@ -30,8 +30,6 @@ ...@@ -30,8 +30,6 @@
"""Manage TCP ports for unit tests; started by run_tests.py""" """Manage TCP ports for unit tests; started by run_tests.py"""
from __future__ import print_function
import argparse import argparse
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
import hashlib import hashlib
...@@ -42,16 +40,17 @@ import time ...@@ -42,16 +40,17 @@ import time
import random import random
from SocketServer import ThreadingMixIn from SocketServer import ThreadingMixIn
import threading import threading
import platform
# increment this number whenever making a change to ensure that # increment this number whenever making a change to ensure that
# the changes are picked up by running CI servers # the changes are picked up by running CI servers
# note that all changes must be backwards compatible # note that all changes must be backwards compatible
_MY_VERSION = 19 _MY_VERSION = 20
if len(sys.argv) == 2 and sys.argv[1] == 'dump_version': if len(sys.argv) == 2 and sys.argv[1] == 'dump_version':
print(_MY_VERSION) print _MY_VERSION
sys.exit(0) sys.exit(0)
...@@ -67,13 +66,16 @@ if args.logfile is not None: ...@@ -67,13 +66,16 @@ if args.logfile is not None:
sys.stderr = open(args.logfile, 'w') sys.stderr = open(args.logfile, 'w')
sys.stdout = sys.stderr sys.stdout = sys.stderr
print('port server running on port %d' % args.port) print 'port server running on port %d' % args.port
pool = [] pool = []
in_use = {} in_use = {}
mu = threading.Lock() mu = threading.Lock()
def can_connect(port): def can_connect(port):
# this test is only really useful on unices where SO_REUSE_PORT is available
# so on Windows, where this test is expensive, skip it
if platform.system() == 'Windows': return False
s = socket.socket() s = socket.socket()
try: try:
s.connect(('localhost', port)) s.connect(('localhost', port))
...@@ -137,7 +139,7 @@ keep_running = True ...@@ -137,7 +139,7 @@ keep_running = True
class Handler(BaseHTTPRequestHandler): class Handler(BaseHTTPRequestHandler):
def setup(self): def setup(self):
# If the client is unreachable for 5 seconds, close the connection # If the client is unreachable for 5 seconds, close the connection
self.timeout = 5 self.timeout = 5
...@@ -195,6 +197,4 @@ class Handler(BaseHTTPRequestHandler): ...@@ -195,6 +197,4 @@ class Handler(BaseHTTPRequestHandler):
class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
"""Handle requests in a separate thread""" """Handle requests in a separate thread"""
ThreadedHTTPServer(('', args.port), Handler).serve_forever() ThreadedHTTPServer(('', args.port), Handler).serve_forever()
...@@ -27,9 +27,7 @@ ...@@ -27,9 +27,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function import urllib
from six.moves import urllib
import jobset import jobset
import logging import logging
import os import os
...@@ -50,9 +48,9 @@ def start_port_server(): ...@@ -50,9 +48,9 @@ def start_port_server():
# otherwise, leave it up # otherwise, leave it up
try: try:
version = int( version = int(
urllib.request.urlopen( urllib.urlopen(
'http://localhost:%d/version_number' % _PORT_SERVER_PORT, 'http://localhost:%d/version_number' %
timeout=10).read()) _PORT_SERVER_PORT).read())
logging.info('detected port server running version %d', version) logging.info('detected port server running version %d', version)
running = True running = True
except Exception as e: except Exception as e:
...@@ -69,8 +67,8 @@ def start_port_server(): ...@@ -69,8 +67,8 @@ def start_port_server():
running = (version >= current_version) running = (version >= current_version)
if not running: if not running:
logging.info('port_server version mismatch: killing the old one') logging.info('port_server version mismatch: killing the old one')
urllib.request.urlopen('http://localhost:%d/quitquitquit' % urllib.urlopen('http://localhost:%d/quitquitquit' %
_PORT_SERVER_PORT).read() _PORT_SERVER_PORT).read()
time.sleep(1) time.sleep(1)
if not running: if not running:
fd, logfile = tempfile.mkstemp() fd, logfile = tempfile.mkstemp()
...@@ -109,9 +107,8 @@ def start_port_server(): ...@@ -109,9 +107,8 @@ def start_port_server():
# try one final time: maybe another build managed to start one # try one final time: maybe another build managed to start one
time.sleep(1) time.sleep(1)
try: try:
urllib.request.urlopen( urllib.urlopen(
'http://localhost:%d/get' % _PORT_SERVER_PORT, 'http://localhost:%d/get' % _PORT_SERVER_PORT).read()
timeout=1).read()
logging.info( logging.info(
'last ditch attempt to contact port server succeeded') 'last ditch attempt to contact port server succeeded')
break break
...@@ -119,18 +116,18 @@ def start_port_server(): ...@@ -119,18 +116,18 @@ def start_port_server():
logging.exception( logging.exception(
'final attempt to contact port server failed') 'final attempt to contact port server failed')
port_log = open(logfile, 'r').read() port_log = open(logfile, 'r').read()
print(port_log) print port_log
sys.exit(1) sys.exit(1)
try: try:
port_server_url = 'http://localhost:%d/get' % _PORT_SERVER_PORT port_server_url = 'http://localhost:%d/get' % _PORT_SERVER_PORT
urllib.request.urlopen(port_server_url, timeout=1).read() urllib.urlopen(port_server_url).read()
logging.info('port server is up and ready') logging.info('port server is up and ready')
break break
except socket.timeout: except socket.timeout:
logging.exception('while waiting for port_server') logging.exception('while waiting for port_server')
time.sleep(1) time.sleep(1)
waits += 1 waits += 1
except urllib.error.URLError: except IOError:
logging.exception('while waiting for port_server') logging.exception('while waiting for port_server')
time.sleep(1) time.sleep(1)
waits += 1 waits += 1
......
#!/usr/bin/env python #!/usr/bin/env python2.7
# Copyright 2017, Google Inc. # Copyright 2017, Google Inc.
# All rights reserved. # All rights reserved.
...@@ -39,10 +39,8 @@ The path to this file is called out in test/core/util/port.c, and printed as ...@@ -39,10 +39,8 @@ The path to this file is called out in test/core/util/port.c, and printed as
an error message to users. an error message to users.
""" """
from __future__ import print_function
import python_utils.start_port_server as start_port_server import python_utils.start_port_server as start_port_server
start_port_server.start_port_server() start_port_server.start_port_server()
print("Port server started successfully") print "Port server started successfully"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment