From: Joseph Sutton Date: Thu, 25 May 2023 00:13:28 +0000 (+1200) Subject: tests/audit_log: Make discardMessages() more reliable X-Git-Tag: talloc-2.4.1~546 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1884e8038f9fa663ddf1993a9d1ec96babe2bc9;p=thirdparty%2Fsamba.git tests/audit_log: Make discardMessages() more reliable It can take two or three calls to msg_ctx.loop_once() before a message comes in. Make sure we get all of the messages. Signed-off-by: Joseph Sutton Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/tests/audit_log_base.py b/python/samba/tests/audit_log_base.py index 9e83e95902b..621e51da372 100644 --- a/python/samba/tests/audit_log_base.py +++ b/python/samba/tests/audit_log_base.py @@ -175,13 +175,20 @@ class AuditLogTestBase(samba.tests.TestCase): # Discard any previously queued messages. def discardMessages(self): - self.msg_ctx.loop_once(0.001) - while (self.context["messages"] or - self.context["txnMessage"] is not None): + messages = self.context["messages"] - self.context["messages"] = [] + while True: + messages.clear() self.context["txnMessage"] = None - self.msg_ctx.loop_once(0.001) + + # tevent presumably has other tasks to run, so we might need two or + # three loops before a message comes through. + for _ in range(5): + self.msg_ctx.loop_once(0.001) + + if not messages and self.context["txnMessage"] is None: + # No new messages. We’ve probably got them all. + break GUID_RE = re.compile( "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")