Skip to content

Commit 517ffe7

Browse files
add test
1 parent b6369b4 commit 517ffe7

File tree

2 files changed

+63
-4
lines changed

2 files changed

+63
-4
lines changed

services/web/server/src/simcore_service_webserver/director_v2/_comp_runs_collections_repository.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,13 @@ async def upsert_comp_run_collection(
8181
modified=func.now(),
8282
)
8383
on_update_stmt = insert_stmt.on_conflict_do_update(
84-
index_elements=[
85-
comp_runs_collections.c.client_or_system_generated_display_name
86-
],
84+
index_elements=[comp_runs_collections.c.client_or_system_generated_id],
8785
set_={
8886
"modified": func.now(),
8987
},
9088
)
9189
result = await conn.stream(
9290
on_update_stmt.returning(comp_runs_collections.c.collection_run_id)
9391
)
94-
collection_id_tuple: tuple[UUID] = result.one()
92+
collection_id_tuple: tuple[UUID] = await result.one()
9593
return TypeAdapter(CollectionRunID).validate_python(collection_id_tuple[0])

services/web/server/tests/integration/02/test_computation.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@
1616
import sqlalchemy as sa
1717
from aiohttp.test_utils import TestClient
1818
from common_library.json_serialization import json_dumps
19+
from faker import Faker
1920
from models_library.projects_state import RunningState
2021
from pytest_simcore.helpers.assert_checks import assert_status
2122
from servicelib.aiohttp import status
2223
from servicelib.aiohttp.application import create_safe_application
2324
from servicelib.status_codes_utils import get_code_display_name
2425
from settings_library.rabbit import RabbitSettings
2526
from settings_library.redis import RedisSettings
27+
from simcore_postgres_database.models.comp_runs_collections import comp_runs_collections
2628
from simcore_postgres_database.models.projects import projects
29+
from simcore_postgres_database.models.projects_metadata import projects_metadata
2730
from simcore_postgres_database.models.users import UserRole
2831
from simcore_postgres_database.webserver_models import (
2932
NodeClass,
@@ -518,3 +521,61 @@ async def test_run_pipeline_and_check_state(
518521
)
519522

520523
print(f"<-- pipeline completed successfully in {time.monotonic() - start} seconds")
524+
525+
526+
@pytest.fixture
527+
async def populated_project_metadata(
528+
client: TestClient,
529+
logged_user: dict[str, Any],
530+
user_project: dict[str, Any],
531+
faker: Faker,
532+
postgres_db: sa.engine.Engine,
533+
):
534+
assert client.app
535+
project_uuid = user_project["uuid"]
536+
with postgres_db.connect() as con:
537+
con.execute(
538+
projects_metadata.insert().values(
539+
**{
540+
"project_uuid": project_uuid,
541+
"custom": {
542+
"job_name": "My Job Name",
543+
"group_id": faker.uuid4(),
544+
"group_name": "My Group Name",
545+
},
546+
}
547+
)
548+
)
549+
yield
550+
con.execute(projects_metadata.delete())
551+
con.execute(comp_runs_collections.delete()) # cleanup
552+
553+
554+
@pytest.mark.parametrize(*user_role_response(), ids=str)
555+
async def test_start_multiple_computation_with_the_same_collection_run_id(
556+
client: TestClient,
557+
sleeper_service: dict[str, str],
558+
postgres_db: sa.engine.Engine,
559+
populated_project_metadata: None,
560+
logged_user: dict[str, Any],
561+
user_project: dict[str, Any],
562+
fake_workbench_adjacency_list: dict[str, Any],
563+
user_role: UserRole,
564+
expected: _ExpectedResponseTuple,
565+
):
566+
assert client.app
567+
project_id = user_project["uuid"]
568+
569+
url_start = client.app.router["start_computation"].url_for(project_id=project_id)
570+
assert url_start == URL(f"/{API_VTAG}/computations/{project_id}:start")
571+
572+
# POST /v0/computations/{project_id}:start
573+
resp = await client.post(f"{url_start}")
574+
await assert_status(resp, expected.created)
575+
576+
resp = await client.post(f"{url_start}")
577+
# starting again should be disallowed, since it's already running
578+
assert resp.status == expected.confict
579+
580+
# NOTE: This tests that there is only one entry in comp_runs_collections table created
581+
# as the project metadata has the same group_id

0 commit comments

Comments
 (0)