|
83 | 83 | raise unittest.SkipTest("libasan has a pthread_create() dead lock related to thread+fork")
|
84 | 84 |
|
85 | 85 |
|
| 86 | +# gh-110666: Tolerate a difference of 100 ms when comparing timings |
| 87 | +# (clock resolution) |
| 88 | +CLOCK_RES = 0.100 |
| 89 | + |
| 90 | + |
86 | 91 | def latin(s):
|
87 | 92 | return s.encode('latin')
|
88 | 93 |
|
@@ -1654,8 +1659,7 @@ def _test_waitfor_timeout_f(cls, cond, state, success, sem):
|
1654 | 1659 | dt = time.monotonic()
|
1655 | 1660 | result = cond.wait_for(lambda : state.value==4, timeout=expected)
|
1656 | 1661 | dt = time.monotonic() - dt
|
1657 |
| - # borrow logic in assertTimeout() from test/lock_tests.py |
1658 |
| - if not result and expected * 0.6 <= dt: |
| 1662 | + if not result and (expected - CLOCK_RES) <= dt: |
1659 | 1663 | success.value = True
|
1660 | 1664 |
|
1661 | 1665 | @unittest.skipUnless(HAS_SHAREDCTYPES, 'needs sharedctypes')
|
@@ -2677,14 +2681,11 @@ def test_make_pool(self):
|
2677 | 2681 | p.join()
|
2678 | 2682 |
|
2679 | 2683 | def test_terminate(self):
|
2680 |
| - result = self.pool.map_async( |
2681 |
| - time.sleep, [0.1 for i in range(10000)], chunksize=1 |
2682 |
| - ) |
| 2684 | + # Simulate slow tasks which take "forever" to complete |
| 2685 | + args = [support.LONG_TIMEOUT for i in range(10_000)] |
| 2686 | + result = self.pool.map_async(time.sleep, args, chunksize=1) |
2683 | 2687 | self.pool.terminate()
|
2684 |
| - join = TimingWrapper(self.pool.join) |
2685 |
| - join() |
2686 |
| - # Sanity check the pool didn't wait for all tasks to finish |
2687 |
| - self.assertLess(join.elapsed, 2.0) |
| 2688 | + self.pool.join() |
2688 | 2689 |
|
2689 | 2690 | def test_empty_iterable(self):
|
2690 | 2691 | # See Issue 12157
|
@@ -4831,7 +4832,7 @@ class TestWait(unittest.TestCase):
|
4831 | 4832 | def _child_test_wait(cls, w, slow):
|
4832 | 4833 | for i in range(10):
|
4833 | 4834 | if slow:
|
4834 |
| - time.sleep(random.random()*0.1) |
| 4835 | + time.sleep(random.random() * 0.100) |
4835 | 4836 | w.send((i, os.getpid()))
|
4836 | 4837 | w.close()
|
4837 | 4838 |
|
@@ -4871,7 +4872,7 @@ def _child_test_wait_socket(cls, address, slow):
|
4871 | 4872 | s.connect(address)
|
4872 | 4873 | for i in range(10):
|
4873 | 4874 | if slow:
|
4874 |
| - time.sleep(random.random()*0.1) |
| 4875 | + time.sleep(random.random() * 0.100) |
4875 | 4876 | s.sendall(('%s\n' % i).encode('ascii'))
|
4876 | 4877 | s.close()
|
4877 | 4878 |
|
@@ -4920,25 +4921,19 @@ def test_wait_socket_slow(self):
|
4920 | 4921 | def test_wait_timeout(self):
|
4921 | 4922 | from multiprocessing.connection import wait
|
4922 | 4923 |
|
4923 |
| - expected = 5 |
| 4924 | + timeout = 5.0 # seconds |
4924 | 4925 | a, b = multiprocessing.Pipe()
|
4925 | 4926 |
|
4926 | 4927 | start = time.monotonic()
|
4927 |
| - res = wait([a, b], expected) |
| 4928 | + res = wait([a, b], timeout) |
4928 | 4929 | delta = time.monotonic() - start
|
4929 | 4930 |
|
4930 | 4931 | self.assertEqual(res, [])
|
4931 |
| - self.assertLess(delta, expected * 2) |
4932 |
| - self.assertGreater(delta, expected * 0.5) |
| 4932 | + self.assertGreater(delta, timeout - CLOCK_RES) |
4933 | 4933 |
|
4934 | 4934 | b.send(None)
|
4935 |
| - |
4936 |
| - start = time.monotonic() |
4937 | 4935 | res = wait([a, b], 20)
|
4938 |
| - delta = time.monotonic() - start |
4939 |
| - |
4940 | 4936 | self.assertEqual(res, [a])
|
4941 |
| - self.assertLess(delta, 0.4) |
4942 | 4937 |
|
4943 | 4938 | @classmethod
|
4944 | 4939 | def signal_and_sleep(cls, sem, period):
|
|
0 commit comments