Beispiel #1
0
async def test_loop_notify_stop_when_connection_closed(aiopg_connector):
    # We want to make sure that the when the connection is closed, the loop end.
    event = asyncio.Event()
    await aiopg_connector.open_async()
    async with aiopg_connector._pool.acquire() as connection:
        coro = aiopg_connector._loop_notify(event=event, connection=connection)
        await asyncio.sleep(0.1)
        # Currently, the the connection closes, the notifies queue is not
        # awaken. This test validates the "normal" stopping condition, there is
        # a separate test for the timeout.
        connection.close()
        connection.notifies.close(exception=Exception())
        try:
            await asyncio.wait_for(coro, 0.1)
        except asyncio.TimeoutError:
            pytest.fail("Failed to detect that connection was closed and stop")
Beispiel #2
0
async def test_loop_notify_timeout(aiopg_connector):
    # We want to make sure that when the listen starts, we don't listen forever. If the
    # connection closes, we eventually finish the coroutine.
    event = asyncio.Event()
    await aiopg_connector.open_async()
    async with aiopg_connector._pool.acquire() as connection:
        task = asyncio.ensure_future(
            aiopg_connector._loop_notify(event=event,
                                         connection=connection,
                                         timeout=0.01))
        await asyncio.sleep(0.1)
        assert not task.done()
        connection.close()
        try:
            await asyncio.wait_for(task, 0.1)
        except asyncio.TimeoutError:
            pytest.fail("Failed to detect that connection was closed and stop")

    assert not event.is_set()