コード例 #1
0
async def test_cancel_double():
    """
    Cancelled externally, twice
    """
    async def cleaner(scope):
        await asyncio.sleep(0.2)
        scope.cancel()
        # Should we raise something in case of double close?
        scope.cancel()

    scope = Scope()

    task = asyncio.ensure_future(cleaner(scope))

    async with scope:
        scope << run10()

    await task
    assert scope.done() and scope.exception() is None
コード例 #2
0
async def test_cancel_double_exception():
    """
    Cancelled externally, twice, with exception
    """
    async def cleaner(scope):
        await asyncio.sleep(0.2)
        scope.cancel(ValueError('boom'))
        # Should we raise something in case of double close?
        scope.cancel(ValueError('boom'))

    scope = Scope()

    task = asyncio.ensure_future(cleaner(scope))

    with pytest.raises(ValueError):
        async with scope:
            scope << run10()

    await task
    assert scope.done() and isinstance(scope.exception(), ValueError)
コード例 #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