10000 [3.12] gh-110666: Fix multiprocessing test_terminate() elapsed (GH-11… · python/cpython@18458a5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 18458a5

Browse files
[3.12] gh-110666: Fix multiprocessing test_terminate() elapsed (GH-110667) (#110668)
gh-110666: Fix multiprocessing test_terminate() elapsed (GH-110667) multiprocessing test_terminate() and test_wait_socket_slow() no longer test the CI performance: no longer check maximum elapsed time. Add CLOCK_RES constant: tolerate a difference of 100 ms. (cherry picked from commit 1556f42) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 55448a5 commit 18458a5

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

Lib/test/_test_multiprocessing.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@
8484
raise unittest.SkipTest("libasan has a pthread_create() dead lock related to thread+fork")
8585

8686

87+
# gh-110666: Tolerate a difference of 100 ms when comparing timings
88+
# (clock resolution)
89+
CLOCK_RES = 0.100
90+
91+
8792
def latin(s):
8893
return s.encode('latin')
8994

@@ -1655,8 +1660,7 @@ def _test_waitfor_timeout_f(cls, cond, state, success, sem):
16551660
dt = time.monotonic()
16561661
result = cond.wait_for(lambda : state.value==4, timeout=expected)
16571662
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:
16601664
success.value = True
16611665

16621666
@unittest.skipUnless(HAS_SHAREDCTYPES, 'needs sharedctypes')
@@ -2678,14 +2682,11 @@ def test_make_pool(self):
26782682
p.join()
26792683

26802684
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)
26842688
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()
26892690

26902691
def test_empty_iterable(self):
26912692
# See Issue 12157
@@ -4870,7 +4871,7 @@ class TestWait(unittest.TestCase):
48704871
def _child_test_wait(cls, w, slow):
48714872
for i in range(10):
48724873
if slow:
4873-
time.sleep(random.random()*0.1)
4874+
time.sleep(random.random() * 0.100)
48744875
w.send((i, os.getpid()))
48754876
w.close()
48764877

@@ -4910,7 +4911,7 @@ def _child_test_wait_socket(cls, address, slow):
49104911
s.connect(address)
49114912
for i in range(10):
49124913
if slow:
4913-
time.sleep(random.random()*0.1)
4914+
time.sleep(random.random() * 0.100)
49144915
s.sendall(('%s\n' % i).encode('ascii'))
49154916
s.close()
49164917

@@ -4959,25 +4960,19 @@ def test_wait_socket_slow(self):
49594960
def test_wait_timeout(self):
49604961
from multiprocessing.connection import wait
49614962

4962-
expected = 5
4963+
timeout = 5.0 # seconds
49634964
a, b = multiprocessing.Pipe()
49644965

49654966
start = time.monotonic()
4966-
res = wait([a, b], expected)
4967+
res = wait([a, b], timeout)
49674968
delta = time.monotonic() - start
49684969

49694970
self.assertEqual(res, [])
4970-
self.assertLess(delta, expected * 2)
4971-
self.assertGreater(delta, expected * 0.5)
4971+
self.assertGreater(delta, timeout - CLOCK_RES)
49724972

49734973
b.send(None)
4974-
4975-
start = time.monotonic()
49764974
res = wait([a, b], 20)
4977-
delta = time.monotonic() - start
4978-
49794975
self.assertEqual(res, [a])
4980-
self.assertLess(delta, 0.4)
49814976

49824977
@classmethod
49834978
def signal_and_sleep(cls, sem, period):

0 commit comments

Comments
 (0)
0