8000 bpo-33723: Remove busy loop from test_time (GH-10773) · python/cpython@48498dd · GitHub
[go: up one dir, main page]

Skip to content

Commit 48498dd

Browse files
authored
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.
1 parent f7e4d36 commit 48498dd

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
@@ -46,12 +46,6 @@ class _PyTime(enum.IntEnum):
4646
)
4747

4848

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

5751
def setUp(self):
@@ -495,25 +489,6 @@ def test_process_time(self):
495489
# on Windows
496490
self.assertLess(stop - start, 0.020)
497491

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

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

0 commit comments

Comments
 (0)
0