Beispiel #1
0
async def test_join_task_cancelled_no_env(wait):
    """Test joining a task, but cancelled"""
    n = Scope(timeout=1)

    t = n.spawn(run10())

    t.cancel()
    with pytest.raises(asyncio.CancelledError):
        await t

    n.finalize()
    if wait:
        await asyncio.wait_for(n, 2)
    else:
        await n
Beispiel #2
0
async def test_join_task_raises_no_env():
    """Test joining a task, but raises"""
    before = time.time()

    n = Scope(timeout=1)

    t = n.spawn(raiser())
    with pytest.raises(ValueError):
        # Catching the error here prevents bubbling
        await t

    n.finalize()
    await n

    after = time.time()
    assert (after - before) < 0.3
Beispiel #3
0
async def test_join_then_new_no_env():
    """Test joining a task, then spawn another one"""
    before = time.time()

    n = Scope(timeout=1)

    # takes 0.2 seconds
    await n.spawn(trivial())
    assert (time.time() - before) < 0.3

    # At this point, the scope should be still started
    assert not n.done()

    # will 0.2 seconds
    n.spawn(trivial())

    n.finalize()
    await n

    after = time.time()
    assert (after - before) < 0.5