From 805381e16da79b9eb704433c18471464468116f4 Mon Sep 17 00:00:00 2001 From: John Eckersberg Date: Mon, 7 Nov 2016 09:41:10 -0500 Subject: [PATCH] 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 --- oslo_utils/eventletutils.py | 2 +- oslo_utils/tests/test_eventletutils.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/oslo_utils/eventletutils.py b/oslo_utils/eventletutils.py index b27bb1d3..5e4b4aa0 100644 --- a/oslo_utils/eventletutils.py +++ b/oslo_utils/eventletutils.py @@ -169,7 +169,7 @@ class _Event(object): def Event(): - if EVENTLET_AVAILABLE: + if is_monkey_patched("thread"): return _Event() else: return threading.Event() diff --git a/oslo_utils/tests/test_eventletutils.py b/oslo_utils/tests/test_eventletutils.py index 811cd89c..e5765c72 100644 --- a/oslo_utils/tests/test_eventletutils.py +++ b/oslo_utils/tests/test_eventletutils.py @@ -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