eventletutils: Fix behavior discrepency when reusing Events
The threading.Event object allows calling set() multiple times, but the eventlet.Event object only permits send() to be called once, before a reset() is required to reuse the Event. Calling eventletutils.Event.set() multiple times triggers an AssertionError from eventlet.Event. This change resets the underlying eventlet.Event if the set() method had already been called previously, and ensures the eventletutils.Event behaves the same as the threading.Event. Change-Id: If761b237266bbfe7e65c56e152074b5d1ccac74b
This commit is contained in:
parent
da8d3c3bbc
commit
82678918aa
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user