Skip to content

Commit d00e92b

Browse files
[3.13] gh-130737: Fix multiprocessing test_notify() (GH-130797) (#130802)
gh-130737: Fix multiprocessing test_notify() (GH-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). (cherry picked from commit 8a64a62) Co-authored-by: Victor Stinner <[email protected]>
1 parent 4c6318e commit d00e92b

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

Lib/test/_test_multiprocessing.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,14 +1577,13 @@ def f(cls, cond, sleeping, woken, timeout=None):
15771577
cond.release()
15781578

15791579
def assertReachesEventually(self, func, value):
1580-
for i in range(10):
1580+
for _ in support.sleeping_retry(support.SHORT_TIMEOUT):
15811581
try:
15821582
if func() == value:
15831583
break
15841584
except NotImplementedError:
15851585
break
1586-
time.sleep(DELTA)
1587-
time.sleep(DELTA)
1586+
15881587
self.assertReturnsIfImplemented(value, func)
15891588

15901589
def check_invariant(self, cond):
@@ -1618,26 +1617,23 @@ def test_notify(self):
16181617
sleeping.acquire()
16191618

16201619
# check no process/thread has woken up
1621-
time.sleep(DELTA)
1622-
self.assertReturnsIfImplemented(0, get_value, woken)
1620+
self.assertReachesEventually(lambda: get_value(woken), 0)
16231621

16241622
# wake up one process/thread
16251623
cond.acquire()
16261624
cond.notify()
16271625
cond.release()
16281626

16291627
# check one process/thread has woken up
1630-
time.sleep(DELTA)
1631-
self.assertReturnsIfImplemented(1, get_value, woken)
1628+
self.assertReachesEventually(lambda: get_value(woken), 1)
16321629

16331630
# wake up another
16341631
cond.acquire()
16351632
cond.notify()
16361633
cond.release()
16371634

16381635
# check other has woken up
1639-
time.sleep(DELTA)
1640-
self.assertReturnsIfImplemented(2, get_value, woken)
1636+
self.assertReachesEventually(lambda: get_value(woken), 2)
16411637

16421638
# check state is not mucked up
16431639
self.check_invariant(cond)

0 commit comments

Comments
 (0)