|
10 | 10 | from datetime import UTC, datetime, timedelta |
11 | 11 | from typing import Any |
12 | 12 |
|
| 13 | +from faker import Faker |
13 | 14 | from models_library.api_schemas_directorv2.comp_runs import ( |
| 15 | + ComputationCollectionRunRpcGetPage, |
| 16 | + ComputationCollectionRunTaskRpcGetPage, |
14 | 17 | ComputationRunRpcGetPage, |
15 | 18 | ComputationTaskRpcGetPage, |
16 | 19 | ) |
| 20 | +from models_library.computations import CollectionRunID |
17 | 21 | from models_library.projects import ProjectAtDB |
18 | 22 | from models_library.projects_state import RunningState |
19 | 23 | from servicelib.rabbitmq import RabbitMQRPCClient |
|
22 | 26 | ) |
23 | 27 | from simcore_postgres_database.models.comp_pipeline import StateType |
24 | 28 | 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 | +) |
25 | 32 | from simcore_service_director_v2.models.comp_runs import CompRunsAtDB |
26 | 33 | from simcore_service_director_v2.models.comp_tasks import CompTaskAtDB |
27 | 34 |
|
@@ -219,3 +226,85 @@ async def test_rpc_list_computation_runs_history( |
219 | 226 | ) |
220 | 227 | assert output.total == 3 |
221 | 228 | 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