Skip to content

Commit

Permalink
wait for uvicorn server to bind before running tests
Browse files Browse the repository at this point in the history
Previously we had a simple `time.sleep(1)` call after `server.start()`
which was present to give the Mint's HTTP server time to spin up during
test runs. This meant that if the server took longer than 1s to start
on a dev's machine for any reason (even intermittently) then tests would
fail due to connection errors.

The fix is to use a simple repeated polling check which allows
the test runner to start only once the server is confirmed listening.
  • Loading branch information
conduition committed Aug 1, 2024
1 parent 77ba356 commit 2e58fe6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
settings.cashu_dir = "./test_data/"
settings.mint_host = "localhost"
settings.mint_port = SERVER_PORT
settings.mint_host = "0.0.0.0"
settings.mint_listen_port = SERVER_PORT
settings.mint_url = SERVER_ENDPOINT
settings.tor = False
Expand Down Expand Up @@ -139,6 +138,16 @@ def mint():

server = UvicornServer(config=config)
server.start()
time.sleep(1)

# Wait until the server has bound to the localhost socket. Max out after 10s.
tries = 0
while tries < 100:
try:
httpx.get(settings.mint_url)
except:
tries += 1
time.sleep(0.1)


yield server
server.stop()

0 comments on commit 2e58fe6

Please sign in to comment.