Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catch and convert all aio_pika connection exceptions #8712

Merged
merged 4 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/8544.misc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Catch and convert all `aio_pika` connection exceptions to subclass of `RasaException` in event broker creation.
1 change: 1 addition & 0 deletions rasa/core/brokers/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ async def create(
sqlalchemy.exc.OperationalError,
aio_pika.exceptions.AMQPConnectionError,
aiormq.exceptions.ChannelNotFoundEntity,
*aio_pika.exceptions.CONNECTION_EXCEPTIONS,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are some of the errors above included in this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just double-checked, the errors above are not included in aio_pika.exceptions.CONNECTION_EXCEPTIONS.

) as error:
raise ConnectionException("Cannot connect to event broker.") from error

Expand Down
26 changes: 26 additions & 0 deletions tests/core/test_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from typing import Union, Text, List, Optional, Type, Dict, Any

import aio_pika.exceptions
import aiormq.exceptions
import pamqp.exceptions
import kafka
import pytest
from _pytest.logging import LogCaptureFixture
Expand Down Expand Up @@ -109,6 +111,30 @@ async def test_pika_raise_connection_exception(monkeypatch: MonkeyPatch):
)


@pytest.mark.parametrize(
"exception",
(
RuntimeError,
ConnectionError,
OSError,
aiormq.exceptions.AMQPError,
pamqp.exceptions.PAMQPException,
pamqp.specification.AMQPConnectionForced,
pamqp.specification.AMQPNotFound,
pamqp.specification.AMQPInternalError,
),
)
async def test_aio_pika_exceptions_caught(
exception: Exception, monkeypatch: MonkeyPatch
):
monkeypatch.setattr(PikaEventBroker, "connect", AsyncMock(side_effect=exception))

with pytest.raises(ConnectionException):
await EventBroker.create(
EndpointConfig(username="username", password="password", type="pika")
)


async def test_no_broker_in_config(endpoints_path: Text):
cfg = read_endpoint_config(endpoints_path, "event_broker")

Expand Down