diff options
author | Matus Valo <matusvalo@users.noreply.github.com> | 2020-06-05 09:20:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-05 09:20:56 +0200 |
commit | 16749626a4b206501ed46577646ad24695cf912d (patch) | |
tree | 7dae7ad54b1b6c0cd63f6deaa901d57fb75f4532 | |
parent | ce6d2016406cd65d3ceaf62d4753b5a1d59a9b67 (diff) | |
download | kombu-16749626a4b206501ed46577646ad24695cf912d.tar.gz |
default_channel should reconnect automatically (#1209)
-rw-r--r-- | kombu/connection.py | 2 | ||||
-rw-r--r-- | t/integration/common.py | 5 | ||||
-rw-r--r-- | t/unit/test_connection.py | 12 |
3 files changed, 19 insertions, 0 deletions
diff --git a/kombu/connection.py b/kombu/connection.py index 65dcb52b..5a5af519 100644 --- a/kombu/connection.py +++ b/kombu/connection.py @@ -883,6 +883,8 @@ class Connection(object): a connection is passed instead of a channel, to functions that require a channel. """ + # make sure we're still connected, and if not refresh. + self.connect() if self._default_channel is None: self._default_channel = self.channel() return self._default_channel diff --git a/t/integration/common.py b/t/integration/common.py index c62837d6..4b3a70fd 100644 --- a/t/integration/common.py +++ b/t/integration/common.py @@ -14,6 +14,11 @@ class BasicFunctionality(object): connection.connect() connection.close() + def test_default_channel_autoconnect(self, connection): + connection.connect() + connection.close() + connection.default_channel + def test_publish_consume(self, connection): test_queue = kombu.Queue('test', routing_key='test') diff --git a/t/unit/test_connection.py b/t/unit/test_connection.py index 13834113..5251f868 100644 --- a/t/unit/test_connection.py +++ b/t/unit/test_connection.py @@ -415,6 +415,18 @@ class test_Connection: conn._close() conn._default_channel.close.assert_called_with() + def test_auto_reconnect_default_channel(self): + # tests GH issue: #1208 + # Tests that default_channel automatically reconnects when connection + # closed + c = Connection('memory://') + c._closed = True + with patch.object( + c, '_connection_factory', side_effect=c._connection_factory + ) as cf_mock: + c.default_channel + cf_mock.assert_called_once_with() + def test_close_when_default_channel_close_raises(self): class Conn(Connection): |