MCPcopy
hub / github.com/pika/pika / test

Method test

tests/acceptance/blocking_adapter_test.py:1213–1255  ·  view source on GitHub ↗

BlockingChannel.basic_nack single message

(self)

Source from the content-addressed store, hash-verified

1211class TestBasicNack(BlockingTestCaseBase):
1212
1213 def test(self):
1214 """BlockingChannel.basic_nack single message"""
1215 connection = self._connect()
1216
1217 ch = connection.channel()
1218
1219 q_name = 'TestBasicNack_q' + uuid.uuid1().hex
1220
1221 # Place channel in publisher-acknowledgments mode so that the message
1222 # may be delivered synchronously to the queue by publishing it with
1223 # mandatory=True
1224 ch.confirm_delivery()
1225
1226 # Declare a new queue
1227 ch.queue_declare(q_name, exclusive=True)
1228
1229 # Deposit two messages in the queue via default exchange
1230 ch.basic_publish(exchange='',
1231 routing_key=q_name,
1232 body='TestBasicNack1',
1233 mandatory=True)
1234 ch.basic_publish(exchange='',
1235 routing_key=q_name,
1236 body='TestBasicNack2',
1237 mandatory=True)
1238
1239 # Get the messages
1240 (rx_method, _, rx_body) = ch.basic_get(q_name, auto_ack=False)
1241 self.assertEqual(rx_body, as_bytes('TestBasicNack1'))
1242
1243 (rx_method, _, rx_body) = ch.basic_get(q_name, auto_ack=False)
1244 self.assertEqual(rx_body, as_bytes('TestBasicNack2'))
1245
1246 # Nack the second message
1247 ch.basic_nack(rx_method.delivery_tag, multiple=False, requeue=True)
1248
1249 # Verify that exactly one message is present in the queue, namely the
1250 # second one
1251 self._assert_exact_message_count_with_retries(channel=ch,
1252 queue=q_name,
1253 expected_count=1)
1254 (rx_method, _, rx_body) = ch.basic_get(q_name, auto_ack=False)
1255 self.assertEqual(rx_body, as_bytes('TestBasicNack2'))
1256
1257
1258class TestBasicNackNoRequeue(BlockingTestCaseBase):

Callers

nothing calls this directly

Calls 9

as_bytesFunction · 0.90
_connectMethod · 0.45
channelMethod · 0.45
confirm_deliveryMethod · 0.45
queue_declareMethod · 0.45
basic_publishMethod · 0.45
basic_getMethod · 0.45
basic_nackMethod · 0.45

Tested by

no test coverage detected