mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
gh-110088, gh-109878: Fix test_asyncio timeouts (#110092)
Fix test_asyncio timeouts: don't measure the maximum duration, a test
should not measure a CI performance. Only measure the minimum
duration when a task has a timeout or delay. Add CLOCK_RES to
test_asyncio.utils.
(cherry picked from commit db0a258e79
)
This commit is contained in:
parent
d81bcc2327
commit
184ce1414b
7 changed files with 19 additions and 54 deletions
|
@ -163,29 +163,25 @@ class ProactorTests(test_utils.TestCase):
|
|||
|
||||
# Wait for unset event with 0.5s timeout;
|
||||
# result should be False at timeout
|
||||
fut = self.loop._proactor.wait_for_handle(event, 0.5)
|
||||
timeout = 0.5
|
||||
fut = self.loop._proactor.wait_for_handle(event, timeout)
|
||||
start = self.loop.time()
|
||||
done = self.loop.run_until_complete(fut)
|
||||
elapsed = self.loop.time() - start
|
||||
|
||||
self.assertEqual(done, False)
|
||||
self.assertFalse(fut.result())
|
||||
# bpo-31008: Tolerate only 450 ms (at least 500 ms expected),
|
||||
# because of bad clock resolution on Windows
|
||||
self.assertTrue(0.45 <= elapsed <= 0.9, elapsed)
|
||||
self.assertGreaterEqual(elapsed, timeout - test_utils.CLOCK_RES)
|
||||
|
||||
_overlapped.SetEvent(event)
|
||||
|
||||
# Wait for set event;
|
||||
# result should be True immediately
|
||||
fut = self.loop._proactor.wait_for_handle(event, 10)
|
||||
start = self.loop.time()
|
||||
done = self.loop.run_until_complete(fut)
|
||||
elapsed = self.loop.time() - start
|
||||
|
||||
self.assertEqual(done, True)
|
||||
self.assertTrue(fut.result())
|
||||
self.assertTrue(0 <= elapsed < 0.3, elapsed)
|
||||
|
||||
# asyncio issue #195: cancelling a done _WaitHandleFuture
|
||||
# must not crash
|
||||
|
@ -199,11 +195,8 @@ class ProactorTests(test_utils.TestCase):
|
|||
# CancelledError should be raised immediately
|
||||
fut = self.loop._proactor.wait_for_handle(event, 10)
|
||||
fut.cancel()
|
||||
start = self.loop.time()
|
||||
with self.assertRaises(asyncio.CancelledError):
|
||||
self.loop.run_until_complete(fut)
|
||||
elapsed = self.loop.time() - start
|
||||
self.assertTrue(0 <= elapsed < 0.1, elapsed)
|
||||
|
||||
# asyncio issue #195: cancelling a _WaitHandleFuture twice
|
||||
# must not crash
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue