From 009b15e2c3e3e1f85cf7992893eefb8bc33e5a34 Mon Sep 17 00:00:00 2001 From: Richard Oudkerk Date: Fri, 4 May 2012 09:44:39 +0100 Subject: Give test_multiprocessing better chance of avoiding timeout failures on Windows --- Lib/test/test_multiprocessing.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py index 4a74e87..4aa0ba8 100644 --- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -2699,35 +2699,43 @@ class TestWait(unittest.TestCase): def test_wait_timeout(self): from multiprocessing.connection import wait - expected = 1 + expected = 5 a, b = multiprocessing.Pipe() start = time.time() - res = wait([a, b], 1) + res = wait([a, b], expected) delta = time.time() - start self.assertEqual(res, []) - self.assertLess(delta, expected + 0.5) - self.assertGreater(delta, expected - 0.5) + self.assertLess(delta, expected + 1) + self.assertGreater(delta, expected - 1) b.send(None) start = time.time() - res = wait([a, b], 1) + res = wait([a, b], 20) delta = time.time() - start self.assertEqual(res, [a]) self.assertLess(delta, 0.4) + @classmethod + def signal_and_sleep(cls, sem, period): + sem.release() + time.sleep(period) + def test_wait_integer(self): from multiprocessing.connection import wait - expected = 5 + expected = 3 + sem = multiprocessing.Semaphore(0) a, b = multiprocessing.Pipe() - p = multiprocessing.Process(target=time.sleep, args=(expected,)) + p = multiprocessing.Process(target=self.signal_and_sleep, + args=(sem, expected)) p.start() self.assertIsInstance(p.sentinel, int) + self.assertTrue(sem.acquire(timeout=20)) start = time.time() res = wait([a, p.sentinel, b], expected + 20) @@ -2755,6 +2763,7 @@ class TestWait(unittest.TestCase): self.assertEqual(res, [a, p.sentinel, b]) self.assertLess(delta, 0.4) + p.terminate() p.join() -- cgit v0.12