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