Merge "Fix race in waitUntilSettled" into feature/zuulv3
diff --git a/tests/base.py b/tests/base.py
index 649de26..566ceae 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -1609,10 +1609,15 @@
                 self.eventQueuesJoin()
                 self.sched.run_handler_lock.acquire()
                 if (not self.merge_client.jobs and
-                    all(self.eventQueuesEmpty()) and
                     self.haveAllBuildsReported() and
                     self.areAllBuildsWaiting() and
-                    self.areAllNodeRequestsComplete()):
+                    self.areAllNodeRequestsComplete() and
+                    all(self.eventQueuesEmpty())):
+                    # The queue empty check is placed at the end to
+                    # ensure that if a component adds an event between
+                    # when locked the run handler and checked that the
+                    # components were stable, we don't erroneously
+                    # report that we are settled.
                     self.sched.run_handler_lock.release()
                     self.launch_server.lock.release()
                     self.log.debug("...settled.")