Skip to content

Commit d46d753

Browse files
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 48498dd) Co-authored-by: Victor Stinner <[email protected]>
1 parent 24b51b1 commit d46d753

File tree

1 file changed

+0
-47
lines changed

1 file changed

+0
-47
lines changed

Lib/test/test_time.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ class _PyTime(enum.IntEnum):
4747
)
4848

4949

50-
def busy_wait(duration):
51-
deadline = time.monotonic() + duration
52-
while time.monotonic() < deadline:
53-
pass
54-
55-
5650
class TimeTestCase(unittest.TestCase):
5751

5852
def setUp(self):
@@ -496,25 +490,6 @@ def test_process_time(self):
496490
# on Windows
497491
self.assertLess(stop - start, 0.020)
498492

499-
# bpo-33723: A busy loop of 100 ms should increase process_time()
500-
# by at least 15 ms. Tolerate 15 ms because of the bad resolution of
501-
# the clock on Windows (around 15.6 ms).
502-
min_time = 0.015
503-
busy_time = 0.100
504-
505-
# process_time() should include CPU time spent in any thread
506-
start = time.process_time()
507-
busy_wait(busy_time)
508-
stop = time.process_time()
509-
self.assertGreaterEqual(stop - start, min_time)
510-
511-
t = threading.Thread(target=busy_wait, args=(busy_time,))
512-
start = time.process_time()
513-
t.start()
514-
t.join()
515-
stop = time.process_time()
516-
self.assertGreaterEqual(stop - start, min_time)
517-
518493
info = time.get_clock_info('process_time')
519494
self.assertTrue(info.monotonic)
520495
self.assertFalse(info.adjustable)
@@ -535,28 +510,6 @@ def test_thread_time(self):
535510
# on Windows
536511
self.assertLess(stop - start, 0.020)
537512

538-
# bpo-33723: A busy loop of 100 ms should increase thread_time()
539-
# by at least 15 ms, but less than 30 ms in other threads.
540-
# Tolerate 15 and 30 ms because of the bad resolution
541-
# of the clock on Windows (around 15.6 ms).
542-
min_time = 0.015
543-
max_time = 0.030
544-
busy_time = 0.100
545-
546-
# thread_time() should include CPU time spent in current thread...
547-
start = time.thread_time()
548-
busy_wait(busy_time)
549-
stop = time.thread_time()
550-
self.assertGreaterEqual(stop - start, min_time)
551-
552-
# ...but not in other threads
553-
t = threading.Thread(target=busy_wait, args=(busy_time,))
554-
start = time.thread_time()
555-
t.start()
556-
t.join()
557-
stop = time.thread_time()
558-
self.assertLess(stop - start, max_time)
559-
560513
info = time.get_clock_info('thread_time')
561514
self.assertTrue(info.monotonic)
562515
self.assertFalse(info.adjustable)

0 commit comments

Comments
 (0)