[3.11] GH-109067: fix randomly failing test_async_gen_asyncio_gc_aclose_09 test (GH-109142) (#109150)

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 ccd48623d4)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
This commit is contained in:
Miss Islington (bot) 2023-09-08 10:02:57 -07:00 committed by GitHub
parent c1a2ef5efc
commit 6b2f44ea78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1037,8 +1037,7 @@ async def gen():
while True:
yield 1
finally:
await asyncio.sleep(0.01)
await asyncio.sleep(0.01)
await asyncio.sleep(0)
DONE = 1
async def run():
@ -1048,7 +1047,10 @@ async def run():
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)