Esempio n. 1
0
async def test_pool_execute_with_moved(loop, test_pool_cluster, free_ports):
    expected_pool_connection = FakeConnection(
        free_ports[0],
        loop,
        return_value=ReplyError(
            'MOVED 6000 127.0.0.1:{}'.format(free_ports[1])
        )
    )
    expected_direct_connection = FakeConnection(free_ports[1], loop)

    with PoolConnectionMock(
            test_pool_cluster, loop, {free_ports[0]: expected_pool_connection}
    ):
        with CreateConnectionMock(
                {free_ports[1]: expected_direct_connection}
        ):
            ok = await test_pool_cluster.execute('SET', SLOT_ZERO_KEY, 'value')

    assert ok

    expected_pool_connection.execute.assert_called_once_with(
        b'SET', SLOT_ZERO_KEY, 'value'
    )
    expected_direct_connection.execute.assert_called_once_with(
        b'SET', SLOT_ZERO_KEY, 'value'
    )
Esempio n. 2
0
async def test_execute_with_reply_error(loop, test_cluster, free_ports):
    expected_connection = FakeConnection(free_ports[0],
                                         loop,
                                         return_value=ReplyError('ERROR'))

    with CreateConnectionMock({free_ports[0]: expected_connection}):
        with pytest.raises(ReplyError):
            await test_cluster.execute('SET', SLOT_ZERO_KEY, 'value')

    expected_connection.execute.assert_called_once_with(
        b'SET', SLOT_ZERO_KEY, 'value')
Esempio n. 3
0
async def test_execute_with_moved(loop, test_cluster, free_ports):
    expected_connections = {
        free_ports[0]:
        FakeConnection(free_ports[0],
                       loop,
                       return_value=ReplyError(
                           'MOVED 6000 127.0.0.1:{}'.format(free_ports[1]))),
        free_ports[1]:
        FakeConnection(free_ports[1], loop)
    }
    with CreateConnectionMock(expected_connections):
        ok = await test_cluster.execute('SET', SLOT_ZERO_KEY, 'value')

    assert ok

    expected_connections[free_ports[0]].execute.assert_called_once_with(
        b'SET', SLOT_ZERO_KEY, 'value')
    expected_connections[free_ports[1]].execute.assert_called_once_with(
        b'SET', SLOT_ZERO_KEY, 'value')
Esempio n. 4
0
def test_parse_moved_response_error():
    assert parse_moved_response_error(ReplyError('')) is None
    assert parse_moved_response_error(ReplyError('ASK')) is None
    assert parse_moved_response_error(
        ReplyError('MOVED 3999 127.0.0.1:6381')) == ('127.0.0.1', 6381)
Esempio n. 5
0
def test_reply_error__classify(error_msg, expect_type):
    with pytest.raises(expect_type):
        raise ReplyError(error_msg)