8000 [3.11] gh-110666: Fix multiprocessing test_terminate() elapsed (GH-11… · python/cpython@8ca7a23 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8ca7a23

Browse files
[3.11] gh-110666: Fix multiprocessing test_terminate() elapsed (GH-110667) (#110669)
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 
8000
7984dc2 commit 8ca7a23

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
@@ -83,6 +83,11 @@
8383
raise unittest.SkipTest("libasan has a pthread_create() dead lock related to thread+fork")
8484

8585

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

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

16611665
@unittest.skipUnless(HAS_SHAREDCTYPES, 'needs sharedctypes')
@@ -2677,14 +2681,11 @@ def test_make_pool(self):
26772681
p.join()
26782682

26792683
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)
26832687
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()
26882689

26892690
def test_empty_iterable(self):
26902691
# See Issue 12157
@@ -4831,7 +4832,7 @@ class TestWait(unittest.TestCase):
48314832
def _child_test_wait(cls, w, slow):
48324833
for i in range(10):
48334834
if slow:
4834-
time.sleep(random.random()*0.1)
4835+
time.sleep(random.random() * 0.100)
48354836
w.send((i, os.getpid()))
48364837
w.close()
48374838

@@ -4871,7 +4872,7 @@ def _child_test_wait_socket(cls, address, slow):
48714872
s.connect(address)
48724873
for i in range(10):
48734874
if slow:
4874-
time.sleep(random.random()*0.1)
4875+
time.sleep(random.random() * 0.100)
48754876
s.sendall(('%s\n' % i).encode('ascii'))
48764877
s.close()
48774878

@@ -4920,25 +4921,19 @@ def test_wait_socket_slow(self):
49204921
def test_wait_timeout(self):
49214922
from multiprocessing.connection import wait
49224923

4923-
expected = 5
4924+
timeout = 5.0 # seconds
49244925
a, b = multiprocessing.Pipe()
49254926

49264927
start = time.monotonic()
4927-
res = wait([a, b], expected)
4928+
res = wait([a, b], timeout)
49284929
delta = time.monotonic() - start
49294930

49304931
self.assertEqual(res, [])
4931-
self.assertLess(delta, expected * 2)
4932-
self.assertGreater(delta, expected * 0.5)
4932+
self.assertGreater(delta, timeout - CLOCK_RES)
49334933

49344934
b.send(None)
4935-
4936-
start = time.monotonic()
49374935
res = wait([a, b], 20)
4938-
delta = time.monotonic() - start
4939-
49404936
self.assertEqual(res, [a])
4941-
self.assertLess(delta, 0.4)
49424937

49434938
@classmethod
49444939
def signal_and_sleep(cls, sem, period):

0 commit comments

Comments
 (0)
0