Skip to content

Commit 0d92121

Browse files
author
Andrei Neagu
committed
adding check to see that API is responsive
1 parent b9da94d commit 0d92121

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

packages/service-library/src/servicelib/docker_utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import aiodocker
1010
import aiohttp
1111
import arrow
12+
import tenacity
1213
from aiohttp import ClientSession
1314
from fastapi import FastAPI
1415
from models_library.docker import DockerGenericTag
@@ -332,11 +333,23 @@ async def _(app: FastAPI) -> AsyncIterator[None]:
332333

333334
app.state.remote_docker_client = client
334335

336+
await wait_till_docker_api_proxy_is_responsive(app)
337+
335338
yield
336339

337340
return _
338341

339342

343+
@tenacity.retry(
344+
wait=tenacity.wait_fixed(5),
345+
stop=tenacity.stop_after_delay(60),
346+
before_sleep=tenacity.before_sleep_log(_logger, logging.INFO),
347+
reraise=True,
348+
)
349+
async def wait_till_docker_api_proxy_is_responsive(app: FastAPI) -> None:
350+
await get_remote_docker_client(app).version()
351+
352+
340353
def get_remote_docker_client(app: FastAPI) -> aiodocker.Docker:
341354
assert isinstance(app.state.remote_docker_client, aiodocker.Docker) # nosec
342355
return app.state.remote_docker_client

services/docker-api-proxy/tests/integration/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async def _(env_vars: EnvVarsDict) -> AsyncIterator[aiodocker.Docker]:
5959

6060
app = _get_test_app()
6161

62-
async with LifespanManager(app):
62+
async with LifespanManager(app, startup_timeout=30, shutdown_timeout=30):
6363
yield get_remote_docker_client(app)
6464

6565
return _

services/docker-api-proxy/tests/integration/test_docker_api_proxy_autenticated.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import aiodocker
1212
import pytest
13+
from pytest_mock import MockerFixture
1314
from pytest_simcore.helpers.monkeypatch_envs import EnvVarsDict
1415
from settings_library.docker_api_proxy import DockerApiProxysettings
1516
from tenacity import AsyncRetrying, stop_after_delay, wait_fixed
@@ -45,8 +46,14 @@ def caddy_file() -> str:
4546
"""
4647

4748

49+
@pytest.fixture
50+
def mock_wait_till_docker_api_proxy_is_responsive(mocker: MockerFixture) -> None:
51+
mocker.patch("servicelib.docker_utils.wait_till_docker_api_proxy_is_responsive")
52+
53+
4854
@pytest.fixture
4955
def authentication_proxy(
56+
mock_wait_till_docker_api_proxy_is_responsive: None,
5057
docker_swarm: None,
5158
docker_api_proxy_settings: DockerApiProxysettings,
5259
caddy_file: str,

0 commit comments

Comments
 (0)