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:
parent
a6585b5ef1
commit
805381e16d
@ -169,7 +169,7 @@ class _Event(object):
|
|||||||
|
|
||||||
|
|
||||||
def Event():
|
def Event():
|
||||||
if EVENTLET_AVAILABLE:
|
if is_monkey_patched("thread"):
|
||||||
return _Event()
|
return _Event()
|
||||||
else:
|
else:
|
||||||
return threading.Event()
|
return threading.Event()
|
||||||
|
@ -125,10 +125,11 @@ class EventletUtilsTest(test_base.BaseTestCase):
|
|||||||
|
|
||||||
@mock.patch('oslo_utils.eventletutils._Event.clear')
|
@mock.patch('oslo_utils.eventletutils._Event.clear')
|
||||||
def test_event_api_compat(self, mock_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)
|
self.assertIsInstance(e_event, eventletutils._Event)
|
||||||
|
|
||||||
eventletutils.EVENTLET_AVAILABLE = False
|
|
||||||
t_event = eventletutils.Event()
|
t_event = eventletutils.Event()
|
||||||
if six.PY3:
|
if six.PY3:
|
||||||
t_event_cls = threading.Event
|
t_event_cls = threading.Event
|
||||||
|
Loading…
Reference in New Issue
Block a user