Ejemplo n.º 1
0
def test_asyncio_thread_has_running_thread_and_loop_after_start():
    from moler.asyncio_runner import AsyncioLoopThread

    thread4async = AsyncioLoopThread()
    thread4async.start()
    assert thread4async.is_alive()
    assert thread4async.ev_loop.is_running()
Ejemplo n.º 2
0
def test_asyncio_thread_can_run_async_function():
    from moler.asyncio_runner import AsyncioLoopThread

    thread4async = AsyncioLoopThread()
    thread4async.start()

    async def my_coro(param):
        await asyncio.sleep(0.1)
        return "called with param={}".format(param)

    assert "called with param=2" == thread4async.run_async_coroutine(my_coro(param=2), timeout=0.2)
Ejemplo n.º 3
0
def test_asyncio_thread_can_timeout_async_function():
    from moler.asyncio_runner import AsyncioLoopThread
    from moler.exceptions import MolerTimeout

    thread4async = AsyncioLoopThread()
    thread4async.start()

    async def my_coro(param):
        await asyncio.sleep(0.2)
        return "called with param={}".format(param)

    with pytest.raises(MolerTimeout):
        thread4async.run_async_coroutine(my_coro(param=2), timeout=0.1)