|
12 | 12 | import socketio |
13 | 13 | import sqlalchemy as sa |
14 | 14 | from aiohttp.test_utils import TestClient |
15 | | -from aioresponses import aioresponses as AioResponsesMock |
16 | 15 | from faker import Faker |
17 | 16 | from models_library.api_schemas_webserver.socketio import SocketIORoomStr |
18 | 17 | from models_library.progress_bar import ProgressReport |
|
39 | 38 | ) |
40 | 39 | from servicelib.rabbitmq import RabbitMQClient |
41 | 40 | from settings_library.rabbit import RabbitSettings |
42 | | -from simcore_postgres_database.models.projects import projects |
43 | 41 | from simcore_postgres_database.models.users import UserRole |
44 | 42 | from simcore_service_webserver.application_settings import setup_settings |
45 | 43 | from simcore_service_webserver.db.plugin import setup_db |
|
58 | 56 | from simcore_service_webserver.socketio.messages import ( |
59 | 57 | SOCKET_IO_EVENT, |
60 | 58 | SOCKET_IO_LOG_EVENT, |
61 | | - SOCKET_IO_NODE_UPDATED_EVENT, |
62 | 59 | ) |
63 | 60 | from simcore_service_webserver.socketio.models import WebSocketNodeProgress |
64 | 61 | from simcore_service_webserver.socketio.plugin import setup_socketio |
65 | | -from sqlalchemy.ext.asyncio import AsyncEngine |
66 | 62 | from tenacity import RetryError |
67 | 63 | from tenacity.asyncio import AsyncRetrying |
68 | 64 | from tenacity.retry import retry_always, retry_if_exception_type |
@@ -402,90 +398,6 @@ async def mocked_dynamic_services_interface( |
402 | 398 | return mock |
403 | 399 |
|
404 | 400 |
|
405 | | -@pytest.mark.parametrize("user_role", [UserRole.GUEST], ids=str) |
406 | | -@pytest.mark.parametrize( |
407 | | - "sender_same_user_id", [True, False], ids=lambda id_: f"same_sender_id={id_}" |
408 | | -) |
409 | | -@pytest.mark.parametrize( |
410 | | - "subscribe_to_logs", [True, False], ids=lambda id_: f"subscribed={id_}" |
411 | | -) |
412 | | -async def test_progress_computational_workflow( |
413 | | - mocked_dynamic_services_interface, |
414 | | - director_v2_service_mock: AioResponsesMock, |
415 | | - client: TestClient, |
416 | | - rabbitmq_publisher: RabbitMQClient, |
417 | | - user_project: ProjectDict, |
418 | | - create_socketio_connection: Callable[ |
419 | | - [str | None, TestClient | None], Awaitable[tuple[socketio.AsyncClient, str]] |
420 | | - ], |
421 | | - mocker: MockerFixture, |
422 | | - sqlalchemy_async_engine: AsyncEngine, |
423 | | - subscribe_to_logs: bool, |
424 | | - # user |
425 | | - sender_same_user_id: bool, |
426 | | - sender_user_id: UserID, |
427 | | - # project |
428 | | - random_node_id_in_user_project: NodeID, |
429 | | - user_project_id: ProjectID, |
430 | | -): |
431 | | - """ |
432 | | - RabbitMQ (TOPIC) --> Webserver --> DB (get project) |
433 | | - Redis --> webclient (socketio) |
434 | | -
|
435 | | - """ |
436 | | - socket_io_conn, *_ = await create_socketio_connection(None, client) |
437 | | - |
438 | | - mock_progress_handler = mocker.MagicMock() |
439 | | - socket_io_conn.on(SOCKET_IO_NODE_UPDATED_EVENT, handler=mock_progress_handler) |
440 | | - |
441 | | - if subscribe_to_logs: |
442 | | - assert client.app |
443 | | - await project_logs.subscribe(client.app, user_project_id) |
444 | | - # this simulates the user openning the project |
445 | | - await get_socket_server(client.app).enter_room( |
446 | | - socket_io_conn.get_sid(), SocketIORoomStr.from_project_id(user_project_id) |
447 | | - ) |
448 | | - progress_message = ProgressRabbitMessageNode( |
449 | | - user_id=sender_user_id, |
450 | | - project_id=user_project_id, |
451 | | - node_id=random_node_id_in_user_project, |
452 | | - progress_type=ProgressType.COMPUTATION_RUNNING, |
453 | | - report=ProgressReport(actual_value=0.3, total=1), |
454 | | - ) |
455 | | - await rabbitmq_publisher.publish(progress_message.channel_name, progress_message) |
456 | | - |
457 | | - call_expected = sender_same_user_id and subscribe_to_logs |
458 | | - if call_expected: |
459 | | - expected_call = jsonable_encoder( |
460 | | - progress_message, include={"node_id", "project_id"} |
461 | | - ) |
462 | | - expected_call |= { |
463 | | - "data": user_project["workbench"][f"{random_node_id_in_user_project}"] |
464 | | - } |
465 | | - expected_call["data"]["progress"] = int( |
466 | | - progress_message.report.percent_value * 100 |
467 | | - ) |
468 | | - await _assert_handler_called_with_json(mock_progress_handler, expected_call) |
469 | | - else: |
470 | | - await _assert_handler_not_called(mock_progress_handler) |
471 | | - |
472 | | - # check the database. doing it after the waiting calls above is safe |
473 | | - async with sqlalchemy_async_engine.connect() as conn: |
474 | | - assert projects is not None |
475 | | - result = await conn.execute( |
476 | | - sa.select(projects.c.workbench).where( |
477 | | - projects.c.uuid == str(user_project_id) |
478 | | - ) |
479 | | - ) |
480 | | - row = result.one() |
481 | | - project_workbench = dict(row[projects.c.workbench]) |
482 | | - # NOTE: the progress might still be present but is not used anymore |
483 | | - assert ( |
484 | | - project_workbench[f"{random_node_id_in_user_project}"].get("progress", 0) |
485 | | - == 0 |
486 | | - ) |
487 | | - |
488 | | - |
489 | 401 | @pytest.mark.parametrize("user_role", [UserRole.GUEST], ids=str) |
490 | 402 | @pytest.mark.parametrize("metrics_name", ["service_started", "service_stopped"]) |
491 | 403 | async def test_instrumentation_workflow( |
|
0 commit comments