'BlockingConnection.close from basic_consume callback'

def test(self):

    connection = self._connect()
    ch = connection.channel()
    q_name = ('TestCloseConnectionFromBasicConsumeCallback_q' + uuid.uuid1().hex)
    ch.confirm_delivery()
    ch.queue_declare(q_name, auto_delete=False)
    self.addCleanup(self._connect().channel().queue_delete, q_name)
    ch.publish('', routing_key=q_name, body='via-publish1', mandatory=True)
    ch.publish('', routing_key=q_name, body='via-publish2', mandatory=True)
    def on_consume(channel, method, props, body):
        connection.close()
    ch.basic_consume(on_consume, q_name, no_ack=False, exclusive=False, arguments=None)
    ch.start_consuming()
    self.assertTrue(ch.is_closed)
    self.assertTrue(connection.is_closed)
    ch = self._connect().channel()
    (_, _, rx_body) = ch.basic_get(q_name)
    self.assertEqual(rx_body, as_bytes('via-publish1'))
    (_, _, rx_body) = ch.basic_get(q_name)
    self.assertEqual(rx_body, as_bytes('via-publish2'))
