'BlockingChannel.basic_cancel purges pending _ConsumerCancellationEvt'

def test(self):

    connection = self._connect()
    ch = connection.channel()
    q_name = ('TestBasicCancelPurgesPendingConsumerCancellationEvt_q' + uuid.uuid1().hex)
    ch.queue_declare(q_name)
    self.addCleanup(self._connect().channel().queue_delete, q_name)
    ch.publish('', routing_key=q_name, body='via-publish', mandatory=True)
    rx_messages = []
    consumer_tag = ch.basic_consume((lambda *args: rx_messages.append(args)), q_name, no_ack=False, exclusive=False, arguments=None)
    while (not ch._pending_events):
        connection.channel().close()
    self.assertEqual(len(ch._pending_events), 1)
    self.assertIsInstance(ch._pending_events[0], blocking_connection._ConsumerDeliveryEvt)
    ch.queue_delete(q_name)
    while (len(ch._pending_events) < 2):
        connection.channel().close()
    self.assertEqual(len(ch._pending_events), 2)
    self.assertIsInstance(ch._pending_events[1], blocking_connection._ConsumerCancellationEvt)
    messages = ch.basic_cancel(consumer_tag)
    self.assertEqual(messages, [])
    self.assertEqual(len(ch._pending_events), 0)
