예제 #1
0
async def test_stopped(create_connection, server, loop):
    sub = await create_connection(server.tcp_address, loop=loop)
    pub = await create_connection(server.tcp_address, loop=loop)

    mpsc = Receiver(loop=loop)
    await sub.execute_pubsub('subscribe', mpsc.channel('channel:1'))
    assert mpsc.is_active
    mpsc.stop()

    with logs('aioredis', 'DEBUG') as cm:
        await pub.execute('publish', 'channel:1', b'Hello')
        await asyncio.sleep(0, loop=loop)

    assert len(cm.output) == 1
    # Receiver must have 1 EndOfStream message
    warn_messaege = (
        "WARNING:aioredis:Pub/Sub listener message after stop: "
        "sender: <_Sender name:b'channel:1', is_pattern:False, receiver:"
        "<Receiver is_active:False, senders:1, qsize:0>>, data: b'Hello'")
    assert cm.output == [warn_messaege]

    # assert (await mpsc.get()) is None
    with pytest.raises(ChannelClosedError):
        await mpsc.get()
    res = await mpsc.wait_message()
    assert res is False
예제 #2
0
async def test_stopped(create_connection, server, loop):
    sub = await create_connection(server.tcp_address, loop=loop)
    pub = await create_connection(server.tcp_address, loop=loop)

    mpsc = Receiver(loop=loop)
    await sub.execute_pubsub('subscribe', mpsc.channel('channel:1'))
    assert mpsc.is_active
    mpsc.stop()

    with logs('aioredis', 'DEBUG') as cm:
        await pub.execute('publish', 'channel:1', b'Hello')
        await asyncio.sleep(0, loop=loop)

    assert len(cm.output) == 1
    # Receiver must have 1 EndOfStream message
    warn_messaege = (
        "WARNING:aioredis:Pub/Sub listener message after stop: "
        "sender: <_Sender name:b'channel:1', is_pattern:False, receiver:"
        "<Receiver is_active:False, senders:1, qsize:0>>, data: b'Hello'"
    )
    assert cm.output == [warn_messaege]

    # assert (await mpsc.get()) is None
    with pytest.raises(ChannelClosedError):
        await mpsc.get()
    res = await mpsc.wait_message()
    assert res is False
예제 #3
0
async def test_release_pending(create_pool, loop, server):
    pool = await create_pool(
        server.tcp_address,
        minsize=1, loop=loop)
    assert pool.size == 1
    assert pool.freesize == 1

    with logs('aioredis', 'WARNING') as cm:
        with (await pool) as conn:
            try:
                await asyncio.wait_for(
                    conn.execute(
                        b'blpop',
                        b'somekey:not:exists',
                        b'0'),
                    0.1,
                    loop=loop)
            except asyncio.TimeoutError:
                pass
    assert pool.size == 0
    assert pool.freesize == 0
    assert cm.output == [
        'WARNING:aioredis:Connection <RedisConnection [db:0]>'
        ' has pending commands, closing it.'
    ]
예제 #4
0
async def test_sentinel_master_pool_size(sentinel, create_sentinel):
    redis_s = await create_sentinel([sentinel.tcp_address], timeout=1,
                                    minsize=10, maxsize=10)
    master = redis_s.master_for('master-no-fail')
    assert isinstance(master.connection, AbcPool)
    assert master.connection.size == 0

    with logs('aioredis.sentinel', 'DEBUG') as cm:
        assert await master.ping()
    assert len(cm.output) == 1
    assert cm.output == [
        "DEBUG:aioredis.sentinel:Discoverred new address {}"
        " for master-no-fail".format(master.address),
    ]
    assert master.connection.size == 10
    assert master.connection.freesize == 10
예제 #5
0
파일: pool_test.py 프로젝트: leenr/aioredis
async def test_pool_check_closed_when_exception(create_pool, create_redis,
                                                start_server, loop):
    server = start_server('server-small')
    redis = await create_redis(server.tcp_address, loop=loop)
    await redis.config_set('maxclients', 2)

    errors = (MaxClientsError, ConnectionClosedError, ConnectionError)
    with logs('aioredis', 'DEBUG') as cm:
        with pytest.raises(errors):
            await create_pool(address=tuple(server.tcp_address),
                              minsize=3,
                              loop=loop)

    assert len(cm.output) >= 3
    connect_msg = ("DEBUG:aioredis:Creating tcp connection"
                   " to ('localhost', {})".format(server.tcp_address.port))
    assert cm.output[:2] == [connect_msg, connect_msg]
    assert cm.output[-1] == "DEBUG:aioredis:Closed 1 connection(s)"
예제 #6
0
async def test_sentinel_master_pool_size(sentinel, create_sentinel):
    redis_s = await create_sentinel([sentinel.tcp_address],
                                    timeout=1,
                                    minsize=10,
                                    maxsize=10)
    master = redis_s.master_for('master-no-fail')
    assert isinstance(master.connection, AbcPool)
    assert master.connection.size == 0

    with logs('aioredis.sentinel', 'DEBUG') as cm:
        assert await master.ping()
    assert len(cm.output) == 1
    assert cm.output == [
        "DEBUG:aioredis.sentinel:Discoverred new address {}"
        " for master-no-fail".format(master.address),
    ]
    assert master.connection.size == 10
    assert master.connection.freesize == 10