]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
test_asyncio: run_until() implements exponential sleep (#93866)
authorVictor Stinner <vstinner@python.org>
Wed, 15 Jun 2022 16:28:00 +0000 (18:28 +0200)
committerGitHub <noreply@github.com>
Wed, 15 Jun 2022 16:28:00 +0000 (18:28 +0200)
run_until() of test.test_asyncio.utils now uses an exponential sleep
delay (max: 1 second), rather than a fixed delay of 1 ms. Similar
design than support.sleeping_retry() wait strategy that applies
exponential backoff.

Lib/test/test_asyncio/utils.py

index 07ef33d3fc2442d634f869c694c70710febaa73e..507daa11c28bca239f4d1acf717f6d9db97a5df4 100644 (file)
@@ -109,10 +109,12 @@ def run_briefly(loop):
 
 
 def run_until(loop, pred, timeout=support.SHORT_TIMEOUT):
+    delay = 0.001
     for _ in support.busy_retry(timeout, error=False):
         if pred():
             break
-        loop.run_until_complete(tasks.sleep(0.001))
+        loop.run_until_complete(tasks.sleep(delay))
+        delay = max(delay * 2, 1.0)
     else:
         raise futures.TimeoutError()