-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests: Fix server/client not loaded yet race (getting connection errors)
- Loading branch information
Showing
3 changed files
with
29 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import requests | ||
import time | ||
|
||
|
||
def wait_for_server(port: int, timeout: int = 2): | ||
""" | ||
Waits for the http server (of either the server or the client) to be available | ||
""" | ||
start = time.time() | ||
while time.time() - start < timeout: | ||
try: | ||
# Assumes both server and client have "/" route | ||
requests.get(f"http://localhost:{port}/") | ||
return | ||
except requests.exceptions.ConnectionError: | ||
time.sleep(0.1) | ||
raise TimeoutError(f"Server did not start within {timeout} seconds") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters