Skip to content

Commit 075c804

Browse files
committed
fixes coro
1 parent e18ff3d commit 075c804

File tree

3 files changed

+40
-27
lines changed

3 files changed

+40
-27
lines changed

services/web/server/src/simcore_service_webserver/projects/_trash_api.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,10 @@ async def _is_project_running(
5252
project_id: ProjectID,
5353
) -> bool:
5454
return bool(
55-
# computational
5655
await director_v2_api.is_pipeline_running(
5756
app, user_id=user_id, project_id=project_id
5857
)
5958
) or bool(
60-
# dynamic
6159
await director_v2_api.list_dynamic_services(
6260
app, user_id=user_id, project_id=f"{project_id}"
6361
)
@@ -87,26 +85,28 @@ async def trash_project(
8785
)
8886

8987
if force_stop_first:
90-
# NOTE: schedules stop-project
91-
92-
stop_project_task = asyncio.gather(
93-
director_v2_api.stop_pipeline(app, user_id=user_id, project_id=project_id),
94-
projects_api.remove_project_dynamic_services(
95-
user_id=user_id,
96-
project_uuid=f"{project_id}",
97-
app=app,
98-
simcore_user_agent=UNDEFINED_DEFAULT_SIMCORE_USER_AGENT_VALUE,
99-
notify_users=False,
100-
),
101-
)
88+
89+
async def _schedule():
90+
await asyncio.gather(
91+
director_v2_api.stop_pipeline(
92+
app, user_id=user_id, project_id=project_id
93+
),
94+
projects_api.remove_project_dynamic_services(
95+
user_id=user_id,
96+
project_uuid=f"{project_id}",
97+
app=app,
98+
simcore_user_agent=UNDEFINED_DEFAULT_SIMCORE_USER_AGENT_VALUE,
99+
notify_users=False,
100+
),
101+
)
102102

103103
fire_and_forget_task(
104-
stop_project_task,
105-
task_suffix_name=f"trash_project_stop_project_{user_id=}_{project_id=}",
104+
_schedule(),
105+
task_suffix_name=f"trash_project_force_stop_first_{user_id=}_{project_id=}",
106106
fire_and_forget_tasks_collection=app[APP_FIRE_AND_FORGET_TASKS_KEY],
107107
)
108108

109-
elif _is_project_running(app, user_id=user_id, project_id=project_id):
109+
elif await _is_project_running(app, user_id=user_id, project_id=project_id):
110110
raise ProjectRunningConflictError(
111111
project_uuid=project_id,
112112
user_id=user_id,

services/web/server/src/simcore_service_webserver/projects/_trash_handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class HttpErrorInfo(NamedTuple):
4141
_TO_HTTP_ERROR_MAP: dict[type[Exception], HttpErrorInfo] = {
4242
ProjectRunningConflictError: HttpErrorInfo(
4343
status.HTTP_409_CONFLICT,
44-
"Current study is in use and cannot be trashed [{project_uuid}]. Please stop all services first and try again",
44+
"Current study is in use and cannot be trashed [project_id={project_uuid}]. Please stop all services first and try again",
4545
),
4646
ProjectStoppingError: HttpErrorInfo(
4747
status.HTTP_503_SERVICE_UNAVAILABLE,

services/web/server/tests/unit/with_dbs/03/test_trash.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,37 @@ def mocked_catalog(
3939
@pytest.mark.acceptance_test(
4040
"For https://github.com/ITISFoundation/osparc-simcore/pull/6579"
4141
)
42-
@pytest.mark.parametrize("is_trash_service_running", [False, True])
42+
@pytest.mark.parametrize("force", [False, True])
43+
@pytest.mark.parametrize("is_project_running", [False, True])
4344
async def test_trash_projects(
4445
client: TestClient,
4546
logged_user: UserInfoDict,
4647
user_project: ProjectDict,
4748
mocked_catalog: None,
4849
director_v2_service_mock: aioresponses,
4950
mocker: MockerFixture,
50-
is_trash_service_running: bool,
51+
force: bool,
52+
is_project_running: bool,
5153
):
5254
assert client.app
5355

5456
# this test should have no errors stopping services
55-
mocker.patch(
57+
mock_remove_dynamic_services = mocker.patch(
5658
"simcore_service_webserver.projects._trash_api.projects_api.remove_project_dynamic_services",
5759
autospec=True,
5860
)
59-
mocker.patch(
60-
"simcore_service_webserver.projects._trash_api.director_v2_api.delete_pipeline",
61+
mock_stop_pipeline = mocker.patch(
62+
"simcore_service_webserver.projects._trash_api.director_v2_api.stop_pipeline",
6163
autospec=True,
6264
)
6365
mocker.patch(
6466
"simcore_service_webserver.projects._trash_api.director_v2_api.is_pipeline_running",
65-
return_value=is_trash_service_running,
67+
return_value=is_project_running,
68+
autospec=True,
69+
)
70+
mocker.patch(
71+
"simcore_service_webserver.projects._trash_api.director_v2_api.list_dynamic_services",
72+
return_value=[mocker.MagicMock()] if is_project_running else [],
6673
autospec=True,
6774
)
6875

@@ -91,15 +98,17 @@ async def test_trash_projects(
9198

9299
# TRASH
93100
trashing_at = arrow.utcnow().datetime
94-
resp = await client.post(f"/v0/projects/{project_uuid}:trash")
101+
resp = await client.post(
102+
f"/v0/projects/{project_uuid}:trash", params={"force": f"{force}"}
103+
)
95104
_, error = await assert_status(
96105
resp,
97106
status.HTTP_409_CONFLICT
98-
if is_trash_service_running
107+
if (is_project_running and not force)
99108
else status.HTTP_204_NO_CONTENT,
100109
)
101110

102-
could_not_trash = is_trash_service_running
111+
could_not_trash = is_project_running and not force
103112

104113
if could_not_trash:
105114
assert error["status"] == status.HTTP_409_CONFLICT
@@ -140,3 +149,7 @@ async def test_trash_projects(
140149

141150
assert got.uuid == project_uuid
142151
assert got.trashed_at is None
152+
153+
if is_project_running and force:
154+
mock_remove_dynamic_services.assert_any_await()
155+
mock_stop_pipeline.assert_any_await()

0 commit comments

Comments
 (0)