Improve eventlet check when selecting Event backend

Verify that eventlet has actually been loaded and has patched the
thread module.  Previously when checking against EVENTLET_AVAILABLE,
it would erroneously use the eventlet Event when eventlet was
installed, but not being used.

Change-Id: Ibb99ac2031a63268ba6e0d61065c2d4eff1e6997
This commit is contained in:
John Eckersberg 2016-11-07 09:41:10 -05:00
parent a6585b5ef1
commit 805381e16d
2 changed files with 4 additions and 3 deletions

View File

@ -169,7 +169,7 @@ class _Event(object):
def Event():
if EVENTLET_AVAILABLE:
if is_monkey_patched("thread"):
return _Event()
else:
return threading.Event()

View File

@ -125,10 +125,11 @@ class EventletUtilsTest(test_base.BaseTestCase):
@mock.patch('oslo_utils.eventletutils._Event.clear')
def test_event_api_compat(self, mock_clear):
e_event = eventletutils.Event()
with mock.patch('oslo_utils.eventletutils.is_monkey_patched',
return_value=True):
e_event = eventletutils.Event()
self.assertIsInstance(e_event, eventletutils._Event)
eventletutils.EVENTLET_AVAILABLE = False
t_event = eventletutils.Event()
if six.PY3:
t_event_cls = threading.Event