Exemplo n.º 1
0
async def test_async_call(loop):
    fut = asyncio.Future(loop=loop)

    async def func(val1, val2):
        fut.set_result((val1, val2))

    async_call(loop, func, 1, val2=2)
    await asyncio.wait([fut], timeout=1)
    assert fut.result() == (1, 2)
Exemplo n.º 2
0
async def test_async_call_delay_td(loop):
    delay = .1
    timeout = .2

    fut = asyncio.Future(loop=loop)

    async def func(val1, val2):
        fut.set_result((val1, val2))

    start = time.time()
    async_call(loop, func, 1, val2=2, delay=datetime.timedelta(seconds=delay))
    await asyncio.wait([fut], timeout=timeout)
    assert time.time() - start >= delay
    assert fut.result() == (1, 2)
Exemplo n.º 3
0
async def test_postgres_health_ok(app: Application, postgres: str,
                                  loop: asyncio.AbstractEventLoop) -> None:
    db = Postgres(postgres)
    app.add('postgres', db)

    async def start():
        await app.run_prepare()
        await db.start()

    res = async_call(loop, start)
    await asyncio.sleep(1)

    result = await app.health()
    assert 'postgres' in result
    assert result['postgres'] is None

    if res['fut'] is not None:
        res['fut'].cancel()
Exemplo n.º 4
0
async def test_amqp_health_ok(app: Application, rabbitmq: str,
                              loop: asyncio.AbstractEventLoop) -> None:
    amqp = Amqp(rabbitmq)
    app.add('amqp', amqp)

    async def start():
        await app.run_prepare()
        await amqp.start()

    res = async_call(loop, start)
    await asyncio.sleep(1)

    result = await app.health()
    assert 'amqp' in result
    assert result['amqp'] is None

    if res['fut'] is not None:
        res['fut'].cancel()
Exemplo n.º 5
0
async def test_http_health_ok(app: Application, unused_tcp_port: int,
                              loop: asyncio.AbstractEventLoop) -> None:
    http = Server('127.0.0.1', unused_tcp_port, Handler)
    app.add('http', http)

    async def start():
        await app.run_prepare()
        await http.start()

    res = async_call(loop, start)
    await asyncio.sleep(1)

    result = await app.health()
    assert 'http' in result
    assert result['http'] is None

    if res['fut'] is not None:
        res['fut'].cancel()
Exemplo n.º 6
0
async def test_postgres_health_bad(app: Application, unused_tcp_port: int,
                                   loop: asyncio.AbstractEventLoop) -> None:
    url = 'postgres://postgres@%s:%s/postgres' % ('127.0.0.1', unused_tcp_port)

    db = Postgres(url)
    app.add('postgres', db)

    async def start():
        await app.run_prepare()
        await db.start()

    res = async_call(loop, start)
    await asyncio.sleep(1)

    result = await app.health()
    assert 'postgres' in result
    assert result['postgres'] is not None
    assert isinstance(result['postgres'], BaseException)

    if res['fut'] is not None:
        res['fut'].cancel()
Exemplo n.º 7
0
async def test_amqp_health_bad(app: Application, unused_tcp_port: int,
                               loop: asyncio.AbstractEventLoop) -> None:
    url = 'amqp://*****:*****@%s:%s/' % ('127.0.0.1', unused_tcp_port)

    amqp = Amqp(url)
    app.add('amqp', amqp)

    async def start():
        await app.run_prepare()
        await amqp.start()

    res = async_call(loop, start)
    await asyncio.sleep(1)

    result = await app.health()
    assert 'amqp' in result
    assert result['amqp'] is not None
    assert isinstance(result['amqp'], BaseException)

    if res['fut'] is not None:
        res['fut'].cancel()