bpo-33723: Fix test_time.test_thread_time() (GH-8267) · python/cpython@d6345de (original) (raw)

`@@ -529,19 +529,24 @@ def test_thread_time(self):

`

529

529

`# on Windows

`

530

530

`self.assertLess(stop - start, 0.020)

`

531

531

``

``

532

`+

bpo-33723: A busy loop of 100 ms should increase thread_time()

`

``

533

`+

by at least 15 ms

`

``

534

`+

min_time = 0.015

`

``

535

`+

busy_time = 0.100

`

``

536

+

532

537

`# thread_time() should include CPU time spent in current thread...

`

533

538

`start = time.thread_time()

`

534

``

`-

busy_wait(0.100)

`

``

539

`+

busy_wait(busy_time)

`

535

540

`stop = time.thread_time()

`

536

``

`-

self.assertGreaterEqual(stop - start, 0.020) # machine busy?

`

``

541

`+

self.assertGreaterEqual(stop - start, min_time)

`

537

542

``

538

543

`# ...but not in other threads

`

539

``

`-

t = threading.Thread(target=busy_wait, args=(0.100,))

`

``

544

`+

t = threading.Thread(target=busy_wait, args=(busy_time,))

`

540

545

`start = time.thread_time()

`

541

546

`t.start()

`

542

547

`t.join()

`

543

548

`stop = time.thread_time()

`

544

``

`-

self.assertLess(stop - start, 0.020)

`

``

549

`+

self.assertLess(stop - start, min_time)

`

545

550

``

546

551

`info = time.get_clock_info('thread_time')

`

547

552

`self.assertTrue(info.monotonic)

`