|
84 | 84 | raise unittest.SkipTest("libasan has a pthread_create() dead lock related to thread+fork")
|
85 | 85 |
|
86 | 86 |
|
| 87 | +# gh-110666: Tolerate a difference of 100 ms when comparing timings |
| 88 | +# (clock resolution) |
| 89 | +CLOCK_RES = 0.100 |
| 90 | + |
| 91 | + |
87 | 92 | def latin(s):
|
88 | 93 | return s.encode('latin')
|
89 | 94 |
|
@@ -1655,8 +1660,7 @@ def _test_waitfor_timeout_f(cls, cond, state, success, sem):
|
1655 | 1660 | dt = time.monotonic()
|
1656 | 1661 | result = cond.wait_for(lambda : state.value==4, timeout=expected)
|
1657 | 1662 | dt = time.monotonic() - dt
|
1658 |
| - # borrow logic in assertTimeout() from test/lock_tests.py |
1659 |
| - if not result and expected * 0.6 <= dt: |
| 1663 | + if not result and (expected - CLOCK_RES) <= dt: |
1660 | 1664 | success.value = True
|
1661 | 1665 |
|
1662 | 1666 | @unittest.skipUnless(HAS_SHAREDCTYPES, 'needs sharedctypes')
|
@@ -2678,14 +2682,11 @@ def test_make_pool(self):
|
2678 | 2682 | p.join()
|
2679 | 2683 |
|
2680 | 2684 | def test_terminate(self):
|
2681 |
| - result = self.pool.map_async( |
2682 |
| - time.sleep, [0.1 for i in range(10000)], chunksize=1 |
2683 |
| - ) |
| 2685 | + # Simulate slow tasks which take "forever" to complete |
| 2686 | + args = [support.LONG_TIMEOUT for i in range(10_000)] |
| 2687 | + result = self.pool.map_async(time.sleep, args, chunksize=1) |
2684 | 2688 | self.pool.terminate()
|
2685 |
| - join = TimingWrapper(self.pool.join) |
2686 |
| - join() |
2687 |
| - # Sanity check the pool didn't wait for all tasks to finish |
2688 |
| - self.assertLess(join.elapsed, 2.0) |
| 2689 | + self.pool.join() |
2689 | 2690 |
|
2690 | 2691 | def test_empty_iterable(self):
|
2691 | 2692 | # See Issue 12157
|
@@ -4870,7 +4871,7 @@ class TestWait(unittest.TestCase):
|
4870 | 4871 | def _child_test_wait(cls, w, slow):
|
4871 | 4872 | for i in range(10):
|
4872 | 4873 | if slow:
|
4873 |
| - time.sleep(random.random()*0.1) |
| 4874 | + time.sleep(random.random() * 0.100) |
4874 | 4875 | w.send((i, os.getpid()))
|
4875 | 4876 | w.close()
|
4876 | 4877 |
|
@@ -4910,7 +4911,7 @@ def _child_test_wait_socket(cls, address, slow):
|
4910 | 4911 | s.connect(address)
|
4911 | 4912 | for i in range(10):
|
4912 | 4913 | if slow:
|
4913 |
| - time.sleep(random.random()*0.1) |
| 4914 | + time.sleep(random.random() * 0.100) |
4914 | 4915 | s.sendall(('%s\n' % i).encode('ascii'))
|
4915 | 4916 | s.close()
|
4916 | 4917 |
|
@@ -4959,25 +4960,19 @@ def test_wait_socket_slow(self):
|
4959 | 4960 | def test_wait_timeout(self):
|
4960 | 4961 | from multiprocessing.connection import wait
|
4961 | 4962 |
|
4962 |
| - expected = 5 |
| 4963 | + timeout = 5.0 # seconds |
4963 | 4964 | a, b = multiprocessing.Pipe()
|
4964 | 4965 |
|
4965 | 4966 | start = time.monotonic()
|
4966 |
| - res = wait([a, b], expected) |
| 4967 | + res = wait([a, b], timeout) |
4967 | 4968 | delta = time.monotonic() - start
|
4968 | 4969 |
|
4969 | 4970 | self.assertEqual(res, [])
|
4970 |
| - self.assertLess(delta, expected * 2) |
4971 |
| - self.assertGreater(delta, expected * 0.5) |
| 4971 | + self.assertGreater(delta, timeout - CLOCK_RES) |
4972 | 4972 |
|
4973 | 4973 | b.send(None)
|
4974 |
| - |
4975 |
| - start = time.monotonic() |
4976 | 4974 | res = wait([a, b], 20)
|
4977 |
| - delta = time.monotonic() - start |
4978 |
| - |
4979 | 4975 | self.assertEqual(res, [a])
|
4980 |
| - self.assertLess(delta, 0.4) |
4981 | 4976 |
|
4982 | 4977 | @classmethod
|
4983 | 4978 | def signal_and_sleep(cls, sem, period):
|
|
0 commit comments