Skip to content

Commit

Permalink
wait for the server to start rather than sleeping a fixed time
Browse files Browse the repository at this point in the history
  • Loading branch information
emilybache committed Mar 9, 2023
1 parent cfd9bbb commit 0fbfe8c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions python/test/test_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@ def server(port):
app.run(port=port)


def wait_for_server_to_start(server_url):

This comment has been minimized.

Copy link
@nitsanavni

nitsanavni Mar 9, 2023

🧡

started = False
while not started:
try:
requests.get(server_url)
started = True
except Exception as e:
time.sleep(0.2)


@pytest.fixture(autouse=True, scope="session")
def lift_pass_pricing_app():
""" starts the lift pass pricing flask app running on localhost """
p = multiprocessing.Process(target=server, args=(TEST_PORT,))
p.start()
# we need to give it time to start - one second usually seems to be enough
time.sleep(1)
yield f"http://127.0.0.1:{TEST_PORT}"
server_url = f"http://127.0.0.1:{TEST_PORT}"
wait_for_server_to_start(server_url)
yield server_url
p.terminate()


Expand Down

0 comments on commit 0fbfe8c

Please sign in to comment.