File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
packages/common-library/tests Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change 11import asyncio
2+ import time
23from concurrent .futures import ThreadPoolExecutor
34from typing import Any
45
@@ -98,11 +99,12 @@ def fetchone(self) -> Any: # pylint: disable=no-self-use
9899
99100async def test_cancel_and_wait ():
100101 state = {"started" : False , "cancelled" : False , "cleaned_up" : False }
102+ SLEEP_TIME = 5 # seconds
101103
102104 async def coro ():
103105 try :
104106 state ["started" ] = True
105- await asyncio .sleep (5 )
107+ await asyncio .sleep (SLEEP_TIME )
106108 except asyncio .CancelledError :
107109 state ["cancelled" ] = True
108110 raise
@@ -112,8 +114,11 @@ async def coro():
112114 task = asyncio .create_task (coro ())
113115 await asyncio .sleep (0.1 ) # Let coro start
114116
117+ start = time .time ()
115118 await cancel_and_wait (task )
116119
120+ elapsed = time .time () - start
121+ assert elapsed < SLEEP_TIME , "Task should be cancelled quickly"
117122 assert task .done ()
118123 assert task .cancelled ()
119124 assert state ["started" ]
@@ -142,7 +147,7 @@ async def outer_coro():
142147 except asyncio .CancelledError :
143148 assert (
144149 not inner_task .cancelled ()
145- ), "Internal Task should not be cancelled yet (shielded) "
150+ ), "Internal Task DOES NOT RAISE CancelledError "
146151 raise
147152
148153 # Cancel the wrapper after a short delay
You can’t perform that action at this time.
0 commit comments