]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] GH-109067: fix randomly failing `test_async_gen_asyncio_gc_aclose_09` test...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 12 Sep 2023 13:56:02 +0000 (06:56 -0700)
committerGitHub <noreply@github.com>
Tue, 12 Sep 2023 13:56:02 +0000 (15:56 +0200)
GH-109067: fix randomly failing `test_async_gen_asyncio_gc_aclose_09` test (GH-109142)

Use `asyncio.sleep(0)` instead of short sleeps.
(cherry picked from commit ccd48623d4860e730a16f3f252d67bfea8c1e905)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Lib/test/test_asyncgen.py

index 09e4010b0e53d6fdd291d8f878de6d8c07dee194..9a9343781cd40c543dace0290e31ca1dd3a2b55a 100644 (file)
@@ -1057,8 +1057,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():
@@ -1068,7 +1067,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)