summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-06-23 10:52:22 (GMT)
committerGitHub <noreply@github.com>2017-06-23 10:52:22 (GMT)
commite2aec8e691d8acb08373889d9af48a5b1d03b689 (patch)
treee99f495a688b03fd1dbbac5c78f6caff99e59e83 /Lib/test
parent8aa15ba884b14c1cf65d4c1a4c5abc4253f5c9ed (diff)
downloadcpython-e2aec8e691d8acb08373889d9af48a5b1d03b689.zip
cpython-e2aec8e691d8acb08373889d9af48a5b1d03b689.tar.gz
cpython-e2aec8e691d8acb08373889d9af48a5b1d03b689.tar.bz2
[3.5] bpo-30727: Fix a race condition in test_threading. (GH-2334) (#2352)
(cherry picked from commit 32cb968)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/lock_tests.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py
index a64aa18..6c03b5a 100644
--- a/Lib/test/lock_tests.py
+++ b/Lib/test/lock_tests.py
@@ -449,21 +449,28 @@ class ConditionTests(BaseTestCase):
# construct. In particular, it is possible that this can no longer
# be conveniently guaranteed should their implementation ever change.
N = 5
+ ready = []
results1 = []
results2 = []
phase_num = 0
def f():
cond.acquire()
+ ready.append(phase_num)
result = cond.wait()
cond.release()
results1.append((result, phase_num))
cond.acquire()
+ ready.append(phase_num)
result = cond.wait()
cond.release()
results2.append((result, phase_num))
b = Bunch(f, N)
b.wait_for_started()
- _wait()
+ # first wait, to ensure all workers settle into cond.wait() before
+ # we continue. See issues #8799 and #30727.
+ while len(ready) < 5:
+ _wait()
+ ready.clear()
self.assertEqual(results1, [])
# Notify 3 threads at first
cond.acquire()
@@ -475,9 +482,9 @@ class ConditionTests(BaseTestCase):
_wait()
self.assertEqual(results1, [(True, 1)] * 3)
self.assertEqual(results2, [])
- # first wait, to ensure all workers settle into cond.wait() before
- # we continue. See issue #8799
- _wait()
+ # make sure all awaken workers settle into cond.wait()
+ while len(ready) < 3:
+ _wait()
# Notify 5 threads: they might be in their first or second wait
cond.acquire()
cond.notify(5)
@@ -488,7 +495,9 @@ class ConditionTests(BaseTestCase):
_wait()
self.assertEqual(results1, [(True, 1)] * 3 + [(True, 2)] * 2)
self.assertEqual(results2, [(True, 2)] * 3)
- _wait() # make sure all workers settle into cond.wait()
+ # make sure all workers settle into cond.wait()
+ while len(ready) < 5:
+ _wait()
# Notify all threads: they are all in their second wait
cond.acquire()
cond.notify_all()