Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 009b15e

Browse files
committed
Give test_multiprocessing better chance of avoiding timeout failures on Windows
1 parent 9bd9d74 commit 009b15e

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

Lib/test/test_multiprocessing.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2699,35 +2699,43 @@ def test_wait_socket_slow(self):
26992699
def test_wait_timeout(self):
27002700
from multiprocessing.connection import wait
27012701

2702-
expected = 1
2702+
expected = 5
27032703
a, b = multiprocessing.Pipe()
27042704

27052705
start = time.time()
2706-
res = wait([a, b], 1)
2706+
res = wait([a, b], expected)
27072707
delta = time.time() - start
27082708

27092709
self.assertEqual(res, [])
2710-
self.assertLess(delta, expected + 0.5)
2711-
self.assertGreater(delta, expected - 0.5)
2710+
self.assertLess(delta, expected + 1)
2711+
self.assertGreater(delta, expected - 1)
27122712

27132713
b.send(None)
27142714

27152715
start = time.time()
2716-
res = wait([a, b], 1)
2716+
res = wait([a, b], 20)
27172717
delta = time.time() - start
27182718

27192719
self.assertEqual(res, [a])
27202720
self.assertLess(delta, 0.4)
27212721

2722+
@classmethod
2723+
def signal_and_sleep(cls, sem, period):
2724+
sem.release()
2725+
time.sleep(period)
2726+
27222727
def test_wait_integer(self):
27232728
from multiprocessing.connection import wait
27242729

2725-
expected = 5
2730+
expected = 3
2731+
sem = multiprocessing.Semaphore(0)
27262732
a, b = multiprocessing.Pipe()
2727-
p = multiprocessing.Process(target=time.sleep, args=(expected,))
2733+
p = multiprocessing.Process(target=self.signal_and_sleep,
2734+
args=(sem, expected))
27282735

27292736
p.start()
27302737
self.assertIsInstance(p.sentinel, int)
2738+
self.assertTrue(sem.acquire(timeout=20))
27312739

27322740
start = time.time()
27332741
res = wait([a, p.sentinel, b], expected + 20)
@@ -2755,6 +2763,7 @@ def test_wait_integer(self):
27552763
self.assertEqual(res, [a, p.sentinel, b])
27562764
self.assertLess(delta, 0.4)
27572765

2766+
p.terminate()
27582767
p.join()
27592768

27602769

0 commit comments

Comments
 (0)