Skip to content

Commit

Permalink
Merge pull request grpc#3677 from ctiller/port_server_be_flaky
Browse files Browse the repository at this point in the history
More robust port_server version checking
  • Loading branch information
nicolasnoble committed Oct 7, 2015
2 parents 39ec1e8 + fe4939f commit a3bb7f8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
19 changes: 14 additions & 5 deletions tools/run_tests/port_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@
import sys
import time


# increment this number whenever making a change to ensure that
# the changes are picked up by running CI servers
# note that all changes must be backwards compatible
_MY_VERSION = 2


if len(sys.argv) == 2 and sys.argv[1] == 'dump_version':
print _MY_VERSION
sys.exit(0)


argp = argparse.ArgumentParser(description='Server for httpcli_test')
argp.add_argument('-p', '--port', default=12345, type=int)
args = argp.parse_args()
Expand All @@ -47,9 +59,6 @@
pool = []
in_use = {}

with open(__file__) as f:
_MY_VERSION = hashlib.sha1(f.read()).hexdigest()


def refill_pool(max_timeout, req):
"""Scan for ports not marked for being in use"""
Expand Down Expand Up @@ -113,7 +122,7 @@ def do_GET(self):
del in_use[p]
pool.append(p)
self.log_message('drop port %d' % p)
elif self.path == '/version':
elif self.path == '/version_number':
# fetch a version string and the current process pid
self.send_response(200)
self.send_header('Content-Type', 'text/plain')
Expand All @@ -128,7 +137,7 @@ def do_GET(self):
self.end_headers()
now = time.time()
self.wfile.write(yaml.dump({'pool': pool, 'in_use': dict((k, now - v) for k, v in in_use.iteritems())}))
elif self.path == '/quit':
elif self.path == '/quitquitquit':
self.send_response(200)
self.end_headers()
keep_running = False
Expand Down
27 changes: 15 additions & 12 deletions tools/run_tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,21 +713,24 @@ def _start_port_server(port_server_port):
# if not running ==> start a new one
# otherwise, leave it up
try:
version = urllib2.urlopen('https://localhost:%d/version' % port_server_port,
timeout=1).read()
print 'detected port server running'
version = int(urllib2.urlopen(
'https://localhost:%d/version_number' % port_server_port,
timeout=1).read())
print 'detected port server running version %d' % version
running = True
except Exception:
except Exception as e:
print 'failed to detect port server: %s' % sys.exc_info()[0]
print e.strerror
running = False
if running:
with open('tools/run_tests/port_server.py') as f:
current_version = hashlib.sha1(f.read()).hexdigest()
running = (version == current_version)
if not running:
print 'port_server version mismatch: killing the old one'
urllib2.urlopen('https://localhost:%d/quit' % port_server_port).read()
time.sleep(1)
current_version = int(subprocess.check_output(
[sys.executable, 'tools/run_tests/port_server.py', 'dump_version']))
print 'my port server is version %d' % current_version
running = (version >= current_version)
if not running:
print 'port_server version mismatch: killing the old one'
urllib2.urlopen('https://localhost:%d/quitquitquit' % port_server_port).read()
time.sleep(1)
if not running:
print 'starting port_server'
port_log = open('portlog.txt', 'w')
Expand Down Expand Up @@ -773,7 +776,7 @@ def _build_and_run(
# start antagonists
antagonists = [subprocess.Popen(['tools/run_tests/antagonist.py'])
for _ in range(0, args.antagonists)]
port_server_port = 9999
port_server_port = 32767
_start_port_server(port_server_port)
try:
infinite_runs = runs_per_test == 0
Expand Down

0 comments on commit a3bb7f8

Please sign in to comment.