File tree Expand file tree Collapse file tree 1 file changed +5
-7
lines changed Expand file tree Collapse file tree 1 file changed +5
-7
lines changed Original file line number Diff line number Diff line change @@ -30,16 +30,14 @@ async def test_client_does_not_block_loop(self):
30
30
31
31
# If the loop is being blocked, at least one iteration will have a latency much more than 0.1 seconds
32
32
async def background_task ():
33
- last_run = None
33
+ start = time . monotonic ()
34
34
try :
35
35
while True :
36
- if last_run is not None :
37
- latencies .append (time .monotonic () - last_run )
38
- last_run = time .monotonic ()
36
+ start = time .monotonic ()
39
37
await asyncio .sleep (0.1 )
38
+ latencies .append (time .monotonic () - start )
40
39
except asyncio .CancelledError :
41
- if last_run is not None :
42
- latencies .append (time .monotonic () - last_run )
40
+ latencies .append (time .monotonic () - start )
43
41
raise
44
42
45
43
t = asyncio .create_task (background_task ())
@@ -54,5 +52,5 @@ async def background_task():
54
52
self .assertLessEqual (
55
53
sorted (latencies , reverse = True )[0 ],
56
54
0.2 ,
57
- "Task took longer than twice its sleep time to run again " ,
55
+ "Background task was blocked from running " ,
58
56
)
You can’t perform that action at this time.
0 commit comments