diff options
author | Matus Valo <matusvalo@gmail.com> | 2020-05-23 00:00:52 +0200 |
---|---|---|
committer | Asif Saif Uddin <auvipy@gmail.com> | 2020-06-01 12:56:32 +0600 |
commit | df31de1c6e369f2f68a4330277196796b46b7ab2 (patch) | |
tree | a082e2d71dd2deb12f4907d13ac4b3982fb3689f | |
parent | 25a026665174c5330e6e3dfbf4361cf8e2a100f4 (diff) | |
download | kombu-df31de1c6e369f2f68a4330277196796b46b7ab2.tar.gz |
Fix broken compatibility with Celery
-rw-r--r-- | kombu/connection.py | 24 | ||||
-rw-r--r-- | t/unit/test_connection.py | 8 |
2 files changed, 21 insertions, 11 deletions
diff --git a/kombu/connection.py b/kombu/connection.py index 64a49842..989a5868 100644 --- a/kombu/connection.py +++ b/kombu/connection.py @@ -280,7 +280,7 @@ class Connection(object): def connect(self): """Establish connection to server immediately.""" conn_opts = self._extract_failover_opts() - return self.ensure_connection(**conn_opts) + return self._ensure_connection(**conn_opts) def channel(self): """Create and return a new channel.""" @@ -380,10 +380,20 @@ class Connection(object): self._close() close = release - def ensure_connection(self, errback=None, max_retries=None, - interval_start=2, interval_step=2, interval_max=30, - callback=None, reraise_as_library_errors=True, - timeout=None): + def ensure_connection(self, *args, **kwargs): + """Public interface of _ensure_connection for retro-compatibility. + + Returns kombu.Connection instance. + """ + self._ensure_connection(*args, **kwargs) + return self + + def _ensure_connection( + self, errback=None, max_retries=None, + interval_start=2, interval_step=2, interval_max=30, + callback=None, reraise_as_library_errors=True, + timeout=None + ): """Ensure we have a connection to the server. If not retry establishing the connection with the settings @@ -533,7 +543,7 @@ class Connection(object): remaining_retries = None if max_retries is not None: remaining_retries = max(max_retries - retries, 1) - self.ensure_connection( + self._ensure_connection( errback, remaining_retries, interval_start, interval_step, interval_max, @@ -850,7 +860,7 @@ class Connection(object): if not self._closed: if not self.connected: conn_opts = self._extract_failover_opts() - self._connection = self.ensure_connection(**conn_opts) + self._connection = self._ensure_connection(**conn_opts) return self._connection def _connection_factory(self): diff --git a/t/unit/test_connection.py b/t/unit/test_connection.py index c4e3764c..017dfae4 100644 --- a/t/unit/test_connection.py +++ b/t/unit/test_connection.py @@ -144,10 +144,10 @@ class test_Connection: def test_connect_no_transport_options(self): conn = self.conn - conn.ensure_connection = Mock() + conn._ensure_connection = Mock() conn.connect() - conn.ensure_connection.assert_called_with() + conn._ensure_connection.assert_called_with() def test_connect_transport_options(self): conn = self.conn @@ -158,10 +158,10 @@ class test_Connection: 'interval_max': 4, 'ignore_this': True } - conn.ensure_connection = Mock() + conn._ensure_connection = Mock() conn.connect() - conn.ensure_connection.assert_called_with(**{ + conn._ensure_connection.assert_called_with(**{ k: v for k, v in options.items() if k in ['max_retries', 'interval_start', |