|
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
|
@@ -4908,7 +4909,7 @@ class TestWait(unittest.TestCase):
|
4908 | 4909 | def _child_test_wait(cls, w, slow):
|
4909 | 4910 | for i in range(10):
|
4910 | 4911 | if slow:
|
4911 |
| - time.sleep(random.random()*0.1) |
| 4912 | + time.sleep(random.random() * 0.100) |
4912 | 4913 | w.send((i, os.getpid()))
|
4913 | 4914 | w.close()
|
4914 | 4915 |
|
@@ -4948,7 +4949,7 @@ def _child_test_wait_socket(cls, address, slow):
|
4948 | 4949 | s.connect(address)
|
4949 | 4950 | for i in range(10):
|
4950 | 4951 | if slow:
|
4951 |
| - time.sleep(random.random()*0.1) |
| 4952 | + time.sleep(random.random() * 0.100) |
4952 | 4953 | s.sendall(('%s\n' % i).encode('ascii'))
|
4953 | 4954 | s.close()
|
4954 | 4955 |
|
@@ -4997,25 +4998,19 @@ def test_wait_socket_slow(self):
|
4997 | 4998 | def test_wait_timeout(self):
|
4998 | 4999 | from multiprocessing.connection import wait
|
4999 | 5000 |
|
5000 |
| - expected = 5 |
| 5001 | + timeout = 5.0 # seconds |
5001 | 5002 | a, b = multiprocessing.Pipe()
|
5002 | 5003 |
|
5003 | 5004 | start = time.monotonic()
|
5004 |
| - res = wait([a, b], expected) |
| 5005 | + res = wait([a, b], timeout) |
5005 | 5006 | delta = time.monotonic() - start
|
5006 | 5007 |
|
5007 | 5008 | self.assertEqual(res, [])
|
5008 |
| - self.assertLess(delta, expected * 2) |
5009 |
| - self.assertGreater(delta, expected * 0.5) |
| 5009 | + self.assertGreater(delta, timeout - CLOCK_RES) |
5010 | 5010 |
|
5011 | 5011 | b.send(None)
|
5012 |
| - |
5013 |
| - start = time.monotonic() |
5014 | 5012 | res = wait([a, b], 20)
|
5015 |
| - delta = time.monotonic() - start |
5016 |
| - |
5017 | 5013 | self.assertEqual(res, [a])
|
5018 |
| - self.assertLess(delta, 0.4) |
5019 | 5014 |
|
5020 | 5015 | @classmethod
|
5021 | 5016 | def signal_and_sleep(cls, sem, period):
|
|
0 commit comments