Пример #1
0
async def test_check_handler_none(sync_none):
    aio_thc = Checker()

    aio_thc.add_check('none', sync_none)

    with pytest.raises(TypeError):
        await aio_thc.check_handler()
Пример #2
0
async def test_check_async_exception_throw(async_exception_check):
    aio_thc = Checker()

    aio_thc.add_check('async_exception', async_exception_check)

    with pytest.raises(ZeroDivisionError):
        await aio_thc.check_handler()
Пример #3
0
async def test_check_handler_partial(async_partial):
    aio_thc = Checker()

    aio_thc.add_check('async_partial', async_partial)

    await aio_thc.check_handler()
    assert len(aio_thc.async_checks) == 1
Пример #4
0
def test_add_async_method(check_class_object):
    aio_thc = Checker()

    aio_thc.add_check('async', check_class_object.async_method_true)

    assert 'async' in aio_thc.async_checks
    assert len(aio_thc.sync_checks) == 0
Пример #5
0
def test_add_check_async(async_true):
    aio_thc = Checker()

    aio_thc.add_check('async', async_true)

    assert 'async' in aio_thc.async_checks
    assert len(aio_thc.sync_checks) == 0
Пример #6
0
async def test_check_handler_sync_only(sync_true):
    aio_thc = Checker()

    aio_thc.add_check('sync_true', sync_true)
    result = await aio_thc.check_handler()

    assert result.code == 200
    assert result.body['sync_true'] is True
Пример #7
0
async def test_check_handler_success_aiohttp(async_true):
    aio_thc = Checker(success_code=201)

    aio_thc.add_check('async_true', async_true)

    response = await aio_thc.aiohttp_handler(None)

    assert response.status == 201
    assert json.loads(response.body.decode())['async_true'] is True
Пример #8
0
async def test_check_handler_empty():
    aio_thc = Checker()

    result = await aio_thc.check_handler()

    assert result.code == 200
    assert len(result.body) == 0
Пример #9
0
async def test_healthcheck_server(sync_false):
    aio_thc = Checker()

    aio_thc.add_check('sync_false', sync_false)

    hc_server = HttpServer(aio_thc, host='localhost')

    task = asyncio.ensure_future(hc_server.run())

    await asyncio.sleep(0.2)
    async with aiohttp.ClientSession() as session:
        async with session.get('http://localhost:8000/healthcheck/') as resp:
            assert resp.status == 500
            resp_body = await resp.text()
            assert json.loads(resp_body)['sync_false'] is False

    hc_server.stop_later()
    await asyncio.sleep(1)
    task.cancel()
Пример #10
0
async def test_slow_handler_slow_async(sync_true, async_true, async_slow_true):
    aio_thc = Checker(timeout=1)

    aio_thc.add_check('sync_true', sync_true)
    aio_thc.add_check('async_true', async_true)
    aio_thc.add_check('async_slow_true', async_slow_true)

    result = await aio_thc.check_handler()
    assert result.code == 500
    assert result.body['sync_true'] == True
    assert result.body['async_true'] == True
    assert result.body['async_slow_true'] == False
Пример #11
0
def test_add_nonuniq_check_async():
    aio_thc = Checker()

    aio_thc.add_check('async', lambda: True)

    with pytest.raises(ValueError):
        aio_thc.add_check('async', lambda: True)
Пример #12
0
async def test_check_handler_error(sync_true, sync_false, async_true,
                                   async_false):
    aio_thc = Checker(fail_code=777)

    aio_thc.add_check('sync_true', sync_true)
    aio_thc.add_check('sync_false', sync_false)
    aio_thc.add_check('async_true', async_true)
    aio_thc.add_check('async_false', async_false)

    check_handler = await aio_thc.check_handler()

    assert check_handler.code == 777
    assert check_handler.body['sync_true'] is True
    assert check_handler.body['sync_false'] is False
    assert check_handler.body['async_true'] is True
    assert check_handler.body['async_false'] is False
Пример #13
0
def test_add_check_noncallable():
    aio_thc = Checker()

    with pytest.raises(TypeError):
        aio_thc.add_check('test', 'var')