Skip to content

Commit

Permalink
timeout test
Browse files Browse the repository at this point in the history
  • Loading branch information
kramstrom committed Oct 29, 2024
1 parent 5d86a18 commit b39bff7
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions test/async_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,20 @@ async def gen2():
await asyncio.sleep(0.1)
yield 4

with pytest.raises(asyncio.TimeoutError):
async with asyncio.timeout(1):
async for _ in async_concat(gen1(), gen2()):
pass
results = []

async def concat_coro():
async with aclosing(async_concat(gen1(), gen2())) as stream:
async for item in stream:
results.append(item)

concat_task = asyncio.create_task(concat_coro())
await asyncio.sleep(0.5)
concat_task.cancel()
with pytest.raises(asyncio.CancelledError):
await concat_task

assert results == [1]


@pytest.mark.asyncio
Expand Down Expand Up @@ -821,11 +831,11 @@ async def concat_coro():
async for _ in stream:
pass

zip_task = asyncio.create_task(concat_coro())
concat_task = asyncio.create_task(concat_coro())
await asyncio.sleep(0.1)
zip_task.cancel()
concat_task.cancel()
with pytest.raises(asyncio.CancelledError):
await zip_task
await concat_task


@pytest.mark.asyncio
Expand Down

0 comments on commit b39bff7

Please sign in to comment.