mirror of https://github.com/celery/kombu.git
Consumer: __exit__ should not cancel if connection error (Closes #670)
This commit is contained in:
parent
e03cbbe0d8
commit
8a7ea091bf
|
@ -430,11 +430,14 @@ class Consumer(object):
|
||||||
self.consume()
|
self.consume()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, *exc_info):
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
try:
|
if self.channel:
|
||||||
self.cancel()
|
conn_errors = self.channel.connection.client.connection_errors
|
||||||
except Exception:
|
if not isinstance(exc_val, conn_errors):
|
||||||
pass
|
try:
|
||||||
|
self.cancel()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
def add_queue(self, queue):
|
def add_queue(self, queue):
|
||||||
"""Add a queue to the list of queues to consume from.
|
"""Add a queue to the list of queues to consume from.
|
||||||
|
|
|
@ -262,6 +262,15 @@ class test_Consumer:
|
||||||
pass
|
pass
|
||||||
c.cancel.assert_called_with()
|
c.cancel.assert_called_with()
|
||||||
|
|
||||||
|
def test_enter_exit_cancel_not_called_on_connection_error(self):
|
||||||
|
c = Consumer(self.connection)
|
||||||
|
c.cancel = Mock(name='Consumer.cancel')
|
||||||
|
assert self.connection.connection_errors
|
||||||
|
with pytest.raises(self.connection.connection_errors[0]):
|
||||||
|
with c:
|
||||||
|
raise self.connection.connection_errors[0]()
|
||||||
|
c.cancel.assert_not_called()
|
||||||
|
|
||||||
def test_receive_callback_accept(self):
|
def test_receive_callback_accept(self):
|
||||||
message = Mock(name='Message')
|
message = Mock(name='Message')
|
||||||
message.errors = []
|
message.errors = []
|
||||||
|
|
Loading…
Reference in New Issue