-
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
168 additions
and
31 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
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
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,30 @@ | ||
import time | ||
|
||
import requests | ||
|
||
|
||
def random_port(): | ||
""" | ||
Return a random available port. | ||
""" | ||
import socket | ||
|
||
sock = socket.socket() | ||
sock.bind(("", 0)) | ||
port = sock.getsockname()[1] | ||
sock.close() | ||
return port | ||
|
||
|
||
def wait_server(port: int): | ||
""" | ||
Wait for server to be ready. | ||
""" | ||
for _ in range(20): # 2 second timeout | ||
try: | ||
requests.get(f"http://127.0.0.1:{port}/", timeout=0.1) | ||
break | ||
except requests.exceptions.RequestException: | ||
time.sleep(0.1) | ||
else: | ||
raise RuntimeError("Server failed to start") |