Skip to content

Commit

Permalink
Merge pull request #1233 from pika/pika-1232
Browse files Browse the repository at this point in the history
Fix add_on_return_callback callback parameters
  • Loading branch information
michaelklishin committed Jul 16, 2019
2 parents 83047f3 + fbcdf5d commit 724d890
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
15 changes: 7 additions & 8 deletions pika/adapters/twisted_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ def _on_delivery_confirmation(self, method_frame):
else:
d.callback(method_frame.method)

def _on_puback_message_returned(self, message):
def _on_puback_message_returned(self, channel, method, properties, body):
"""Called as the result of Basic.Return from broker in
publisher-acknowledgements mode. Saves the info as a ReturnedMessage
instance in self._puback_return.
Expand All @@ -747,19 +747,18 @@ def _on_puback_message_returned(self, message):
:param bytes body: returned message body; empty string if no body
"""
assert isinstance(message.method, spec.Basic.Return), message.method
assert isinstance(message.properties,
spec.BasicProperties), (message.properties)
assert isinstance(method, spec.Basic.Return), method
assert isinstance(properties, spec.BasicProperties), properties

LOGGER.warning(
"Published message was returned: _delivery_confirmation=%s; "
"channel=%s; method=%r; properties=%r; body_size=%d; "
"body_prefix=%.255r", self._delivery_confirmation,
message.channel.channel_number, message.method, message.properties,
len(message.body) if message.body is not None else None,
message.body)
channel.channel_number, method, properties,
len(body) if body is not None else None, body)

self._puback_return = message
self._puback_return = ReceivedMessage(channel=self,
method=method, properties=properties, body=body)

def exchange_bind(self, destination, source, routing_key='',
arguments=None):
Expand Down
20 changes: 6 additions & 14 deletions tests/acceptance/twisted_adapter_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ def send_message(_result):
return d

def check_response(error):
self.assertTrue(isinstance(error.value, NackError))
self.assertIsInstance(error.value, NackError)
self.assertEqual(len(error.value.messages), 0)
d.addCallback(send_message)
d.addCallbacks(self.fail, check_response)
Expand All @@ -539,19 +539,15 @@ def send_message(_result):
# Send the Basic.Return frame
method = spec.Basic.Return(
exchange="testexch", routing_key="testrk")
return_cb(ReceivedMessage(
channel=self.channel,
method=method,
properties=spec.BasicProperties(),
body="testbody",
))
return_cb(self.channel, method,
spec.BasicProperties(), "testbody")
# Send the Basic.Ack frame
frame = Method(1, spec.Basic.Ack(delivery_tag=1))
self.channel._on_delivery_confirmation(frame)
return d

def check_response(error):
self.assertTrue(isinstance(error.value, UnroutableError))
self.assertIsInstance(error.value, UnroutableError)
self.assertEqual(len(error.value.messages), 1)
msg = error.value.messages[0]
self.assertEqual(msg.body, "testbody")
Expand All @@ -574,12 +570,8 @@ def send_message(_result):
# Send the Basic.Return frame
method = spec.Basic.Return(
exchange="testexch", routing_key="testrk")
return_cb(ReceivedMessage(
channel=self.channel,
method=method,
properties=spec.BasicProperties(),
body="testbody",
))
return_cb(self.channel, method,
spec.BasicProperties(), "testbody")
# Send the Basic.Nack frame
frame = Method(1, spec.Basic.Nack(delivery_tag=1))
self.channel._on_delivery_confirmation(frame)
Expand Down

0 comments on commit 724d890

Please sign in to comment.