Skip to content

Commit d6bb65a

Browse files
fix test
1 parent 641494d commit d6bb65a

File tree

3 files changed

+97
-2
lines changed

3 files changed

+97
-2
lines changed

packages/postgres-database/src/simcore_postgres_database/migration/versions/42ec7816c0b4_computational_collection_runs.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""computational collection runs
22
33
Revision ID: 42ec7816c0b4
4-
Revises: 4f6fd2586491
4+
Revises: d159ac30983c
55
Create Date: 2025-07-01 13:30:02.736058+00:00
66
77
"""
@@ -12,7 +12,7 @@
1212

1313
# revision identifiers, used by Alembic.
1414
revision = "42ec7816c0b4"
15-
down_revision = "4f6fd2586491"
15+
down_revision = "d159ac30983c"
1616
branch_labels = None
1717
depends_on = None
1818

@@ -55,6 +55,11 @@ def upgrade():
5555
op.add_column(
5656
"comp_runs", sa.Column("collection_run_id", sa.String(), nullable=False)
5757
)
58+
op.create_unique_constraint(
59+
"comp_runs_project_collection_run_id_unique_constraint",
60+
"comp_runs",
61+
["project_uuid", "collection_run_id"],
62+
)
5863

5964
# Data migration: Create collection run records for existing comp_runs
6065
op.execute(

packages/postgres-database/src/simcore_postgres_database/models/comp_runs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,5 @@
113113
sa.UniqueConstraint("project_uuid", "user_id", "iteration"),
114114
sa.Index("ix_comp_runs_user_id", "user_id"),
115115
sa.Index("ix_comp_runs_collection_run_id", "collection_run_id"),
116+
sa.UniqueConstraint("project_uuid", "collection_run_id"),
116117
)

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

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
from datetime import UTC, datetime, timedelta
1111
from typing import Any
1212

13+
from faker import Faker
1314
from models_library.api_schemas_directorv2.comp_runs import (
15+
ComputationCollectionRunRpcGetPage,
16+
ComputationCollectionRunTaskRpcGetPage,
1417
ComputationRunRpcGetPage,
1518
ComputationTaskRpcGetPage,
1619
)
20+
from models_library.computations import CollectionRunID
1721
from models_library.projects import ProjectAtDB
1822
from models_library.projects_state import RunningState
1923
from servicelib.rabbitmq import RabbitMQRPCClient
@@ -22,6 +26,9 @@
2226
)
2327
from simcore_postgres_database.models.comp_pipeline import StateType
2428
from simcore_service_director_v2.models.comp_pipelines import CompPipelineAtDB
29+
from simcore_service_director_v2.models.comp_run_snapshot_tasks import (
30+
CompRunSnapshotTaskDBGet,
31+
)
2532
from simcore_service_director_v2.models.comp_runs import CompRunsAtDB
2633
from simcore_service_director_v2.models.comp_tasks import CompTaskAtDB
2734

@@ -219,3 +226,85 @@ async def test_rpc_list_computation_runs_history(
219226
)
220227
assert output.total == 3
221228
assert isinstance(output, ComputationRunRpcGetPage)
229+
230+
231+
async def test_rpc_list_computation_collection_runs_page_and_collection_run_tasks_page(
232+
fake_workbench_without_outputs: dict[str, Any], # <-- Has 4 nodes
233+
fake_workbench_adjacency: dict[str, Any],
234+
create_registered_user: Callable[..., dict[str, Any]],
235+
project: Callable[..., Awaitable[ProjectAtDB]],
236+
create_pipeline: Callable[..., Awaitable[CompPipelineAtDB]],
237+
create_tasks: Callable[..., Awaitable[list[CompTaskAtDB]]],
238+
create_comp_run_snapshot_tasks: Callable[
239+
..., Awaitable[list[CompRunSnapshotTaskDBGet]]
240+
],
241+
create_comp_run: Callable[..., Awaitable[CompRunsAtDB]],
242+
rpc_client: RabbitMQRPCClient,
243+
faker: Faker,
244+
):
245+
user = create_registered_user()
246+
projects = [
247+
await project(user, workbench=fake_workbench_without_outputs) for _ in range(3)
248+
]
249+
250+
default_collection_run_id = CollectionRunID(f"{faker.uuid4(cast_to=None)}")
251+
not_default_collection_run_id = CollectionRunID(f"{faker.uuid4(cast_to=None)}")
252+
253+
collection_run_id_project_list = [
254+
default_collection_run_id,
255+
default_collection_run_id,
256+
not_default_collection_run_id,
257+
]
258+
259+
for proj, collection_run_id in zip(projects, collection_run_id_project_list):
260+
await create_pipeline(
261+
project_id=f"{proj.uuid}",
262+
dag_adjacency_list=fake_workbench_adjacency,
263+
)
264+
await create_tasks(
265+
user=user, project=proj, state=StateType.PUBLISHED, progress=None
266+
)
267+
run = await create_comp_run(
268+
user=user,
269+
project=proj,
270+
result=RunningState.SUCCESS,
271+
started=datetime.now(tz=UTC) - timedelta(minutes=120),
272+
ended=datetime.now(tz=UTC) - timedelta(minutes=100),
273+
iteration=1,
274+
dag_adjacency_list=fake_workbench_adjacency,
275+
collection_run_id=f"{collection_run_id}",
276+
)
277+
await create_comp_run_snapshot_tasks(
278+
user=user,
279+
project=proj,
280+
run_id=run.run_id,
281+
)
282+
283+
output = await rpc_computations.list_computation_collection_runs_page(
284+
rpc_client, product_name="osparc", user_id=user["id"], project_ids=None
285+
)
286+
assert output.total == 2
287+
assert len(output.items) == 2
288+
assert isinstance(output, ComputationCollectionRunRpcGetPage)
289+
assert len(output.items[0].project_ids) == 1
290+
assert len(output.items[1].project_ids) == 2
291+
292+
output = await rpc_computations.list_computation_collection_run_tasks_page(
293+
rpc_client,
294+
product_name="osparc",
295+
user_id=user["id"],
296+
collection_run_id=default_collection_run_id,
297+
)
298+
assert output.total == 8
299+
assert len(output.items) == 8
300+
isinstance(output, ComputationCollectionRunTaskRpcGetPage)
301+
302+
output = await rpc_computations.list_computation_collection_run_tasks_page(
303+
rpc_client,
304+
product_name="osparc",
305+
user_id=user["id"],
306+
collection_run_id=not_default_collection_run_id,
307+
)
308+
assert output.total == 4
309+
assert len(output.items) == 4
310+
isinstance(output, ComputationCollectionRunTaskRpcGetPage)

0 commit comments

Comments
 (0)