async def test_token_wait(event_loop): token = CancelToken('token') event_loop.call_soon(token.trigger) done, pending = await asyncio.wait([token.wait()], timeout=0.1) assert len(done) == 1 assert len(pending) == 0 assert token.triggered
async def test_wait_cancel_pending_tasks_on_cancellation(event_loop): token = CancelToken('token').chain(CancelToken('token2')).chain( CancelToken('token3')) token_wait_coroutine = token.wait() done, pending = await asyncio.wait([token_wait_coroutine], timeout=0.1) assert len(done) == 0 assert len(pending) == 1 pending_task = pending.pop() assert pending_task._coro == token_wait_coroutine pending_task.cancel() await assert_only_current_task_not_done()