[IMP] tests: allow to add a margin on performance tests
Purpose of this commit is to avoid errors for some performance tests that have a slightly variable number of queries. Indeed some tests in test_mail module vary of 1 or 2 queries due to a behavior still not found that does not seem deterministic. This should not be considered as a real error, but should not be considered as completely valid. This is why a margin is accepted in some tests that will raise a warning instead of an error. This warning tells people to check if they have increased the query counter or if it is due to a random effect in query count.
This commit is contained in:
+10
-6
@@ -192,7 +192,7 @@ class BaseCase(TreeCase, MetaCase('DummyCase', (object,), {})):
|
||||
return self._assertRaises(exception)
|
||||
|
||||
@contextmanager
|
||||
def assertQueryCount(self, default=0, **counters):
|
||||
def assertQueryCount(self, default=0, margin=0, **counters):
|
||||
""" Context manager that counts queries. It may be invoked either with
|
||||
one value, or with a set of named arguments like ``login=value``::
|
||||
|
||||
@@ -210,13 +210,17 @@ class BaseCase(TreeCase, MetaCase('DummyCase', (object,), {})):
|
||||
count0 = self.cr.sql_log_count
|
||||
yield
|
||||
count = self.cr.sql_log_count - count0
|
||||
if not count <= expected:
|
||||
msg = "Query count for user %s: got %d instead of %d"
|
||||
self.fail(msg % (login, count, expected))
|
||||
if count > (expected + margin):
|
||||
msg = "Too much query count: user %s: got %d instead of %d (margin %s)"
|
||||
self.fail(msg % (login, count, expected, margin))
|
||||
elif count > expected and count <= (expected + margin):
|
||||
logger = logging.getLogger(type(self).__module__)
|
||||
msg = "Query count greater but still in margin : user %s: got %d instead of %d (margin %s)"
|
||||
logger.warn(msg, login, count, expected, margin)
|
||||
elif count < expected:
|
||||
logger = logging.getLogger(type(self).__module__)
|
||||
msg = "Query count for user %s: got %d instead of %d"
|
||||
logger.info(msg, login, count, expected)
|
||||
msg = "Better query count: user %s: got %d instead of %d (margin %s)"
|
||||
logger.info(msg, login, count, expected, margin)
|
||||
else:
|
||||
yield
|
||||
|
||||
|
||||
Reference in New Issue
Block a user