Skip to content

Commit 33ef9db

Browse files
fix test
1 parent ee061d4 commit 33ef9db

File tree

4 files changed

+50
-14
lines changed

4 files changed

+50
-14
lines changed

services/director-v2/tests/unit/with_dbs/comp_scheduler/test_db_repositories_comp_runs.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ async def test_list_group_by_collection_run_id(
587587
total_count, items = await CompRunsRepository(
588588
sqlalchemy_async_engine
589589
).list_group_by_collection_run_id(
590-
product_name=run_metadata.get("product_name", "osparc"),
590+
product_name=run_metadata.get("product_name"),
591591
user_id=published_project_1.user["id"],
592592
offset=0,
593593
limit=10,
@@ -682,7 +682,7 @@ async def test_list_group_by_collection_run_id_with_mixed_states_returns_started
682682

683683
# Test the list_group_by_collection_run_id function
684684
total_count, items = await repo.list_group_by_collection_run_id(
685-
product_name=run_metadata.get("product_name", "osparc"),
685+
product_name=run_metadata.get("product_name"),
686686
user_id=published_project_1.user["id"],
687687
offset=0,
688688
limit=10,
@@ -748,7 +748,7 @@ async def test_list_group_by_collection_run_id_all_success_returns_success(
748748

749749
# Test the function
750750
total_count, items = await repo.list_group_by_collection_run_id(
751-
product_name=run_metadata.get("product_name", "osparc"),
751+
product_name=run_metadata.get("product_name"),
752752
user_id=published_project_1.user["id"],
753753
offset=0,
754754
limit=10,
@@ -815,7 +815,7 @@ async def test_list_group_by_collection_run_id_with_failed_returns_failed(
815815

816816
# Test the function
817817
total_count, items = await repo.list_group_by_collection_run_id(
818-
product_name=run_metadata.get("product_name", "osparc"),
818+
product_name=run_metadata.get("product_name"),
819819
user_id=published_project_1.user["id"],
820820
offset=0,
821821
limit=10,
@@ -880,7 +880,7 @@ async def test_list_group_by_collection_run_id_with_aborted_returns_aborted(
880880

881881
# Test the function
882882
total_count, items = await repo.list_group_by_collection_run_id(
883-
product_name=run_metadata.get("product_name", "osparc"),
883+
product_name=run_metadata.get("product_name"),
884884
user_id=published_project_1.user["id"],
885885
offset=0,
886886
limit=10,
@@ -945,7 +945,7 @@ async def test_list_group_by_collection_run_id_with_unknown_returns_unknown(
945945

946946
# Test the function
947947
total_count, items = await repo.list_group_by_collection_run_id(
948-
product_name=run_metadata.get("product_name", "osparc"),
948+
product_name=run_metadata.get("product_name"),
949949
user_id=published_project_1.user["id"],
950950
offset=0,
951951
limit=10,
@@ -1004,7 +1004,7 @@ async def test_list_group_by_collection_run_id_with_project_filter(
10041004

10051005
# Test with project filter for only first two projects
10061006
total_count, items = await repo.list_group_by_collection_run_id(
1007-
product_name=run_metadata.get("product_name", "osparc"),
1007+
product_name=run_metadata.get("product_name"),
10081008
user_id=published_project_1.user["id"],
10091009
project_ids=[
10101010
published_project_1.project.uuid,
@@ -1051,7 +1051,7 @@ async def test_list_group_by_collection_run_id_pagination(
10511051

10521052
# Test first page
10531053
total_count, items = await repo.list_group_by_collection_run_id(
1054-
product_name=run_metadata.get("product_name", "osparc"),
1054+
product_name=run_metadata.get("product_name"),
10551055
user_id=published_project.user["id"],
10561056
offset=0,
10571057
limit=2,
@@ -1062,7 +1062,7 @@ async def test_list_group_by_collection_run_id_pagination(
10621062

10631063
# Test second page
10641064
total_count, items = await repo.list_group_by_collection_run_id(
1065-
product_name=run_metadata.get("product_name", "osparc"),
1065+
product_name=run_metadata.get("product_name"),
10661066
user_id=published_project.user["id"],
10671067
offset=2,
10681068
limit=2,
@@ -1073,7 +1073,7 @@ async def test_list_group_by_collection_run_id_pagination(
10731073

10741074
# Test last page
10751075
total_count, items = await repo.list_group_by_collection_run_id(
1076-
product_name=run_metadata.get("product_name", "osparc"),
1076+
product_name=run_metadata.get("product_name"),
10771077
user_id=published_project.user["id"],
10781078
offset=4,
10791079
limit=2,
@@ -1092,7 +1092,7 @@ async def test_list_group_by_collection_run_id_empty_result(
10921092
repo = CompRunsRepository(sqlalchemy_async_engine)
10931093

10941094
total_count, items = await repo.list_group_by_collection_run_id(
1095-
product_name=run_metadata.get("product_name", "osparc"),
1095+
product_name=run_metadata.get("product_name"),
10961096
user_id=fake_user_id,
10971097
offset=0,
10981098
limit=10,
@@ -1143,7 +1143,7 @@ async def test_list_group_by_collection_run_id_with_different_users(
11431143

11441144
# Test for user1 - should only see their own runs
11451145
total_count, items = await repo.list_group_by_collection_run_id(
1146-
product_name=run_metadata.get("product_name", "osparc"),
1146+
product_name=run_metadata.get("product_name"),
11471147
user_id=user1["id"],
11481148
offset=0,
11491149
limit=10,
@@ -1158,7 +1158,7 @@ async def test_list_group_by_collection_run_id_with_different_users(
11581158

11591159
# Test for user2 - should only see their own runs
11601160
total_count, items = await repo.list_group_by_collection_run_id(
1161-
product_name=run_metadata.get("product_name", "osparc"),
1161+
product_name=run_metadata.get("product_name"),
11621162
user_id=user2["id"],
11631163
offset=0,
11641164
limit=10,
@@ -1217,7 +1217,7 @@ async def test_list_group_by_collection_run_id_state_priority_precedence(
12171217

12181218
# Test the function
12191219
total_count, items = await repo.list_group_by_collection_run_id(
1220-
product_name=run_metadata.get("product_name", "osparc"),
1220+
product_name=run_metadata.get("product_name"),
12211221
user_id=published_projects[0].user["id"],
12221222
offset=0,
12231223
limit=10,

services/director-v2/tests/unit/with_dbs/comp_scheduler/test_manager.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import pytest
1919
from _helpers import PublishedProject, assert_comp_runs, assert_comp_runs_empty
2020
from fastapi import FastAPI
21+
from models_library.computations import CollectionRunID
2122
from models_library.projects import ProjectAtDB
2223
from models_library.projects_state import RunningState
2324
from pytest_mock.plugin import MockerFixture
@@ -146,6 +147,7 @@ async def test_schedule_all_pipelines(
146147
sqlalchemy_async_engine: AsyncEngine,
147148
run_metadata: RunMetadataDict,
148149
scheduler_rabbit_client_parser: mock.AsyncMock,
150+
fake_collection_run_id: CollectionRunID,
149151
):
150152
await assert_comp_runs_empty(sqlalchemy_async_engine)
151153
assert published_project.project.prj_owner
@@ -156,6 +158,7 @@ async def test_schedule_all_pipelines(
156158
project_id=published_project.project.uuid,
157159
run_metadata=run_metadata,
158160
use_on_demand_clusters=False,
161+
collection_run_id=fake_collection_run_id,
159162
)
160163
# this directly schedule a new pipeline
161164
scheduler_rabbit_client_parser.assert_called_once_with(
@@ -247,6 +250,7 @@ async def test_schedule_all_pipelines_logs_error_if_it_find_old_pipelines(
247250
run_metadata: RunMetadataDict,
248251
scheduler_rabbit_client_parser: mock.AsyncMock,
249252
caplog: pytest.LogCaptureFixture,
253+
fake_collection_run_id: CollectionRunID,
250254
):
251255
await assert_comp_runs_empty(sqlalchemy_async_engine)
252256
assert published_project.project.prj_owner
@@ -257,6 +261,7 @@ async def test_schedule_all_pipelines_logs_error_if_it_find_old_pipelines(
257261
project_id=published_project.project.uuid,
258262
run_metadata=run_metadata,
259263
use_on_demand_clusters=False,
264+
collection_run_id=fake_collection_run_id,
260265
)
261266
# this directly schedule a new pipeline
262267
scheduler_rabbit_client_parser.assert_called_once_with(
@@ -327,6 +332,7 @@ async def test_empty_pipeline_is_not_scheduled(
327332
sqlalchemy_async_engine: AsyncEngine,
328333
scheduler_rabbit_client_parser: mock.AsyncMock,
329334
caplog: pytest.LogCaptureFixture,
335+
fake_collection_run_id: CollectionRunID,
330336
):
331337
await assert_comp_runs_empty(sqlalchemy_async_engine)
332338
user = create_registered_user()
@@ -340,6 +346,7 @@ async def test_empty_pipeline_is_not_scheduled(
340346
project_id=empty_project.uuid,
341347
run_metadata=run_metadata,
342348
use_on_demand_clusters=False,
349+
collection_run_id=fake_collection_run_id,
343350
)
344351
await assert_comp_runs_empty(sqlalchemy_async_engine)
345352
scheduler_rabbit_client_parser.assert_not_called()
@@ -355,6 +362,7 @@ async def test_empty_pipeline_is_not_scheduled(
355362
project_id=empty_project.uuid,
356363
run_metadata=run_metadata,
357364
use_on_demand_clusters=False,
365+
collection_run_id=fake_collection_run_id,
358366
)
359367
assert len(caplog.records) == 1
360368
assert "no computational dag defined" in caplog.records[0].message

services/director-v2/tests/unit/with_dbs/comp_scheduler/test_scheduler_dask.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import asyncio
1313
import datetime
14+
from calendar import c
1415
from collections.abc import AsyncIterator, Awaitable, Callable
1516
from copy import deepcopy
1617
from dataclasses import dataclass
@@ -32,6 +33,7 @@
3233
from dask_task_models_library.container_tasks.protocol import TaskOwner
3334
from faker import Faker
3435
from fastapi.applications import FastAPI
36+
from models_library.computations import CollectionRunID
3537
from models_library.projects import ProjectAtDB, ProjectID
3638
from models_library.projects_nodes_io import NodeID
3739
from models_library.projects_state import RunningState
@@ -164,6 +166,7 @@ async def _assert_start_pipeline(
164166
published_project: PublishedProject,
165167
run_metadata: RunMetadataDict,
166168
computational_pipeline_rabbit_client_parser: mock.AsyncMock,
169+
fake_collection_run_id: CollectionRunID,
167170
) -> tuple[CompRunsAtDB, list[CompTaskAtDB]]:
168171
exp_published_tasks = deepcopy(published_project.tasks)
169172
assert published_project.project.prj_owner
@@ -173,6 +176,7 @@ async def _assert_start_pipeline(
173176
project_id=published_project.project.uuid,
174177
run_metadata=run_metadata,
175178
use_on_demand_clusters=False,
179+
collection_run_id=fake_collection_run_id,
176180
)
177181

178182
# check the database is correctly updated, the run is published
@@ -472,6 +476,7 @@ async def test_proper_pipeline_is_scheduled( # noqa: PLR0915
472476
resource_tracking_rabbit_client_parser: mock.AsyncMock,
473477
computational_pipeline_rabbit_client_parser: mock.AsyncMock,
474478
run_metadata: RunMetadataDict,
479+
fake_collection_run_id: CollectionRunID,
475480
):
476481
with_disabled_auto_scheduling.assert_called_once()
477482
_with_mock_send_computation_tasks(published_project.tasks, mocked_dask_client)
@@ -485,6 +490,7 @@ async def test_proper_pipeline_is_scheduled( # noqa: PLR0915
485490
published_project=published_project,
486491
run_metadata=run_metadata,
487492
computational_pipeline_rabbit_client_parser=computational_pipeline_rabbit_client_parser,
493+
collection_run_id=fake_collection_run_id,
488494
)
489495
with_disabled_scheduler_publisher.assert_called()
490496

@@ -965,6 +971,7 @@ async def with_started_project(
965971
instrumentation_rabbit_client_parser: mock.AsyncMock,
966972
resource_tracking_rabbit_client_parser: mock.AsyncMock,
967973
computational_pipeline_rabbit_client_parser: mock.AsyncMock,
974+
fake_collection_run_id: CollectionRunID,
968975
) -> RunningProject:
969976
with_disabled_auto_scheduling.assert_called_once()
970977
published_project = await publish_project()
@@ -977,6 +984,7 @@ async def with_started_project(
977984
published_project=published_project,
978985
run_metadata=run_metadata,
979986
computational_pipeline_rabbit_client_parser=computational_pipeline_rabbit_client_parser,
987+
collection_run_id=fake_collection_run_id,
980988
)
981989
with_disabled_scheduler_publisher.assert_called_once()
982990

@@ -1210,6 +1218,7 @@ async def test_broken_pipeline_configuration_is_not_scheduled_and_aborted(
12101218
sqlalchemy_async_engine: AsyncEngine,
12111219
run_metadata: RunMetadataDict,
12121220
computational_pipeline_rabbit_client_parser: mock.AsyncMock,
1221+
fake_collection_run_id: CollectionRunID,
12131222
):
12141223
"""A pipeline which comp_tasks are missing should not be scheduled.
12151224
It shall be aborted and shown as such in the comp_runs db"""
@@ -1230,6 +1239,7 @@ async def test_broken_pipeline_configuration_is_not_scheduled_and_aborted(
12301239
project_id=sleepers_project.uuid,
12311240
run_metadata=run_metadata,
12321241
use_on_demand_clusters=False,
1242+
collection_run_id=fake_collection_run_id,
12331243
)
12341244
with_disabled_scheduler_publisher.assert_called_once()
12351245
# we shall have a a new comp_runs row with the new pipeline job
@@ -1282,6 +1292,7 @@ async def test_task_progress_triggers(
12821292
mocked_clean_task_output_and_log_files_if_invalid: mock.Mock,
12831293
run_metadata: RunMetadataDict,
12841294
computational_pipeline_rabbit_client_parser: mock.AsyncMock,
1295+
fake_collection_run_id: CollectionRunID,
12851296
):
12861297
_with_mock_send_computation_tasks(published_project.tasks, mocked_dask_client)
12871298
_run_in_db, expected_published_tasks = await _assert_start_pipeline(
@@ -1290,6 +1301,7 @@ async def test_task_progress_triggers(
12901301
published_project=published_project,
12911302
run_metadata=run_metadata,
12921303
computational_pipeline_rabbit_client_parser=computational_pipeline_rabbit_client_parser,
1304+
collection_run_id=fake_collection_run_id,
12931305
)
12941306

12951307
# -------------------------------------------------------------------------------
@@ -1357,6 +1369,7 @@ async def test_handling_of_disconnected_scheduler_dask(
13571369
backend_error: ComputationalSchedulerError,
13581370
run_metadata: RunMetadataDict,
13591371
computational_pipeline_rabbit_client_parser: mock.AsyncMock,
1372+
fake_collection_run_id: CollectionRunID,
13601373
):
13611374
# this will create a non connected backend issue that will trigger re-connection
13621375
mocked_dask_client_send_task = mocker.patch(
@@ -1373,6 +1386,7 @@ async def test_handling_of_disconnected_scheduler_dask(
13731386
project_id=published_project.project.uuid,
13741387
run_metadata=run_metadata,
13751388
use_on_demand_clusters=False,
1389+
collection_run_id=fake_collection_run_id,
13761390
)
13771391
await _assert_message_received(
13781392
computational_pipeline_rabbit_client_parser,
@@ -1801,6 +1815,7 @@ async def test_running_pipeline_triggers_heartbeat(
18011815
resource_tracking_rabbit_client_parser: mock.AsyncMock,
18021816
run_metadata: RunMetadataDict,
18031817
computational_pipeline_rabbit_client_parser: mock.AsyncMock,
1818+
fake_collection_run_id: CollectionRunID,
18041819
):
18051820
_with_mock_send_computation_tasks(published_project.tasks, mocked_dask_client)
18061821
run_in_db, expected_published_tasks = await _assert_start_pipeline(
@@ -1809,6 +1824,7 @@ async def test_running_pipeline_triggers_heartbeat(
18091824
published_project=published_project,
18101825
run_metadata=run_metadata,
18111826
computational_pipeline_rabbit_client_parser=computational_pipeline_rabbit_client_parser,
1827+
collection_run_id=fake_collection_run_id,
18121828
)
18131829
# -------------------------------------------------------------------------------
18141830
# 1. first run will move comp_tasks to PENDING so the dask-worker can take them
@@ -1918,6 +1934,7 @@ async def test_pipeline_with_on_demand_cluster_with_not_ready_backend_waits(
19181934
mocked_get_or_create_cluster: mock.Mock,
19191935
faker: Faker,
19201936
computational_pipeline_rabbit_client_parser: mock.AsyncMock,
1937+
fake_collection_run_id: CollectionRunID,
19211938
):
19221939
mocked_get_or_create_cluster.side_effect = (
19231940
ComputationalBackendOnDemandNotReadyError(
@@ -1932,6 +1949,7 @@ async def test_pipeline_with_on_demand_cluster_with_not_ready_backend_waits(
19321949
project_id=published_project.project.uuid,
19331950
run_metadata=run_metadata,
19341951
use_on_demand_clusters=True,
1952+
collection_run_id=fake_collection_run_id,
19351953
)
19361954

19371955
# we ask to use an on-demand cluster, therefore the tasks are published first
@@ -2038,6 +2056,7 @@ async def test_pipeline_with_on_demand_cluster_with_no_clusters_keeper_fails(
20382056
mocked_get_or_create_cluster: mock.Mock,
20392057
get_or_create_exception: Exception,
20402058
computational_pipeline_rabbit_client_parser: mock.AsyncMock,
2059+
fake_collection_run_id: CollectionRunID,
20412060
):
20422061
# needs to change: https://github.com/ITISFoundation/osparc-simcore/issues/6817
20432062

@@ -2050,6 +2069,7 @@ async def test_pipeline_with_on_demand_cluster_with_no_clusters_keeper_fails(
20502069
project_id=published_project.project.uuid,
20512070
run_metadata=run_metadata,
20522071
use_on_demand_clusters=True,
2072+
collection_run_id=fake_collection_run_id,
20532073
)
20542074

20552075
# we ask to use an on-demand cluster, therefore the tasks are published first
@@ -2151,6 +2171,7 @@ async def test_run_new_pipeline_called_twice_prevents_duplicate_runs(
21512171
published_project: PublishedProject,
21522172
run_metadata: RunMetadataDict,
21532173
computational_pipeline_rabbit_client_parser: mock.AsyncMock,
2174+
fake_collection_run_id: CollectionRunID,
21542175
):
21552176
# Ensure we start with an empty database
21562177
await assert_comp_runs_empty(sqlalchemy_async_engine)
@@ -2163,6 +2184,7 @@ async def test_run_new_pipeline_called_twice_prevents_duplicate_runs(
21632184
project_id=published_project.project.uuid,
21642185
run_metadata=run_metadata,
21652186
use_on_demand_clusters=False,
2187+
collection_run_id=fake_collection_run_id,
21662188
)
21672189

21682190
# Verify first run was created and published
@@ -2191,6 +2213,7 @@ async def test_run_new_pipeline_called_twice_prevents_duplicate_runs(
21912213
project_id=published_project.project.uuid,
21922214
run_metadata=run_metadata,
21932215
use_on_demand_clusters=False,
2216+
collection_run_id=fake_collection_run_id,
21942217
)
21952218

21962219
# Verify still only one run exists with same run_id

0 commit comments

Comments
 (0)