bpo-33723: Remove busy loop from test_time (GH-10773)
The "busy loops" of test_process_time() and test_thread_time() are
not reliable and fail randomly on Windows: remove them.
(cherry picked from commit 48498dd57f
)
Co-authored-by: Victor Stinner <vstinner@redhat.com>
This commit is contained in:
parent
24b51b1a49
commit
d46d753d15
|
@ -47,12 +47,6 @@ ROUNDING_MODES = (
|
|||
)
|
||||
|
||||
|
||||
def busy_wait(duration):
|
||||
deadline = time.monotonic() + duration
|
||||
while time.monotonic() < deadline:
|
||||
pass
|
||||
|
||||
|
||||
class TimeTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -496,25 +490,6 @@ class TimeTestCase(unittest.TestCase):
|
|||
# on Windows
|
||||
self.assertLess(stop - start, 0.020)
|
||||
|
||||
# bpo-33723: A busy loop of 100 ms should increase process_time()
|
||||
# by at least 15 ms. Tolerate 15 ms because of the bad resolution of
|
||||
# the clock on Windows (around 15.6 ms).
|
||||
min_time = 0.015
|
||||
busy_time = 0.100
|
||||
|
||||
# process_time() should include CPU time spent in any thread
|
||||
start = time.process_time()
|
||||
busy_wait(busy_time)
|
||||
stop = time.process_time()
|
||||
self.assertGreaterEqual(stop - start, min_time)
|
||||
|
||||
t = threading.Thread(target=busy_wait, args=(busy_time,))
|
||||
start = time.process_time()
|
||||
t.start()
|
||||
t.join()
|
||||
stop = time.process_time()
|
||||
self.assertGreaterEqual(stop - start, min_time)
|
||||
|
||||
info = time.get_clock_info('process_time')
|
||||
self.assertTrue(info.monotonic)
|
||||
self.assertFalse(info.adjustable)
|
||||
|
@ -535,28 +510,6 @@ class TimeTestCase(unittest.TestCase):
|
|||
# on Windows
|
||||
self.assertLess(stop - start, 0.020)
|
||||
|
||||
# bpo-33723: A busy loop of 100 ms should increase thread_time()
|
||||
# by at least 15 ms, but less than 30 ms in other threads.
|
||||
# Tolerate 15 and 30 ms because of the bad resolution
|
||||
# of the clock on Windows (around 15.6 ms).
|
||||
min_time = 0.015
|
||||
max_time = 0.030
|
||||
busy_time = 0.100
|
||||
|
||||
# thread_time() should include CPU time spent in current thread...
|
||||
start = time.thread_time()
|
||||
busy_wait(busy_time)
|
||||
stop = time.thread_time()
|
||||
self.assertGreaterEqual(stop - start, min_time)
|
||||
|
||||
# ...but not in other threads
|
||||
t = threading.Thread(target=busy_wait, args=(busy_time,))
|
||||
start = time.thread_time()
|
||||
t.start()
|
||||
t.join()
|
||||
stop = time.thread_time()
|
||||
self.assertLess(stop - start, max_time)
|
||||
|
||||
info = time.get_clock_info('thread_time')
|
||||
self.assertTrue(info.monotonic)
|
||||
self.assertFalse(info.adjustable)
|
||||
|
|
Loading…
Reference in New Issue