From 90f51bcbbd32146998e7c7e4491150344343776b Mon Sep 17 00:00:00 2001 From: Oleh Kuchuk Date: Wed, 15 Apr 2020 15:16:57 +0300 Subject: Raise RecoverableConnectionError in maybe_declare with retry on and dropped connection --- kombu/common.py | 4 ++++ t/unit/test_common.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/kombu/common.py b/kombu/common.py index 30abe1c6..8c2c847d 100644 --- a/kombu/common.py +++ b/kombu/common.py @@ -168,6 +168,10 @@ def _maybe_declare(entity, channel): def _imaybe_declare(entity, channel, **retry_policy): _ensure_channel_is_bound(entity, channel) + + if not channel.connection: + raise RecoverableConnectionError('channel disconnected') + return entity.channel.connection.client.ensure( entity, _maybe_declare, **retry_policy)(entity, channel) diff --git a/t/unit/test_common.py b/t/unit/test_common.py index 2f2874fb..42fac679 100644 --- a/t/unit/test_common.py +++ b/t/unit/test_common.py @@ -198,6 +198,21 @@ class test_maybe_declare: # Then: the connection client used ensure to ensure the retry policy assert channel.connection.client.ensure.call_count + def test_with_retry_dropped_connection(self): + # Given: A mock Channel and mock entity + channel = self._get_mock_channel() + # Given: A mock Entity that is already bound + entity = self._get_mock_entity( + is_bound=True, can_cache_declaration=True) + entity.channel = channel + assert entity.is_bound, "Expected entity is bound to begin this test." + # When: Entity channel connection has gone away + entity.channel.connection = None + # When: calling maybe_declare with retry + # Then: the RecoverableConnectionError should be raised + with pytest.raises(RecoverableConnectionError): + maybe_declare(entity, channel, retry=True) + class test_replies: -- cgit v1.2.1