]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-109067: fix randomly failing `test_async_gen_asyncio_gc_aclose_09` test (#109142)
authorKumar Aditya <kumaraditya@python.org>
Fri, 8 Sep 2023 16:27:58 +0000 (21:57 +0530)
committerGitHub <noreply@github.com>
Fri, 8 Sep 2023 16:27:58 +0000 (16:27 +0000)
Use `asyncio.sleep(0)` instead of short sleeps.

Lib/test/test_asyncgen.py

index 4f00558770dafdfd020d54babdd155f26c3e0417..a49630112af5106d37ad57bf872c7def1e55a82e 100644 (file)
@@ -1058,8 +1058,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
                 while True:
                     yield 1
             finally:
-                await asyncio.sleep(0.01)
-                await asyncio.sleep(0.01)
+                await asyncio.sleep(0)
                 DONE = 1
 
         async def run():
@@ -1069,7 +1068,10 @@ class AsyncGenAsyncioTest(unittest.TestCase):
             del g
             gc_collect()  # For PyPy or other GCs.
 
-            await asyncio.sleep(0.1)
+            # Starts running the aclose task
+            await asyncio.sleep(0)
+            # For asyncio.sleep(0) in finally block
+            await asyncio.sleep(0)
 
         self.loop.run_until_complete(run())
         self.assertEqual(DONE, 1)