Beispiel #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
Beispiel #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)