Merge "eventletutils: Fix behavior discrepency when reusing Events"

This commit is contained in:
Zuul 2018-04-17 23:08:56 +00:00 committed by Gerrit Code Review
commit f0d4b6d431
2 changed files with 13 additions and 2 deletions

View File

@ -159,6 +159,9 @@ class _Event(object):
isSet = is_set
def set(self):
if self._set:
self._event.reset()
self._set = True
self._event.send(True)

View File

@ -123,8 +123,8 @@ class EventletUtilsTest(test_base.BaseTestCase):
eventletutils.warn_eventlet_not_patched,
['blah.blah'])
@mock.patch('oslo_utils.eventletutils._Event.clear')
def test_event_api_compat(self, mock_clear):
@mock.patch('oslo_utils.eventletutils._eventlet')
def test_event_api_compat(self, mock_eventlet):
with mock.patch('oslo_utils.eventletutils.is_monkey_patched',
return_value=True):
e_event = eventletutils.Event()
@ -142,3 +142,11 @@ class EventletUtilsTest(test_base.BaseTestCase):
for method in public_methods:
self.assertTrue(hasattr(e_event, method))
# Ensure set() allows multiple invocations, same as in
# threading implementation. Must call reset on underlying
# Event before reusing it
e_event.set()
self.assertEqual(0, mock_eventlet.event.Event().reset.call_count)
e_event.set()
self.assertEqual(1, mock_eventlet.event.Event().reset.call_count)