Skip to content

Commit fe1ee67

Browse files
committed
the test now runs
1 parent 4ddb842 commit fe1ee67

File tree

1 file changed

+37
-26
lines changed

1 file changed

+37
-26
lines changed

services/director-v2/tests/unit/test_modules_dask_client.py

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# pylint: disable=reimported
77
import asyncio
88
import functools
9+
import logging
910
import traceback
1011
from collections.abc import AsyncIterator, Awaitable, Callable, Coroutine
1112
from dataclasses import dataclass
@@ -49,6 +50,7 @@
4950
from models_library.users import UserID
5051
from pydantic import AnyUrl, ByteSize, TypeAdapter
5152
from pytest_mock.plugin import MockerFixture
53+
from pytest_simcore.helpers.logging_tools import log_context
5254
from pytest_simcore.helpers.typing_env import EnvVarsDict
5355
from settings_library.s3 import S3Settings
5456
from simcore_sdk.node_ports_v2 import FileLinkType
@@ -140,41 +142,48 @@ def _minimal_dask_config(
140142
@pytest.fixture
141143
async def create_dask_client_from_scheduler(
142144
_minimal_dask_config: None,
143-
dask_spec_local_cluster: SpecCluster,
145+
dask_spec_local_cluster: distributed.SpecCluster,
144146
minimal_app: FastAPI,
145147
tasks_file_link_type: FileLinkType,
146148
) -> AsyncIterator[Callable[[], Awaitable[DaskClient]]]:
147149
created_clients = []
148150

149151
async def factory() -> DaskClient:
150-
client = await DaskClient.create(
151-
app=minimal_app,
152-
settings=minimal_app.state.settings.DIRECTOR_V2_COMPUTATIONAL_BACKEND,
153-
endpoint=TypeAdapter(AnyUrl).validate_python(
154-
dask_spec_local_cluster.scheduler_address
155-
),
156-
authentication=NoAuthentication(),
157-
tasks_file_link_type=tasks_file_link_type,
158-
cluster_type=ClusterTypeInModel.ON_PREMISE,
159-
)
160-
assert client
161-
assert client.app == minimal_app
162-
assert (
163-
client.settings
164-
== minimal_app.state.settings.DIRECTOR_V2_COMPUTATIONAL_BACKEND
165-
)
152+
with log_context(
153+
logging.INFO,
154+
f"Create director-v2 DaskClient to {dask_spec_local_cluster.scheduler_address}",
155+
) as ctx:
156+
client = await DaskClient.create(
157+
app=minimal_app,
158+
settings=minimal_app.state.settings.DIRECTOR_V2_COMPUTATIONAL_BACKEND,
159+
endpoint=TypeAdapter(AnyUrl).validate_python(
160+
dask_spec_local_cluster.scheduler_address
161+
),
162+
authentication=NoAuthentication(),
163+
tasks_file_link_type=tasks_file_link_type,
164+
cluster_type=ClusterTypeInModel.ON_PREMISE,
165+
)
166+
assert client
167+
assert client.app == minimal_app
168+
assert (
169+
client.settings
170+
== minimal_app.state.settings.DIRECTOR_V2_COMPUTATIONAL_BACKEND
171+
)
172+
173+
assert client.backend.client
174+
scheduler_infos = client.backend.client.scheduler_info() # type: ignore
175+
ctx.logger.info(
176+
"%s",
177+
f"--> Connected to scheduler via client {client=} to scheduler {scheduler_infos=}",
178+
)
166179

167-
assert client.backend.client
168-
scheduler_infos = client.backend.client.scheduler_info() # type: ignore
169-
print(
170-
f"--> Connected to scheduler via client {client=} to scheduler {scheduler_infos=}"
171-
)
172180
created_clients.append(client)
173181
return client
174182

175183
yield factory
176-
await asyncio.gather(*[client.delete() for client in created_clients])
177-
print(f"<-- Disconnected scheduler clients {created_clients=}")
184+
185+
with log_context(logging.INFO, "Disconnect scheduler clients"):
186+
await asyncio.gather(*[client.delete() for client in created_clients])
178187

179188

180189
@pytest.fixture(params=["create_dask_client_from_scheduler"])
@@ -728,15 +737,17 @@ def fake_remote_fct(
728737
with pytest.raises(TaskCancelledError):
729738
await dask_client.get_task_result(published_computation_task[0].job_id)
730739

731-
# after releasing the results, the task shall be UNKNOWN
740+
await asyncio.sleep(5)
732741
await dask_client.release_task_result(published_computation_task[0].job_id)
742+
# after releasing the results, the task shall be UNKNOWN
743+
733744
# NOTE: this change of status takes a very long time to happen and is not relied upon so we skip it since it
734745
# makes the test fail a lot for no gain (it's kept here in case it ever becomes an issue)
735746
await _assert_wait_for_task_status(
736747
published_computation_task[0].job_id,
737748
dask_client,
738749
RunningState.UNKNOWN,
739-
timeout=120,
750+
timeout=10,
740751
)
741752

742753

0 commit comments

Comments
 (0)