Skip to content

Commit 70362cf

Browse files
author
Andrei Neagu
committed
refactred test
1 parent 74e261e commit 70362cf

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

services/director-v2/tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ async def client(mock_env: EnvVarsDict) -> AsyncIterator[TestClient]:
208208
async def initialized_app(mock_env: EnvVarsDict) -> AsyncIterable[FastAPI]:
209209
settings = AppSettings.create_from_envs()
210210
app = init_app(settings)
211+
print("Application settings\n", settings.json(indent=2))
211212
async with LifespanManager(app):
212213
yield app
213214

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,18 @@ def mock_env(
6565
minio_s3_settings_envs: EnvVarsDict,
6666
storage_service: URL,
6767
network_name: str,
68+
services_endpoint: dict[str, URL],
6869
) -> EnvVarsDict:
70+
director_host = services_endpoint["director"].host
71+
assert director_host
72+
director_port = services_endpoint["director"].port
73+
assert director_port
74+
75+
catalog_host = services_endpoint["catalog"].host
76+
assert catalog_host
77+
catalog_port = services_endpoint["catalog"].port
78+
assert catalog_port
79+
6980
env_vars: EnvVarsDict = {
7081
"DYNAMIC_SIDECAR_PROMETHEUS_SERVICE_LABELS": "{}",
7182
"TRAEFIK_SIMCORE_ZONE": "test_traefik_zone",
@@ -81,6 +92,10 @@ def mock_env(
8192
"COMPUTATIONAL_BACKEND_ENABLED": "false",
8293
"R_CLONE_PROVIDER": "MINIO",
8394
"DIRECTOR_V2_PROMETHEUS_INSTRUMENTATION_ENABLED": "1",
95+
"DIRECTOR_HOST": director_host,
96+
"DIRECTOR_PORT": f"{director_port}",
97+
"CATALOG_HOST": catalog_host,
98+
"CATALOG_PORT": f"{catalog_port}",
8499
}
85100
setenvs_from_dict(monkeypatch, env_vars)
86101
monkeypatch.delenv("DYNAMIC_SIDECAR_MOUNT_PATH_DEV", raising=False)
@@ -159,7 +174,7 @@ def _assemble_node_data(spec: dict, label: str) -> dict[str, str]:
159174
@pytest.fixture
160175
async def ensure_services_stopped(
161176
dy_static_file_server_project: ProjectAtDB,
162-
minimal_app: FastAPI,
177+
initialized_app: FastAPI,
163178
) -> AsyncIterable[None]:
164179
yield
165180
# ensure service cleanup when done testing
@@ -178,7 +193,7 @@ async def ensure_services_stopped(
178193

179194
# pylint: disable=protected-access
180195
scheduler_interval = (
181-
minimal_app.state.settings.DYNAMIC_SERVICES.DYNAMIC_SCHEDULER.DIRECTOR_V2_DYNAMIC_SCHEDULER_INTERVAL
196+
initialized_app.state.settings.DYNAMIC_SERVICES.DYNAMIC_SCHEDULER.DIRECTOR_V2_DYNAMIC_SCHEDULER_INTERVAL
182197
)
183198
# sleep enough to ensure the observation cycle properly stopped the service
184199
await asyncio.sleep(2 * scheduler_interval.total_seconds())
@@ -213,9 +228,8 @@ async def _mocked_context_manger(*args, **kwargs) -> AsyncIterator[None]:
213228
)
214229

215230

216-
@pytest.mark.flaky(max_runs=3)
217231
async def test_legacy_and_dynamic_sidecar_run(
218-
minimal_app: FastAPI,
232+
initialized_app: FastAPI,
219233
wait_for_catalog_service: Callable[[UserID, str], Awaitable[None]],
220234
dy_static_file_server_project: ProjectAtDB,
221235
user_dict: dict[str, Any],
@@ -264,13 +278,7 @@ async def test_legacy_and_dynamic_sidecar_run(
264278
if is_legacy(node):
265279
continue
266280

267-
# NOTE: it seems the minimal_app fixture does not contain the actual data
268-
# so we use the one in the async_client??? very strange
269-
await patch_dynamic_service_url(
270-
# pylint: disable=protected-access
271-
app=async_client._transport.app, # noqa: SLF001 # type: ignore
272-
node_uuid=node_id,
273-
)
281+
await patch_dynamic_service_url(app=initialized_app, node_uuid=node_id)
274282

275283
assert len(dy_static_file_server_project.workbench) == 3
276284

services/director-v2/tests/unit/with_dbs/test_cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def mock_save_service_state(mocker: MockerFixture) -> None:
8181
mocker.patch(
8282
"simcore_service_director_v2.modules.dynamic_sidecar.api_client._public.SidecarsClient.save_service_state",
8383
spec=True,
84+
return_value=0,
8485
)
8586

8687

0 commit comments

Comments
 (0)