From a6da2a98c367de2c1c023acf914c3f4ad5a41783 Mon Sep 17 00:00:00 2001 From: Matthew Booth Date: Fri, 16 Oct 2015 16:16:23 +0100 Subject: [PATCH] Trivial locking cleanup in test_listener ListenerSetupMixin.ThreadTracker was reading self._received_msgs unlocked and sleep/looping until the desired value was reached. Replaced this pattern with a threading.Condition. Change-Id: Id4731caee2104bdb231e78e7b460905a0aaf84bf --- oslo_messaging/tests/notify/test_listener.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/oslo_messaging/tests/notify/test_listener.py b/oslo_messaging/tests/notify/test_listener.py index 1644936ad..fb4a5e011 100644 --- a/oslo_messaging/tests/notify/test_listener.py +++ b/oslo_messaging/tests/notify/test_listener.py @@ -53,16 +53,18 @@ class ListenerSetupMixin(object): def __init__(self): self._received_msgs = 0 self.threads = [] - self.lock = threading.Lock() + self.lock = threading.Condition() def info(self, ctxt, publisher_id, event_type, payload, metadata): # NOTE(sileht): this run into an other thread with self.lock: self._received_msgs += 1 + self.lock.notify_all() def wait_for_messages(self, expect_messages): - while self._received_msgs < expect_messages: - time.sleep(0.01) + with self.lock: + while self._received_msgs < expect_messages: + self.lock.wait() def stop(self): for thread in self.threads: