mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-130737: Fix multiprocessing test_notify() (#130797)
Replace hardcoded delay (100 ms) with a loop awaiting until a condition is true: replace assertReturnsIfImplemented() with assertReachesEventually(). Use sleeping_retry() in assertReachesEventually() to tolerate slow buildbots and raise an exception on timeout (30 seconds).
This commit is contained in:
parent
d0eb01c9de
commit
8a64a62002
1 changed files with 5 additions and 9 deletions
|
@ -1622,14 +1622,13 @@ class _TestCondition(BaseTestCase):
|
|||
cond.release()
|
||||
|
||||
def assertReachesEventually(self, func, value):
|
||||
for i in range(10):
|
||||
for _ in support.sleeping_retry(support.SHORT_TIMEOUT):
|
||||
try:
|
||||
if func() == value:
|
||||
break
|
||||
except NotImplementedError:
|
||||
break
|
||||
time.sleep(DELTA)
|
||||
time.sleep(DELTA)
|
||||
|
||||
self.assertReturnsIfImplemented(value, func)
|
||||
|
||||
def check_invariant(self, cond):
|
||||
|
@ -1663,8 +1662,7 @@ class _TestCondition(BaseTestCase):
|
|||
sleeping.acquire()
|
||||
|
||||
# check no process/thread has woken up
|
||||
time.sleep(DELTA)
|
||||
self.assertReturnsIfImplemented(0, get_value, woken)
|
||||
self.assertReachesEventually(lambda: get_value(woken), 0)
|
||||
|
||||
# wake up one process/thread
|
||||
cond.acquire()
|
||||
|
@ -1672,8 +1670,7 @@ class _TestCondition(BaseTestCase):
|
|||
cond.release()
|
||||
|
||||
# check one process/thread has woken up
|
||||
time.sleep(DELTA)
|
||||
self.assertReturnsIfImplemented(1, get_value, woken)
|
||||
self.assertReachesEventually(lambda: get_value(woken), 1)
|
||||
|
||||
# wake up another
|
||||
cond.acquire()
|
||||
|
@ -1681,8 +1678,7 @@ class _TestCondition(BaseTestCase):
|
|||
cond.release()
|
||||
|
||||
# check other has woken up
|
||||
time.sleep(DELTA)
|
||||
self.assertReturnsIfImplemented(2, get_value, woken)
|
||||
self.assertReachesEventually(lambda: get_value(woken), 2)
|
||||
|
||||
# check state is not mucked up
|
||||
self.check_invariant(cond)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue