dsdb: Log the transaction duraton.
[nivanova/samba-autobuild/.git] / python / samba / tests / audit_log_base.py
index fa51911e7650962a0aa3338e99d27f006cfb622c..e91c4142f1cafbe36a9bfdd6e85e83aebd816fce 100644 (file)
@@ -27,6 +27,7 @@ import json
 import os
 import re
 
 import os
 import re
 
+
 def getAudit(message):
     if "type" not in message:
         return None
 def getAudit(message):
     if "type" not in message:
         return None
@@ -35,8 +36,8 @@ def getAudit(message):
     audit = message[type]
     return audit
 
     audit = message[type]
     return audit
 
-class AuditLogTestBase(samba.tests.TestCase):
 
 
+class AuditLogTestBase(samba.tests.TestCase):
 
     def setUp(self):
         super(AuditLogTestBase, self).setUp()
 
     def setUp(self):
         super(AuditLogTestBase, self).setUp()
@@ -51,7 +52,7 @@ class AuditLogTestBase(samba.tests.TestCase):
         def isRemote(message):
             audit = getAudit(message)
             if audit is None:
         def isRemote(message):
             audit = getAudit(message)
             if audit is None:
-                return false
+                return False
 
             remote = audit["remoteAddress"]
             if remote is None:
 
             remote = audit["remoteAddress"]
             if remote is None:
@@ -76,7 +77,7 @@ class AuditLogTestBase(samba.tests.TestCase):
             elif jsonMsg["type"] == "dsdbTransaction":
                 context["txnMessage"] = jsonMsg
 
             elif jsonMsg["type"] == "dsdbTransaction":
                 context["txnMessage"] = jsonMsg
 
-        self.context = {"messages": [], "txnMessage": ""}
+        self.context = {"messages": [], "txnMessage": None}
         self.msg_handler_and_context = (messageHandler, self.context)
         self.msg_ctx.register(self.msg_handler_and_context,
                               msg_type=self.message_type)
         self.msg_handler_and_context = (messageHandler, self.context)
         self.msg_ctx.register(self.msg_handler_and_context,
                               msg_type=self.message_type)
@@ -127,7 +128,6 @@ class AuditLogTestBase(samba.tests.TestCase):
                         return True
             return False
 
                         return True
             return False
 
-
     def waitForMessages(self, number, connection=None, dn=None):
         """Wait for all the expected messages to arrive
         The connection is passed through to keep the connection alive
     def waitForMessages(self, number, connection=None, dn=None):
         """Wait for all the expected messages to arrive
         The connection is passed through to keep the connection alive
@@ -158,8 +158,11 @@ class AuditLogTestBase(samba.tests.TestCase):
     # Discard any previously queued messages.
     def discardMessages(self):
         self.msg_ctx.loop_once(0.001)
     # Discard any previously queued messages.
     def discardMessages(self):
         self.msg_ctx.loop_once(0.001)
-        while len(self.context["messages"]):
+        while (len(self.context["messages"]) or
+               self.context["txnMessage"] is not None):
+
             self.context["messages"] = []
             self.context["messages"] = []
+            self.context["txnMessage"] = None
             self.msg_ctx.loop_once(0.001)
 
     GUID_RE = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
             self.msg_ctx.loop_once(0.001)
 
     GUID_RE = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"