Exemplo n.º 1
0
async def test_broker_rollback_many_attempts_ok():
    queue = Queue(name='test_queue')
    broker = AIORedisBroker('redis://localhost')
    broker.send = AsyncMock()
    broker._rollbacks[str(hash(queue.name)) + str(hash('{}'))] = 4
    await broker.rollback(queue.name, '{}')
    broker.send.assert_not_called()
Exemplo n.º 2
0
async def test_broker_consume_ok(monkeypatch):
    queue = Queue(name='test_queue')
    consumer = Consumer(agent=None, handler=AsyncMock(), queue=queue, timeout=1, options={})
    create_redis = MagicMock(blpop=AsyncMock(side_effect=[('ch', '{}'), None, Exception]))
    monkeypatch.setattr(aioredis, 'create_redis', AsyncMock(return_value=create_redis))

    broker = AIORedisBroker('redis://localhost')
    broker.BIND_TIME = .01
    await broker.bind_consumer(consumer)
    await asyncio.sleep(.02)
Exemplo n.º 3
0
async def test_broker_handling_sync_rollback_ok():
    queue = Queue(name='test_queue')
    consumer = Consumer(agent=None, handler=Mock(side_effect=Exception),
        queue=queue, timeout=1, options={})
    broker = AIORedisBroker('redis://localhost')
    broker.send = AsyncMock()
    broker._bindings[queue.name] = consumer
    await broker._handler(queue.name, '{}')
    consumer.handler.assert_called_once()
    await asyncio.sleep(.01)
    broker.send.assert_called_once_with(queue.name, '{}')
Exemplo n.º 4
0
async def test_broker_handling_async_ok():
    queue = Queue(name='test_queue')
    consumer = Consumer(agent=None, handler=AsyncMock(), queue=queue, timeout=1, options={})
    broker = AIORedisBroker('redis://localhost')
    broker._bindings[queue.name] = consumer
    await broker._handler(queue.name, '{}')
    consumer.handler.assert_called_once_with()
Exemplo n.º 5
0
async def test_broker_queue_length_ok(monkeypatch):
    create_redis = MagicMock(llen=AsyncMock())
    monkeypatch.setattr(aioredis, 'create_redis', AsyncMock(return_value=create_redis))

    broker = AIORedisBroker('redis://localhost')
    await broker.queue_length('test_queue')

    create_redis.llen.assert_called_once_with('test_queue')

    await broker.queue_length('test_queue')

    assert create_redis.llen.call_count == 2
Exemplo n.º 6
0
async def test_broker_send_ok(monkeypatch):
    create_redis = MagicMock(rpush=AsyncMock())
    monkeypatch.setattr(aioredis, 'create_redis', AsyncMock(return_value=create_redis))

    broker = AIORedisBroker('redis://localhost')
    await broker.send('test_queue', '{}')

    create_redis.rpush.assert_called_once_with('test_queue', '{}')

    await broker.send('test_queue', '{}')

    assert create_redis.rpush.call_count == 2
Exemplo n.º 7
0
async def main():
    bus = AIORedisSignalBus('redis://localhost/7')
    broker = AIORedisBroker('redis://localhost/7')
    await bus.started.send('user_agent')

    user_agent = UserAgent(bus=bus, broker=broker)
    comment_agent = CommentAgent(bus=bus, broker=broker)
    email_agent = EmailAgent(broker=broker)

    await user_agent.start()
    await comment_agent.start()
    await email_agent.start()

    while True:
        await asyncio.sleep(60)