async def test_broker_consume_fail(amqp_connection): queue = Queue(name='test_queue') consumer = Consumer(agent=None, handler=AsyncMock(), queue=queue, timeout=1, options={}) channel, connection = amqp_connection channel.basic_consume.side_effect = aioamqp.ChannelClosed(code=500) broker = AMQPBroker('amqp://localhost') with pytest.raises(aioamqp.ChannelClosed): await broker.bind_consumer(consumer)
async def test_broker_consume_new_channel_ok(amqp_connection): queue = Queue(name='test_queue') consumer = Consumer(agent=None, handler=AsyncMock(), queue=queue, timeout=1, options={}) channel, connection = amqp_connection channel.basic_consume.side_effect = [aioamqp.ChannelClosed(code=404), None] broker = AMQPBroker('amqp://localhost') await broker.bind_consumer(consumer) connection.channel.assert_called() channel.queue_declare.assert_called_once_with(queue.name) assert channel.basic_consume.call_count == 2
async def test_broker_channel_ok(amqp_connection): channel, connection = amqp_connection channel.basic_consume.side_effect = aioamqp.ChannelClosed(code=500) broker = AMQPBroker('amqp://localhost') assert await broker.get_channel() connection.channel.assert_called() conn_id = id(broker.protocol) assert await broker.get_channel() assert connection.channel.call_count == 2 assert id(broker.protocol) == conn_id assert broker.channels == {} connection.channel.side_effect = aioamqp.AmqpClosedConnection with pytest.raises(aioamqp.AmqpClosedConnection): await broker.get_channel() assert not broker.protocol assert broker.channels == {}
async def test_broker_rebind_fail_close_channel(): broker = AMQPBroker('amqp://localhost') broker.bind = AsyncMock(side_effect=aioamqp.ChannelClosed()) broker._bind_attempts['test_queue'] = 0 assert not await broker.rebind('test_queue')