[3.11] gh-109833: Fix asyncio test_wait_for() (GH-109834) (#109838)

gh-109833: Fix asyncio test_wait_for() (GH-109834)

Expect the test to be "short" but don't measure the exact performance
of the CI. SHORT_TIMEOUT is about 30 seconds whereas the cancelled
coroutine takes around 1 hour.
(cherry picked from commit f29bc9c9a0)

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Miss Islington (bot) 2023-09-25 07:22:41 -07:00 committed by GitHub
parent 97ea90194c
commit 9238c6880e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import asyncio import asyncio
import unittest import unittest
import time import time
from test import support
def tearDownModule(): def tearDownModule():
@ -130,7 +131,7 @@ async def foo():
nonlocal foo_running nonlocal foo_running
foo_running = True foo_running = True
try: try:
await asyncio.sleep(10) await asyncio.sleep(support.LONG_TIMEOUT)
finally: finally:
foo_running = False foo_running = False
return 'done' return 'done'
@ -144,7 +145,7 @@ async def foo():
self.assertTrue(fut.done()) self.assertTrue(fut.done())
# it should have been cancelled due to the timeout # it should have been cancelled due to the timeout
self.assertTrue(fut.cancelled()) self.assertTrue(fut.cancelled())
self.assertLess(t1 - t0, 0.5) self.assertLess(t1 - t0, support.SHORT_TIMEOUT)
self.assertEqual(foo_running, False) self.assertEqual(foo_running, False)
async def test_wait_for_blocking(self): async def test_wait_for_blocking(self):