Skip to content

Commit

Permalink
Pass connection options from broker_options to default_channel (#769)
Browse files Browse the repository at this point in the history
* Pass connection options from broker_options to default_channel (fixes #765)

* Fixup

* Fixup
  • Loading branch information
alukach authored and Omer Katz committed Aug 2, 2017
1 parent 802e77b commit 0f4da8d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion kombu/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,20 @@ def default_channel(self):
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
Expand Down
26 changes: 26 additions & 0 deletions t/unit/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,32 @@ def test_revive_when_default_channel(self):
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()

Expand Down

0 comments on commit 0f4da8d

Please sign in to comment.