Skip to content

Commit 3544897

Browse files
authored
♻️ Maintenance: improve CI reliability + add healthcheck in migration service (ITISFoundation#3365)
1 parent 59c34d8 commit 3544897

File tree

10 files changed

+54
-7
lines changed

10 files changed

+54
-7
lines changed

packages/pytest-simcore/src/pytest_simcore/docker_compose.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ def testing_environ_vars(env_devel_file: Path) -> EnvVarsDict:
6666
"SWARM_STACK_NAME_NO_HYPHEN", env_devel["SWARM_STACK_NAME"].replace("-", "_")
6767
)
6868

69+
env_devel[
70+
"AIOCACHE_DISABLE"
71+
] = "1" # ensure that aio-caches are disabled for testing [https://aiocache.readthedocs.io/en/latest/testing.html]
72+
env_devel[
73+
"CATALOG_BACKGROUND_TASK_REST_TIME"
74+
] = "1" # ensure catalog refreshes services access rights fast
75+
6976
env_devel["DIRECTOR_REGISTRY_CACHING"] = "False"
7077
env_devel.setdefault("DIRECTOR_SERVICES_CUSTOM_CONSTRAINTS", "")
7178
env_devel.setdefault("DIRECTOR_SELF_SIGNED_SSL_SECRET_ID", "")

packages/simcore-sdk/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ tests-integration-ci: ## runs integration tests against local+production images
8080
--cov-report=xml \
8181
--cov=simcore_sdk \
8282
--durations=10 \
83+
--keep-docker-up \
8384
--log-date-format="%Y-%m-%d %H:%M:%S" \
84-
--log-format="%(asctime)s %(levelname)s %(message)s" \
8585
--verbose \
8686
-m "not heavy_load" \
87+
--log-format="%(asctime)s %(levelname)s %(message)s" \
8788
$(CURDIR)/tests/integration
8889

8990
tests: tests-unit tests-integration ## runs all tests

services/catalog/tests/unit/with_dbs/conftest.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import itertools
77
import random
88
from random import randint
9-
from typing import Any, AsyncIterator, Callable, Iterable, Iterator
9+
from typing import Any, AsyncIterator, Awaitable, Callable, Iterable, Iterator
1010

1111
import pytest
1212
import respx
@@ -24,6 +24,7 @@
2424
services_access_rights,
2525
services_meta_data,
2626
)
27+
from sqlalchemy import tuple_
2728
from sqlalchemy.dialects.postgresql import insert as pg_insert
2829
from sqlalchemy.ext.asyncio import AsyncEngine
2930
from starlette.testclient import TestClient
@@ -178,7 +179,7 @@ async def user_groups_ids(
178179
@pytest.fixture()
179180
async def services_db_tables_injector(
180181
sqlalchemy_async_engine: AsyncEngine,
181-
) -> AsyncIterator[Callable]:
182+
) -> AsyncIterator[Callable[[list[tuple]], Awaitable[None]]]:
182183
"""Returns a helper function to init
183184
services_meta_data and services_access_rights tables
184185
@@ -205,6 +206,7 @@ async def services_db_tables_injector(
205206
)
206207
"""
207208
# pylint: disable=no-value-for-parameter
209+
inserted_services: set[tuple[str, str]] = set()
208210

209211
async def inject_in_db(fake_catalog: list[tuple]):
210212
# [(service, ar1, ...), (service2, ar1, ...) ]
@@ -221,6 +223,7 @@ async def inject_in_db(fake_catalog: list[tuple]):
221223
set_=service,
222224
)
223225
await conn.execute(upsert_meta)
226+
inserted_services.add((service["key"], service["version"]))
224227

225228
for access_rights in itertools.chain(items[1:] for items in fake_catalog):
226229
stmt_access = services_access_rights.insert().values(access_rights)
@@ -229,8 +232,13 @@ async def inject_in_db(fake_catalog: list[tuple]):
229232
yield inject_in_db
230233

231234
async with sqlalchemy_async_engine.begin() as conn:
232-
await conn.execute(services_access_rights.delete())
233-
await conn.execute(services_meta_data.delete())
235+
await conn.execute(
236+
services_meta_data.delete().where(
237+
tuple_(services_meta_data.c.key, services_meta_data.c.version).in_(
238+
inserted_services
239+
)
240+
)
241+
)
234242

235243

236244
@pytest.fixture()

services/director-v2/tests/integration/02/test_mixed_dynamic_sidecar_and_legacy_project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ async def director_v2_client(
164164
monkeypatch.setenv("S3_ACCESS_KEY", minio_config["client"]["access_key"])
165165
monkeypatch.setenv("S3_SECRET_KEY", minio_config["client"]["secret_key"])
166166
monkeypatch.setenv("S3_BUCKET_NAME", minio_config["bucket_name"])
167-
monkeypatch.setenv("S3_SECURE", minio_config["client"]["secure"])
167+
monkeypatch.setenv("S3_SECURE", f"{minio_config['client']['secure']}")
168168

169169
# patch host for dynamic-sidecar, not reachable via localhost
170170
# the dynamic-sidecar (running inside a container) will use

services/migration/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,7 @@ USER ${SC_USER_NAME}
7474
# bring installed package without build tools
7575
COPY --from=build ${VIRTUAL_ENV} ${VIRTUAL_ENV}
7676
COPY --chown=scu:scu services/migration/docker services/migration/docker
77+
#, "| grep --regexp='^Rev: .* (head)$'" ]
78+
HEALTHCHECK --interval=10s --timeout=10s --start-period=1ms --retries=3 CMD [ "/bin/sh", "/home/scu/services/migration/docker/healthcheck.sh"]
7779

7880
ENTRYPOINT [ "/bin/sh", "services/migration/docker/entrypoint.sh" ]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
exec sc-pg info | grep --regexp='^Rev: .* (head)$'
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# pylint: disable=redefined-outer-name
2+
# pylint: disable=unused-argument
3+
# pylint: disable=unused-variable
4+
5+
6+
import pytest
7+
from pytest import MonkeyPatch
8+
9+
10+
@pytest.fixture
11+
def app_environment(
12+
app_environment: dict[str, str], monkeypatch: MonkeyPatch
13+
) -> dict[str, str]:
14+
# NOTE: overrides app_environment
15+
monkeypatch.setenv("WEBSERVER_GARBAGE_COLLECTOR", "null")
16+
return app_environment | {"WEBSERVER_GARBAGE_COLLECTOR": "null"}

services/web/server/tests/unit/with_dbs/02/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,21 @@
1616
ServiceResourcesDictHelpers,
1717
)
1818
from pydantic import parse_obj_as
19+
from pytest import MonkeyPatch
1920
from pytest_simcore.helpers.utils_assert import assert_status
2021
from pytest_simcore.helpers.utils_projects import NewProject, delete_all_projects
2122
from simcore_service_webserver import catalog
2223

2324

25+
@pytest.fixture
26+
def app_environment(
27+
app_environment: dict[str, str], monkeypatch: MonkeyPatch
28+
) -> dict[str, str]:
29+
# NOTE: overrides app_environment
30+
monkeypatch.setenv("WEBSERVER_GARBAGE_COLLECTOR", "null")
31+
return app_environment | {"WEBSERVER_GARBAGE_COLLECTOR": "null"}
32+
33+
2434
@pytest.fixture
2535
def mock_service_resources() -> ServiceResourcesDict:
2636
return parse_obj_as(

services/web/server/tests/unit/with_dbs/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from aiohttp import web
3131
from aiohttp.test_utils import TestClient, TestServer
3232
from pydantic import ByteSize, parse_obj_as
33+
from pytest_mock.plugin import MockerFixture
3334
from pytest_simcore.helpers.utils_dict import ConfigDict
3435
from pytest_simcore.helpers.utils_login import NewUser
3536
from servicelib.aiohttp.application_keys import APP_DB_ENGINE_KEY
@@ -254,7 +255,7 @@ def asyncpg_storage_system_mock(mocker):
254255

255256

256257
@pytest.fixture
257-
async def mocked_director_v2_api(mocker) -> dict[str, MagicMock]:
258+
async def mocked_director_v2_api(mocker: MockerFixture) -> dict[str, MagicMock]:
258259
mock = {}
259260

260261
#

0 commit comments

Comments
 (0)