diff options
author | Tim Peters <tim@python.org> | 2013-10-09 02:12:58 (GMT) |
---|---|---|
committer | Tim Peters <tim@python.org> | 2013-10-09 02:12:58 (GMT) |
commit | e99bdb9694dd472fda932926d87cd6d783ec5da8 (patch) | |
tree | ae646be60a30d6a478235350fc1dc1262e3ab9f8 /Lib/test/test_threading.py | |
parent | 77e904e6a6d8fefd8c6100ea33cf46fb69b45efd (diff) | |
parent | 7634e1cf9028ed5b21f0a97db45c91d8e8a159a6 (diff) | |
download | cpython-e99bdb9694dd472fda932926d87cd6d783ec5da8.zip cpython-e99bdb9694dd472fda932926d87cd6d783ec5da8.tar.gz cpython-e99bdb9694dd472fda932926d87cd6d783ec5da8.tar.bz2 |
Issue 19158: a rare race in BoundedSemaphore could allow .release() too often.
Diffstat (limited to 'Lib/test/test_threading.py')
-rw-r--r-- | Lib/test/test_threading.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index 826acbb..4d30ee4 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -599,6 +599,24 @@ class ThreadTests(BaseTestCase): time.sleep(0.01) self.assertIn(LOOKING_FOR, repr(t)) # we waited at least 5 seconds + def test_BoundedSemaphore_limit(self): + # BoundedSemaphore should raise ValueError if released too often. + for limit in range(1, 10): + bs = threading.BoundedSemaphore(limit) + threads = [threading.Thread(target=bs.acquire) + for _ in range(limit)] + for t in threads: + t.start() + for t in threads: + t.join() + threads = [threading.Thread(target=bs.release) + for _ in range(limit)] + for t in threads: + t.start() + for t in threads: + t.join() + self.assertRaises(ValueError, bs.release) + class ThreadJoinOnShutdown(BaseTestCase): def _run_and_join(self, script): |