Make test_multiprocessing more lenient about another timeout check

This commit is contained in:
Richard Oudkerk 2012-05-06 16:46:36 +01:00
parent 41eb85b194
commit 6dbca367dc
1 changed files with 7 additions and 4 deletions

View File

@ -922,7 +922,8 @@ def test_waitfor(self):
self.assertEqual(p.exitcode, 0) self.assertEqual(p.exitcode, 0)
@classmethod @classmethod
def _test_waitfor_timeout_f(cls, cond, state, success): def _test_waitfor_timeout_f(cls, cond, state, success, sem):
sem.release()
with cond: with cond:
expected = 0.1 expected = 0.1
dt = time.time() dt = time.time()
@ -938,11 +939,13 @@ def test_waitfor_timeout(self):
cond = self.Condition() cond = self.Condition()
state = self.Value('i', 0) state = self.Value('i', 0)
success = self.Value('i', False) success = self.Value('i', False)
sem = self.Semaphore(0)
p = self.Process(target=self._test_waitfor_timeout_f, p = self.Process(target=self._test_waitfor_timeout_f,
args=(cond, state, success)) args=(cond, state, success, sem))
p.daemon = True p.daemon = True
p.start() p.start()
self.assertTrue(sem.acquire(timeout=10))
# Only increment 3 times, so state == 4 is never reached. # Only increment 3 times, so state == 4 is never reached.
for i in range(3): for i in range(3):
@ -2723,8 +2726,8 @@ def test_wait_timeout(self):
delta = time.time() - start delta = time.time() - start
self.assertEqual(res, []) self.assertEqual(res, [])
self.assertLess(delta, expected + 1) self.assertLess(delta, expected * 2)
self.assertGreater(delta, expected - 1) self.assertGreater(delta, expected * 0.5)
b.send(None) b.send(None)