From 0e9635fa5110ebdb4d3335af62b075143c92b416 Mon Sep 17 00:00:00 2001 From: Simon Westphahl Date: Fri, 12 Feb 2021 14:24:40 +0100 Subject: [PATCH] Avoid race when task from queue is in progress In case a consumer is currently processing a message, but hasn't called `queue.task_done()` yet, the method `queue.empty()` will already return True. To avoid race conditions we can instead check the `queue.unfinished_tasks` attribute which also includes tasks that are still in progress. Change-Id: I20efab6d8588da328cd06489e78ca54ea9cf85a0 --- tests/base.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/base.py b/tests/base.py index d19eb8e968..e092e92a21 100644 --- a/tests/base.py +++ b/tests/base.py @@ -4901,9 +4901,9 @@ class ZuulTestCase(BaseTestCase): return False return True - def __eventQueuesEmpty(self, matcher) -> Generator[bool, None, None]: + def __eventQueuesEmpty(self, matcher=None) -> Generator[bool, None, None]: for event_queue in self.__event_queues(matcher): - yield event_queue.empty() + yield not event_queue.unfinished_tasks def __eventQueuesJoin(self, matcher) -> None: for app in self.scheds.filter(matcher): @@ -4988,7 +4988,8 @@ class ZuulTestCase(BaseTestCase): all_event_queues_empty): logger("Queue status:") for event_queue in self.__event_queues(matcher): - self.log.debug(" %s: %s", event_queue, event_queue.empty()) + is_empty = not event_queue.unfinished_tasks + self.log.debug(" %s: %s", event_queue, is_empty) logger("All ZK event queues empty: %s", all_zk_queues_empty) logger("All merge jobs waiting: %s", all_merge_jobs_waiting) logger("All builds reported: %s", all_builds_reported)