Merge pull request #3309 from quay/less-flaky-tests
Add automatic retry to the registry test suite to make it less flaky
This commit is contained in:
commit
bf3fe2bfd6
1 changed files with 27 additions and 17 deletions
|
@ -59,12 +59,18 @@ class liveFlaskServer(object):
|
|||
socketserver.TCPServer.server_bind = socket_bind_wrapper
|
||||
app.run(port=port, use_reloader=False)
|
||||
|
||||
retry_count = self.app.config.get('LIVESERVER_RETRY_COUNT', 3)
|
||||
started = False
|
||||
for _ in range(0, retry_count):
|
||||
if started:
|
||||
break
|
||||
|
||||
self._process = multiprocessing.Process(target=worker, args=(self.app, 0))
|
||||
self._process.start()
|
||||
|
||||
# We must wait for the server to start listening, but give up
|
||||
# after a specified maximum timeout
|
||||
timeout = self.app.config.get('LIVESERVER_TIMEOUT', 5)
|
||||
timeout = self.app.config.get('LIVESERVER_TIMEOUT', 10)
|
||||
start_time = time.time()
|
||||
|
||||
while True:
|
||||
|
@ -72,12 +78,16 @@ class liveFlaskServer(object):
|
|||
|
||||
elapsed_time = (time.time() - start_time)
|
||||
if elapsed_time > timeout:
|
||||
raise RuntimeError("Failed to start the server after %d seconds. " % timeout)
|
||||
break
|
||||
|
||||
if self._can_connect():
|
||||
self.app.config['SERVER_HOSTNAME'] = 'localhost:%s' % self._port_value.value
|
||||
started = True
|
||||
break
|
||||
|
||||
if not started:
|
||||
raise RuntimeError("Failed to start the server after %d retries. " % retry_count)
|
||||
|
||||
def _can_connect(self):
|
||||
host, port = self._get_server_address()
|
||||
if port == 0:
|
||||
|
|
Reference in a new issue