Skip to content

Commit

Permalink
moving rabbitmq code to rabbitmq folder
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg committed Apr 24, 2023
1 parent 6ef3b8b commit bab5b9e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,7 +78,6 @@ def create_application() -> web.Application:
# monitoring
setup_diagnostics(app)
setup_activity(app)
setup_computation(app)
setup_socketio(app)

# login
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -33,7 +34,6 @@
SocketMessageDict,
send_messages,
)
from .rabbitmq import get_rabbitmq_client

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pylint: disable=redefined-outer-name
# pylint: disable=protected-access

from typing import Iterator
from unittest.mock import AsyncMock

import pytest
Expand All @@ -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

Expand Down Expand Up @@ -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)

0 comments on commit bab5b9e

Please sign in to comment.