File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -867,6 +867,38 @@ async def raise_after(t, e):
867867 self .fail ("ValueError not raised" )
868868 self .assertEqual (asyncio .current_task ().cancelling (), 0 )
869869
870+ async def test_error_and_cancel (self ):
871+ event = asyncio .Event ()
872+
873+ async def raise_error ():
874+ event .set ()
875+ await asyncio .sleep (0 )
876+ raise RuntimeError ()
877+
878+ async def inner ():
879+ try :
880+ async with taskgroups .TaskGroup () as tg :
881+ tg .create_task (raise_error ())
882+ await asyncio .sleep (1 )
883+ self .fail ("Sleep in group should have been cancelled" )
884+ except* RuntimeError :
885+ self .assertEqual (asyncio .current_task ().cancelling (), 1 )
886+ self .assertEqual (asyncio .current_task ().cancelling (), 1 )
887+ await asyncio .sleep (1 )
888+ self .fail ("Sleep after group should have been cancelled" )
889+
890+ async def outer ():
891+ t = asyncio .create_task (inner ())
892+ await event .wait ()
893+ self .assertEqual (t .cancelling (), 0 )
894+ t .cancel ()
895+ self .assertEqual (t .cancelling (), 1 )
896+ with self .assertRaises (asyncio .CancelledError ):
897+ await t
898+ self .assertTrue (t .cancelled ())
899+
900+ await outer ()
901+
870902
871903if __name__ == "__main__" :
872904 unittest .main ()
You can’t perform that action at this time.
0 commit comments