Skip to content

Commit

Permalink
update according to change requests - ensuring that test won't run en…
Browse files Browse the repository at this point in the history
…dlessly if the server does not start properly
  • Loading branch information
thomasstorm committed Jan 16, 2024
1 parent 3c231f4 commit be57273
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions xcube/server/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import urllib3
from tornado.platform.asyncio import AnyThreadEventLoopPolicy
from urllib3.exceptions import MaxRetryError

from xcube.server.server import Server
from xcube.server.webservers.tornado import TornadoFramework
Expand Down Expand Up @@ -66,13 +67,20 @@ def setUp(self) -> None:

self.http = urllib3.PoolManager()

# Taking care that server is fully started until tests make requests.
# Fixing https://github.com/dcs4cop/xcube/issues/899
elapsed_time = 0.0
while True:
# noinspection PyBroadException
if elapsed_time > 60:
self.fail('Server did not respond after one minute. '
'Failing the test.')
try:
self.fetch('/')
break
except Exception:
time.sleep(0.1)
except (MaxRetryError, TimeoutError):
sleep_time = 0.1
time.sleep(sleep_time)
elapsed_time += sleep_time

def tearDown(self) -> None:
self.server.stop()
Expand Down

0 comments on commit be57273

Please sign in to comment.