@@ -45,21 +45,33 @@ async def test_timeout_at_basic(self):
45
45
self .assertEqual (deadline , cm .when ())
46
46
47
47
async def test_nested_timeouts (self ):
48
- cancel = False
48
+ loop = asyncio .get_running_loop ()
49
+ cancelled = False
49
50
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 :
51
53
# 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 :
54
56
await asyncio .sleep (10 )
57
+ except asyncio .CancelledError :
58
+ cancelled = True
59
+ raise
60
+ self .assertTrue (cancelled )
55
61
self .assertTrue (cm1 .expired ())
56
62
self .assertTrue (cm2 .expired ())
57
63
58
64
async def test_waiter_cancelled (self ):
65
+ loop = asyncio .get_running_loop ()
66
+ cancelled = False
59
67
with self .assertRaises (TimeoutError ):
60
68
async with asyncio .timeout (0.01 ):
61
- with self . assertRaises ( asyncio . CancelledError ) :
69
+ try :
62
70
await asyncio .sleep (10 )
71
+ except asyncio .CancelledError :
72
+ cancelled = True
73
+ raise
74
+ self .assertTrue (cancelled )
63
75
64
76
async def test_timeout_not_called (self ):
65
77
loop = asyncio .get_running_loop ()
0 commit comments