Skip to content

Commit b076e6d

Browse files
committed
multi-cancel test.. which should perhaps be fixed
1 parent e9596a2 commit b076e6d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/trio/_tests/test_channel.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,3 +598,26 @@ async def handle_value(
598598
await nursery.start(handle_value, recv_chan, 0)
599599
await nursery.start(handle_value, recv_chan, 1)
600600
event.set()
601+
602+
603+
async def test_as_safe_channel_multi_cancel() -> None:
604+
@as_safe_channel
605+
async def agen() -> AsyncGenerator[None]:
606+
try:
607+
yield
608+
finally:
609+
# this will give a warning of ASYNC120, although it's not technically a
610+
# problem of swallowing existing exceptions
611+
await trio.lowlevel.checkpoint()
612+
613+
with trio.CancelScope() as cs:
614+
with RaisesGroup(
615+
RaisesGroup(
616+
trio.Cancelled, trio.Cancelled, match="^Exceptions from Trio nursery$"
617+
),
618+
match=r"^Encountered exception during cleanup of generator object, as well as exception in the contextmanager body - unable to unwrap.$",
619+
):
620+
async with agen() as recv_chan:
621+
async for _ in recv_chan: # pragma: no branch
622+
cs.cancel()
623+
await trio.lowlevel.checkpoint()

0 commit comments

Comments
 (0)