Pass connection options from broker_options to default_channel (#769)

* Pass connection options from broker_options to default_channel (fixes #765)

* Fixup

* Fixup
This commit is contained in:
Anthony Lukach 2017-08-02 03:06:47 -06:00 committed by Omer Katz
parent 802e77b6c3
commit 0f4da8d450
3 changed files with 53 additions and 1 deletions

View File

@ -4,6 +4,20 @@
Change history
================
.. _version-4.1.1:
4.1.1
=====
:release-date: TBD
:release-by: TBD
- Now passing ``max_retries``, ``interval_start``, ``interval_step``,
``interval_max`` parameters from broker ``transport_options`` to
:meth:`~kombu.Connection.ensure_connection` when returning
:meth:`~kombu.Connection.default_connection` (Issue #765).
Contributed by **Anthony Lukach**.
.. _version-4.1.0:
4.1.0

View File

@ -815,8 +815,20 @@ class Connection(object):
a connection is passed instead of a channel, to functions that
require a channel.
"""
conn_opts = {}
transport_opts = self.transport_options
if transport_opts:
if 'max_retries' in transport_opts:
conn_opts['max_retries'] = transport_opts['max_retries']
if 'interval_start' in transport_opts:
conn_opts['interval_start'] = transport_opts['interval_start']
if 'interval_step' in transport_opts:
conn_opts['interval_step'] = transport_opts['interval_step']
if 'interval_max' in transport_opts:
conn_opts['interval_max'] = transport_opts['interval_max']
# make sure we're still connected, and if not refresh.
self.ensure_connection()
self.ensure_connection(**conn_opts)
if self._default_channel is None:
self._default_channel = self.channel()
return self._default_channel

View File

@ -380,6 +380,32 @@ class test_Connection:
defchan.close.assert_called_with()
assert conn._default_channel is None
def test_default_channel_no_transport_options(self):
conn = self.conn
conn.ensure_connection = Mock()
assert conn.default_channel
conn.ensure_connection.assert_called_with()
def test_default_channel_transport_options(self):
conn = self.conn
conn.transport_options = options = {
'max_retries': 1,
'interval_start': 2,
'interval_step': 3,
'interval_max': 4,
'ignore_this': True
}
conn.ensure_connection = Mock()
assert conn.default_channel
conn.ensure_connection.assert_called_with(**{
k: v for k, v in options.items()
if k in ['max_retries',
'interval_start',
'interval_step',
'interval_max']})
def test_ensure_connection(self):
assert self.conn.ensure_connection()