From be949bbfa64912e2fb80132335c6654594a6032b Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 29 Apr 2024 17:25:20 +0200 Subject: [PATCH 1/2] gh-88494: Reduce CLOCK_RES to 1 ms in tests On Windows, time.monotonic() now calls QueryPerformanceCounter() which has a resolution of 100 ns. Reduce CLOCK_RES from 50 or 100 ms to 1 ms. --- Lib/test/_test_multiprocessing.py | 4 ++-- Lib/test/test_asyncio/utils.py | 6 ++---- Lib/test/test_capi/test_time.py | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index a74b61013c4848..9bf30b2cdc9bef 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -84,9 +84,9 @@ raise unittest.SkipTest("libasan has a pthread_create() dead lock related to thread+fork") -# gh-110666: Tolerate a difference of 100 ms when comparing timings +# gh-110666: Tolerate a difference of 1 ms when comparing timings # (clock resolution) -CLOCK_RES = 0.100 +CLOCK_RES = 0.001 def latin(s): diff --git a/Lib/test/test_asyncio/utils.py b/Lib/test/test_asyncio/utils.py index 44943e1fa7bc4e..c59b27bc6c5780 100644 --- a/Lib/test/test_asyncio/utils.py +++ b/Lib/test/test_asyncio/utils.py @@ -36,10 +36,8 @@ from test.support import threading_helper -# Use the maximum known clock resolution (gh-75191, gh-110088): Windows -# GetTickCount64() has a resolution of 15.6 ms. Use 50 ms to tolerate rounding -# issues. -CLOCK_RES = 0.050 +# Tolerate 1 ms difference when comparing timings. +CLOCK_RES = 0.001 def data_file(*filename): diff --git a/Lib/test/test_capi/test_time.py b/Lib/test/test_capi/test_time.py index 10b7fbf2c372a3..99aac461d1221d 100644 --- a/Lib/test/test_capi/test_time.py +++ b/Lib/test/test_capi/test_time.py @@ -9,7 +9,7 @@ SEC_TO_NS = 10 ** 9 DAY_TO_SEC = (24 * 60 * 60) # Worst clock resolution: maximum delta between two clock reads. -CLOCK_RES = 0.050 +CLOCK_RES = 0.001 class CAPITest(unittest.TestCase): From eb4e7d36d8c7b932ade8c7af6c9ba7a3978914e3 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 29 Apr 2024 18:53:20 +0200 Subject: [PATCH 2/2] Fix test_asyncio.test_windows_events --- Lib/test/test_asyncio/test_windows_events.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_asyncio/test_windows_events.py b/Lib/test/test_asyncio/test_windows_events.py index 0c128c599ba011..fae1a7baa13707 100644 --- a/Lib/test/test_asyncio/test_windows_events.py +++ b/Lib/test/test_asyncio/test_windows_events.py @@ -177,6 +177,10 @@ def test_wait_for_handle(self): event = _overlapped.CreateEvent(None, True, False, None) self.addCleanup(_winapi.CloseHandle, event) + # RegisterWaitForSingleObject() has a resolution of 15.6 ms. + # Tolerate 50 ms difference when comparing timings. + CLOCK_RES = 0.050 + # Wait for unset event with 0.5s timeout; # result should be False at timeout timeout = 0.5 @@ -187,7 +191,7 @@ def test_wait_for_handle(self): self.assertEqual(done, False) self.assertFalse(fut.result()) - self.assertGreaterEqual(elapsed, timeout - test_utils.CLOCK_RES) + self.assertGreaterEqual(elapsed, timeout - CLOCK_RES) _overlapped.SetEvent(event)