Skip to content

Commit de93669

Browse files
committed
improving test
1 parent 1c6c25c commit de93669

File tree

4 files changed

+62
-31
lines changed

4 files changed

+62
-31
lines changed

services/autoscaling/tests/unit/conftest.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
Resources,
3131
)
3232
from common_library.json_serialization import json_dumps
33+
from dask_task_models_library.container_tasks.utils import generate_dask_job_id
3334
from deepdiff import DeepDiff
3435
from faker import Faker
3536
from fakeredis.aioredis import FakeRedis
@@ -52,7 +53,11 @@
5253
Service,
5354
TaskSpec,
5455
)
56+
from models_library.projects import ProjectID
57+
from models_library.projects_nodes_io import NodeID
5558
from models_library.services_metadata_runtime import SimcoreContainerLabels
59+
from models_library.services_types import ServiceKey, ServiceVersion
60+
from models_library.users import UserID
5661
from pydantic import ByteSize, NonNegativeInt, PositiveInt, TypeAdapter
5762
from pytest_mock import MockType
5863
from pytest_mock.plugin import MockerFixture
@@ -857,9 +862,55 @@ def _creator(**cluter_overrides) -> Cluster:
857862
return _creator
858863

859864

865+
@pytest.fixture
866+
def service_version() -> ServiceVersion:
867+
return "1.0.234"
868+
869+
870+
@pytest.fixture
871+
def service_key() -> ServiceKey:
872+
return "simcore/services/dynamic/test"
873+
874+
875+
@pytest.fixture
876+
def node_id(faker: Faker) -> NodeID:
877+
return faker.uuid4(cast_to=None)
878+
879+
880+
@pytest.fixture
881+
def project_id(faker: Faker) -> ProjectID:
882+
return faker.uuid4(cast_to=None)
883+
884+
885+
@pytest.fixture
886+
def user_id(faker: Faker) -> UserID:
887+
return faker.pyint(min_value=1)
888+
889+
890+
@pytest.fixture
891+
def fake_dask_job_id(
892+
service_key: ServiceKey,
893+
service_version: ServiceVersion,
894+
user_id: UserID,
895+
project_id: ProjectID,
896+
faker: Faker,
897+
) -> Callable[[], str]:
898+
def _() -> str:
899+
return generate_dask_job_id(
900+
service_key=service_key,
901+
service_version=service_version,
902+
user_id=user_id,
903+
project_id=project_id,
904+
node_id=faker.uuid4(cast_to=None),
905+
)
906+
907+
return _
908+
909+
860910
@pytest.fixture
861911
async def create_dask_task(
862912
dask_spec_cluster_client: distributed.Client,
913+
fake_dask_job_id: Callable[[], str],
863914
) -> Callable[..., distributed.Future]:
864915
def _remote_pytest_fct(x: int, y: int) -> int:
865916
return x + y
@@ -874,6 +925,7 @@ def _creator(
874925
43,
875926
resources=required_resources,
876927
pure=False,
928+
key=fake_dask_job_id(),
877929
**overrides,
878930
)
879931
assert future

services/autoscaling/tests/unit/test_modules_cluster_scaling_computational.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,14 @@ def _assert_rabbit_autoscaling_message_sent(
126126
instances_running=0,
127127
)
128128
expected_message = default_message.model_copy(update=message_update_kwargs)
129-
mock_rabbitmq_post_message.assert_called_once_with(
130-
app,
131-
expected_message,
132-
)
129+
# in this mock we get all kind of messages, we just want to assert one of them is the expected one and there is only one
130+
autoscaling_status_messages = [
131+
call_args.args[1]
132+
for call_args in mock_rabbitmq_post_message.call_args_list
133+
if isinstance(call_args.args[1], RabbitAutoscalingStatusMessage)
134+
]
135+
assert len(autoscaling_status_messages) == 1, "too many messages sent"
136+
assert autoscaling_status_messages[0] == expected_message
133137

134138

135139
@pytest.fixture

services/autoscaling/tests/unit/test_modules_dask.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ async def test_list_unrunnable_tasks(
124124
# we have nothing running now
125125
assert await list_unrunnable_tasks(scheduler_url, scheduler_authentication) == []
126126
# start a task that cannot run
127-
dask_task_impossible_resources = DaskTaskResources(XRAM=213, threads=1)
127+
dask_task_impossible_resources = DaskTaskResources(XRAM=213, threads=1) # type: ignore
128128
future = create_dask_task(dask_task_impossible_resources)
129129
assert future
130130
assert await list_unrunnable_tasks(scheduler_url, scheduler_authentication) == [
@@ -168,7 +168,7 @@ def _add_fct(x: int, y: int) -> int:
168168
next(iter(dask_spec_cluster_client.scheduler_info()["workers"])): [
169169
DaskTask(
170170
task_id=DaskTaskId(future_queued_task.key),
171-
required_resources=DaskTaskResources(threads=1),
171+
required_resources=DaskTaskResources(threads=1), # type: ignore
172172
)
173173
]
174174
}

services/autoscaling/tests/unit/test_utils_rabbitmq.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -122,31 +122,6 @@ async def _(labels: dict[DockerLabelKey, str]) -> list[Task]:
122122
return _
123123

124124

125-
@pytest.fixture
126-
def service_version() -> ServiceVersion:
127-
return "1.0.0"
128-
129-
130-
@pytest.fixture
131-
def service_key() -> ServiceKey:
132-
return "simcore/services/dynamic/test"
133-
134-
135-
@pytest.fixture
136-
def node_id(faker: Faker) -> NodeID:
137-
return faker.uuid4(cast_to=None)
138-
139-
140-
@pytest.fixture
141-
def project_id(faker: Faker) -> ProjectID:
142-
return faker.uuid4(cast_to=None)
143-
144-
145-
@pytest.fixture
146-
def user_id(faker: Faker) -> UserID:
147-
return faker.pyint(min_value=1)
148-
149-
150125
@pytest.fixture
151126
def dask_task(
152127
service_key: ServiceKey,

0 commit comments

Comments
 (0)