Exemplo n.º 1
0
async def test_siblings(
    event_loop, root_store: FutureStore, child_store: FutureStore
):
    async def coro(store):
        await asyncio.sleep(0.1)
        await store.reject(RuntimeError, TaskPriority.LOW)

    task1 = child_store.create_task(coro(child_store), TaskPriority.LOW)
    assert root_store.future_sets[TaskPriority.LOW]
    assert child_store.future_sets[TaskPriority.LOW]

    with pytest.raises(RuntimeError):
        await task1

    await asyncio.sleep(0.1)

    assert not root_store.future_sets[TaskPriority.LOW]
    assert not child_store.future_sets[TaskPriority.LOW]

    child = child_store.get_child().get_child().get_child()
    task = child.create_task(coro(child))

    assert root_store.future_sets[TaskPriority.LOW]
    assert child_store.future_sets[TaskPriority.LOW]
    assert child.future_sets[TaskPriority.LOW]

    with pytest.raises(RuntimeError):
        await task

    await asyncio.sleep(0.1)

    assert not root_store.future_sets[TaskPriority.LOW]
    assert not child_store.future_sets[TaskPriority.LOW]
    assert not child.future_sets[TaskPriority.LOW]
Exemplo n.º 2
0
async def test_siblings(event_loop, root_store: FutureStore,
                        child_store: FutureStore):

    async def coro(store):
        await asyncio.sleep(0.1, loop=event_loop)
        await store.reject_all(RuntimeError)

    task1 = child_store.create_task(coro(child_store))
    assert root_store.futures
    assert child_store.futures

    with pytest.raises(RuntimeError):
        await task1

    await asyncio.sleep(0.1, loop=event_loop)

    assert not root_store.futures
    assert not child_store.futures

    child = child_store.get_child().get_child().get_child()
    task = child.create_task(coro(child))

    assert root_store.futures
    assert child_store.futures
    assert child.futures

    with pytest.raises(RuntimeError):
        await task

    await asyncio.sleep(0.1, loop=event_loop)

    assert not root_store.futures
    assert not child_store.futures
    assert not child.futures
Exemplo n.º 3
0
def root_store(event_loop):
    store = FutureStore(loop=event_loop)
    try:
        yield store
    finally:
        event_loop.run_until_complete(store.reject_all(
            Exception("Cancelling")))
Exemplo n.º 4
0
def root_store(event_loop):
    store = FutureStore(loop=event_loop)
    try:
        yield store
    finally:
        event_loop.run_until_complete(
            store.reject(Exception("Cancelling"), TaskPriority.HIGH)
        )
Exemplo n.º 5
0
async def test_reject_all(event_loop, root_store: FutureStore,
                          child_store: FutureStore):

    future1 = root_store.create_future()
    future2 = child_store.create_future()

    assert root_store.futures
    assert child_store.futures

    await root_store.reject_all(RuntimeError)
    await asyncio.sleep(0.1, loop=event_loop)

    assert isinstance(future1.exception(), RuntimeError)
    assert isinstance(future2.exception(), RuntimeError)
    assert not root_store.futures
    assert not child_store.futures
Exemplo n.º 6
0
async def test_reject(
    event_loop, root_store: FutureStore, child_store: FutureStore
):

    future1 = root_store.create_future(TaskPriority.LOW)
    future2 = child_store.create_future(TaskPriority.HIGH)

    assert root_store.future_sets[TaskPriority.LOW]
    assert child_store.future_sets[TaskPriority.HIGH]

    await root_store.reject(RuntimeError, TaskPriority.HIGH)
    await asyncio.sleep(0.1)

    assert isinstance(future1.exception(), RuntimeError)
    assert isinstance(future2.exception(), RuntimeError)
    assert not root_store.future_sets[TaskPriority.LOW]
    assert not child_store.future_sets[TaskPriority.HIGH]