changeset cbe0b8e94565 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=cbe0b8e94565
description:
        Do not keeping lock when relaunch listener and join listener in test

        We can not recursively call Bus._listen when holding the lock because it
        blocks all subscription until the listener stops.
        The tearDown of the test should ensure the listener is really stopped 
before
        ending.

        issue8039
        review52611002
diffstat:

 trytond/bus.py            |  6 +++++-
 trytond/tests/test_bus.py |  7 ++++---
 2 files changed, 9 insertions(+), 4 deletions(-)

diffs (40 lines):

diff -r ea37edb11459 -r cbe0b8e94565 trytond/bus.py
--- a/trytond/bus.py    Wed Jan 30 10:02:36 2019 +0100
+++ b/trytond/bus.py    Wed Jan 30 10:04:11 2019 +0100
@@ -95,6 +95,7 @@
             if start_listener:
                 listener = threading.Thread(
                     target=cls._listen, args=(database,), daemon=True)
+                cls._queues[database]['listener'] = listener
                 listener.start()
 
         messages = cls._messages.get(database)
@@ -191,7 +192,10 @@
                 del cls._queues[database]
             else:
                 # A query arrived between the end of the while and here
-                cls._listen(database)
+                listener = threading.Thread(
+                    target=cls._listen, args=(database,), daemon=True)
+                cls._queues[database]['listener'] = listener
+                listener.start()
 
     @classmethod
     def publish(cls, channel, message):
diff -r ea37edb11459 -r cbe0b8e94565 trytond/tests/test_bus.py
--- a/trytond/tests/test_bus.py Wed Jan 30 10:02:36 2019 +0100
+++ b/trytond/tests/test_bus.py Wed Jan 30 10:04:11 2019 +0100
@@ -96,9 +96,10 @@
 
     def tearDown(self):
         if DB_NAME in Bus._queues:
-            Bus._queues[DB_NAME]['timeout'] = 0
-            # Wait to let the listen thread stops
-            time.sleep(bus._select_timeout)
+            with Bus._queues_lock:
+                Bus._queues[DB_NAME]['timeout'] = 0
+                listener = Bus._queues[DB_NAME]['listener']
+            listener.join()
         Bus._messages.clear()
 
     @with_transaction()

Reply via email to