From bab5b9e7dcf2b13d103745fd0d3b7cecfdfd9bee Mon Sep 17 00:00:00 2001 From: sanderegg <35365065+sanderegg@users.noreply.github.com> Date: Mon, 24 Apr 2023 16:33:13 +0200 Subject: [PATCH] moving rabbitmq code to rabbitmq folder --- .../src/simcore_service_webserver/application.py | 2 -- .../rabbitmq/consumers.py | 4 ++-- .../unit/isolated/test_computation_subscribe.py | 14 +++++++------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/services/web/server/src/simcore_service_webserver/application.py b/services/web/server/src/simcore_service_webserver/application.py index c004c42790e..86fd9869496 100644 --- a/services/web/server/src/simcore_service_webserver/application.py +++ b/services/web/server/src/simcore_service_webserver/application.py @@ -13,7 +13,6 @@ from .application_settings import setup_settings from .catalog import setup_catalog from .clusters.plugin import setup_clusters -from .computation import setup_computation from .db import setup_db from .diagnostics import setup_diagnostics from .director.plugin import setup_director @@ -79,7 +78,6 @@ def create_application() -> web.Application: # monitoring setup_diagnostics(app) setup_activity(app) - setup_computation(app) setup_socketio(app) # login diff --git a/services/web/server/src/simcore_service_webserver/rabbitmq/consumers.py b/services/web/server/src/simcore_service_webserver/rabbitmq/consumers.py index b13fe0bd2bd..3e5040febb5 100644 --- a/services/web/server/src/simcore_service_webserver/rabbitmq/consumers.py +++ b/services/web/server/src/simcore_service_webserver/rabbitmq/consumers.py @@ -12,6 +12,7 @@ ProgressType, ) from pydantic import parse_raw_as +from servicelib.aiohttp.application_keys import APP_RABBITMQ_CLIENT_KEY from servicelib.aiohttp.monitor_services import ( SERVICE_STARTED_LABELS, SERVICE_STOPPED_LABELS, @@ -33,7 +34,6 @@ SocketMessageDict, send_messages, ) -from .rabbitmq import get_rabbitmq_client logger = logging.getLogger(__name__) @@ -179,7 +179,7 @@ async def _events_message_parser(app: web.Application, data: bytes) -> bool: async def setup_rabbitmq_consumers(app: web.Application) -> AsyncIterator[None]: with log_context(logger, logging.INFO, msg="Subscribing to rabbitmq channels"): - rabbit_client: RabbitMQClient = get_rabbitmq_client(app) + rabbit_client: RabbitMQClient = app[APP_RABBITMQ_CLIENT_KEY] for exchange_name, parser_fct, queue_kwargs in EXCHANGE_TO_PARSER_CONFIG: await rabbit_client.subscribe( diff --git a/services/web/server/tests/unit/isolated/test_computation_subscribe.py b/services/web/server/tests/unit/isolated/test_computation_subscribe.py index 42af7740fcf..ce99277a0ba 100644 --- a/services/web/server/tests/unit/isolated/test_computation_subscribe.py +++ b/services/web/server/tests/unit/isolated/test_computation_subscribe.py @@ -1,6 +1,7 @@ # pylint: disable=redefined-outer-name # pylint: disable=protected-access +from typing import Iterator from unittest.mock import AsyncMock import pytest @@ -10,22 +11,21 @@ ProgressRabbitMessageProject, ProgressType, ) +from pydantic import BaseModel from pytest_mock import MockerFixture -from simcore_service_webserver import computation_subscribe +from simcore_service_webserver.rabbitmq import consumers _faker = Faker() @pytest.fixture -def mock_send_messages(mocker: MockerFixture) -> dict: +def mock_send_messages(mocker: MockerFixture) -> Iterator[dict]: reference = {} async def mock_send_message(*args) -> None: reference["args"] = args - mocker.patch.object( - computation_subscribe, "send_messages", side_effect=mock_send_message - ) + mocker.patch.object(consumers, "send_messages", side_effect=mock_send_message) yield reference @@ -61,9 +61,9 @@ async def mock_send_message(*args) -> None: ], ) async def test_regression_progress_message_parser( - mock_send_messages: dict, raw_data: bytes, class_type: type + mock_send_messages: dict, raw_data: bytes, class_type: type[BaseModel] ): - await computation_subscribe._progress_message_parser(AsyncMock(), raw_data) + await consumers._progress_message_parser(AsyncMock(), raw_data) serialized_sent_data = mock_send_messages["args"][2][0]["data"] # check that all fields are sent as expected assert class_type.parse_obj(serialized_sent_data)