From ded0348c08f298fda4426eb2a62cc3d50eed25b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Fran=C3=A7ois=20Natali?= Date: Sat, 7 Jan 2012 18:24:56 +0100 Subject: Issue #13502: threading: Fix a race condition in Event.wait() that made it return False when the event was set and cleared right after. --- Lib/test/lock_tests.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Lib/test/lock_tests.py') diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py index 30148e638a..094cc7a459 100644 --- a/Lib/test/lock_tests.py +++ b/Lib/test/lock_tests.py @@ -351,6 +351,22 @@ class EventTests(BaseTestCase): for r, dt in results2: self.assertTrue(r) + def test_set_and_clear(self): + # Issue #13502: check that wait() returns true even when the event is + # cleared before the waiting thread is woken up. + evt = self.eventtype() + results = [] + N = 5 + def f(): + results.append(evt.wait(1)) + b = Bunch(f, N) + b.wait_for_started() + time.sleep(0.5) + evt.set() + evt.clear() + b.wait_for_finished() + self.assertEqual(results, [True] * N) + class ConditionTests(BaseTestCase): """ -- cgit v1.2.1