1919from common_library .json_serialization import json_dumps
2020from faker import Faker
2121from models_library .projects_state import RunningState
22+ from pytest_mock import MockerFixture
2223from pytest_simcore .helpers .assert_checks import assert_status
2324from servicelib .aiohttp import status
2425from servicelib .aiohttp .application import create_safe_application
5051from simcore_service_webserver .rest .plugin import setup_rest
5152from simcore_service_webserver .security .plugin import setup_security
5253from simcore_service_webserver .session .plugin import setup_session
54+ from simcore_service_webserver .socketio .messages import SOCKET_IO_NODE_UPDATED_EVENT
5355from simcore_service_webserver .socketio .plugin import setup_socketio
5456from simcore_service_webserver .users .plugin import setup_users
5557from sqlalchemy .ext .asyncio import AsyncEngine
6466 "catalog" ,
6567 "dask-scheduler" ,
6668 "dask-sidecar" ,
69+ "docker-api-proxy" ,
70+ "dynamic-schdlr" ,
6771 "director-v2" ,
6872 "director" ,
6973 "migration" ,
@@ -596,21 +600,28 @@ async def test_running_computation_sends_progress_updates_via_socketio(
596600 create_socketio_connection : Callable [
597601 [str | None , TestClient | None ], Awaitable [tuple [socketio .AsyncClient , str ]]
598602 ],
603+ mocker : MockerFixture ,
599604):
600605 assert client .app
601- socket_io_conn , * _ = await create_socketio_connection (None , client )
606+ socket_io_conn , client_id = await create_socketio_connection (None , client )
607+ mock_progress_handler = mocker .MagicMock ()
608+ socket_io_conn .on (SOCKET_IO_NODE_UPDATED_EVENT , handler = mock_progress_handler )
602609
603610 project_id = user_project ["uuid" ]
604611
612+ url_open = client .app .router ["open_project" ].url_for (
613+ project_id = user_project ["uuid" ]
614+ )
615+ resp = await client .post (f"{ url_open } " , json = client_id )
616+ await assert_status (resp , status .HTTP_200_OK )
617+
605618 url_start = client .app .router ["start_computation" ].url_for (project_id = project_id )
606619 assert url_start == URL (f"/{ API_VTAG } /computations/{ project_id } :start" )
607620
608621 # POST /v0/computations/{project_id}:start
609622 resp = await client .post (f"{ url_start } " )
610623 data , error = await assert_status (resp , status .HTTP_201_CREATED )
611-
612- if error :
613- return
624+ assert not error
614625
615626 assert "pipeline_id" in data
616627 assert data ["pipeline_id" ] == project_id
@@ -628,10 +639,17 @@ async def test_running_computation_sends_progress_updates_via_socketio(
628639 client ,
629640 project_id ,
630641 RunningState .SUCCESS ,
631- _ExpectedResponseTuple (
632- ok = status .HTTP_200_OK ,
633- created = status .HTTP_201_CREATED ,
634- no_content = status .HTTP_204_NO_CONTENT ,
635- confict = status .HTTP_409_CONFLICT ,
636- ),
642+ expected ,
643+ )
644+
645+ # check that the progress updates were sent
646+ assert mock_progress_handler .call_count > 0 , (
647+ "expected progress updates to be sent via socketio, "
648+ f"but got { mock_progress_handler .call_count } calls"
649+ )
650+ # check that the last progress update was for the SUCCESS state
651+ last_call_args = mock_progress_handler .call_args_list [- 1 ][0 ]
652+ assert len (last_call_args ) == 1 , (
653+ "expected the progress handler to be called with a single argument, "
654+ f"but got { len (last_call_args )} arguments"
637655 )
0 commit comments