@@ -45,21 +45,33 @@ async def test_timeout_at_basic(self):
4545 self .assertEqual (deadline , cm .when ())
4646
4747 async def test_nested_timeouts (self ):
48- cancel = False
48+ loop = asyncio .get_running_loop ()
49+ cancelled = False
4950 with self .assertRaises (TimeoutError ):
50- async with asyncio .timeout (0.01 ) as cm1 :
51+ deadline = loop .time () + 0.01
52+ async with asyncio .timeout_at (deadline ) as cm1 :
5153 # Only the topmost context manager should raise TimeoutError
52- with self . assertRaises ( asyncio . CancelledError ) :
53- async with asyncio .timeout ( 0.01 ) as cm2 :
54+ try :
55+ async with asyncio .timeout_at ( deadline ) as cm2 :
5456 await asyncio .sleep (10 )
57+ except asyncio .CancelledError :
58+ cancelled = True
59+ raise
60+ self .assertTrue (cancelled )
5561 self .assertTrue (cm1 .expired ())
5662 self .assertTrue (cm2 .expired ())
5763
5864 async def test_waiter_cancelled (self ):
65+ loop = asyncio .get_running_loop ()
66+ cancelled = False
5967 with self .assertRaises (TimeoutError ):
6068 async with asyncio .timeout (0.01 ):
61- with self . assertRaises ( asyncio . CancelledError ) :
69+ try :
6270 await asyncio .sleep (10 )
71+ except asyncio .CancelledError :
72+ cancelled = True
73+ raise
74+ self .assertTrue (cancelled )
6375
6476 async def test_timeout_not_called (self ):
6577 loop = asyncio .get_running_loop ()
0 commit comments