]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
tests/audit_log: Make discardMessages() more reliable
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Thu, 25 May 2023 00:13:28 +0000 (12:13 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 29 May 2023 22:32:28 +0000 (22:32 +0000)
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 <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/audit_log_base.py

index 9e83e95902b32576cc68ed06489866dc352de93b..621e51da3729763e002858b6a0abfe36b2c039d7 100644 (file)
@@ -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}")