summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleh Kuchuk <kuchuklehjs@gmail.com>2020-04-15 15:16:57 +0300
committerAsif Saif Uddin <auvipy@gmail.com>2020-04-15 21:08:18 +0600
commit90f51bcbbd32146998e7c7e4491150344343776b (patch)
tree250034eaff1395331adb7548aebf7ae0f8313536
parent472101103e5ead37ad637beb7361aa1b3a32e389 (diff)
downloadkombu-90f51bcbbd32146998e7c7e4491150344343776b.tar.gz
Raise RecoverableConnectionError in maybe_declare with retry on and dropped connection
-rw-r--r--kombu/common.py4
-rw-r--r--t/unit/test_common.py15
2 files changed, 19 insertions, 0 deletions
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: