fix(tests runtime):

This commit is contained in:
Alexander Myasoedov
2025-12-09 20:00:04 +02:00
parent b9dc5de708
commit d56b406e1a
5 changed files with 59 additions and 17 deletions
+21 -3
View File
@@ -1,6 +1,7 @@
import importlib
import os
import signal
import socket
import subprocess
import tempfile
import time
@@ -24,12 +25,29 @@ def test_server(request):
preexec_fn=lambda: signal.signal(signal.SIGINT, signal.SIG_IGN),
)
# Give the server time to start
time.sleep(2)
def wait_for_port(host: str, port: int, timeout: float = 5.0) -> bool:
start = time.time()
while time.time() - start < timeout:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.settimeout(0.2)
try:
sock.connect((host, port))
return True
except OSError:
time.sleep(0.1)
return False
if not wait_for_port("127.0.0.1", 9094):
server.kill()
pytest.skip("Test server failed to start within timeout")
def cleanup():
server.terminate()
server.wait()
try:
server.wait(timeout=3)
except subprocess.TimeoutExpired:
server.kill()
server.wait(timeout=2)
request.addfinalizer(cleanup)
return server