Subject: changeset in trytond:5.0 Do not keeping lock when relaunch listener and join listener in test From: Cédric Krier <[email protected]>
changeset d9f490511ba7 in trytond:5.0 details: https://hg.tryton.org/trytond?cmd=changeset;node=d9f490511ba7 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 (grafted from cbe0b8e94565b8483a94239d5f2a134255f8ea87) diffstat: trytond/bus.py | 6 +++++- trytond/tests/test_bus.py | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diffs (40 lines): diff -r c209d11bc94e -r d9f490511ba7 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 @@ -87,6 +87,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) @@ -183,7 +184,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 c209d11bc94e -r d9f490511ba7 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()
