diff --git a/oslo_utils/eventletutils.py b/oslo_utils/eventletutils.py index 5d3c0a68..2770de14 100644 --- a/oslo_utils/eventletutils.py +++ b/oslo_utils/eventletutils.py @@ -150,16 +150,12 @@ class EventletEvent(object): """ def __init__(self, *args, **kwargs): super(EventletEvent, self).__init__() - self._set = False self.clear() def clear(self): - old_event = getattr(self, "_event", None) - was_set = self._set - self._set = False - self._event = _eventlet.event.Event() - if old_event is not None and not was_set: - old_event.send(True) + if getattr(self, '_set', True): + self._set = False + self._event = _eventlet.event.Event() def is_set(self): return self._set diff --git a/oslo_utils/tests/test_eventletutils.py b/oslo_utils/tests/test_eventletutils.py index b6ce9957..d96851ca 100644 --- a/oslo_utils/tests/test_eventletutils.py +++ b/oslo_utils/tests/test_eventletutils.py @@ -201,6 +201,30 @@ class EventletUtilsTest(test_base.BaseTestCase): with eventlet.timeout.Timeout(0.7): b.wait() + def test_event_set_clear_timeout(self): + event = eventletutils.EventletEvent() + wakes = [] + + def thread_func(): + result = event.wait(0.2) + wakes.append(result) + if len(wakes) == 1: + self.assertTrue(result) + event.clear() + else: + self.assertFalse(result) + + a = greenthread.spawn(thread_func) + b = greenthread.spawn(thread_func) + eventlet.sleep(0) # start threads + event.set() + + with eventlet.timeout.Timeout(0.3): + a.wait() + b.wait() + self.assertFalse(event.is_set()) + self.assertEqual([True, False], wakes) + @mock.patch('oslo_utils.eventletutils._eventlet.event.Event') def test_event_clear_already_sent(self, mock_event): old_event = mock.Mock()