dynamic waiting for server to be ready in tests
This commit is contained in:
parent
1a1ece1f95
commit
c372529ee5
@ -2,6 +2,8 @@
|
||||
[run]
|
||||
branch = True
|
||||
parallel = True
|
||||
command_line = -m pytest
|
||||
concurrency = multiprocessing
|
||||
omit =
|
||||
*/site-packages/*
|
||||
*/distutils/*
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
import socket
|
||||
from multiprocessing import Process
|
||||
from time import sleep
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
from funcy import retry, complement
|
||||
|
||||
from image_prediction.flask import make_prediction_server, run_prediction_server
|
||||
|
||||
@ -47,14 +49,24 @@ def host_and_port(host, port, server):
|
||||
return {"host": host, "port": port}
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def server_process(server, host_and_port):
|
||||
@retry(tries=5, timeout=1)
|
||||
def server_ready(url):
|
||||
response = requests.get(f"{url}/ready")
|
||||
response.raise_for_status()
|
||||
return response.status_code == 200
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, scope="function")
|
||||
def server_process(server, host_and_port, url):
|
||||
def get_server_process():
|
||||
return Process(target=run_prediction_server, kwargs={"app": server, **host_and_port})
|
||||
|
||||
server = get_server_process()
|
||||
server.start()
|
||||
yield
|
||||
|
||||
if server_ready(url):
|
||||
yield
|
||||
|
||||
server.terminate()
|
||||
|
||||
|
||||
@ -71,6 +83,4 @@ def test_server_health_check(url):
|
||||
|
||||
|
||||
def test_server_ready_check(url):
|
||||
response = requests.get(f"{url}/ready")
|
||||
response.raise_for_status()
|
||||
assert response.status_code == 200
|
||||
assert server_ready(url)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user