From 3bb498d696744c36b198c4da7cf428d643699aff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 9 Apr 2018 15:33:51 +0200 Subject: [PATCH] [REVERT] "[IMP] core: tolerate a 10% deviation for number of queries" This reverts commit d565596868a55b5e593d2907b0cfba66c5daefac. Indeed whole purpose of having tests based on query counters is to fail every time query count is greater than expected. Query count could be greater than expected because * either it is required by a bug fix or a feature and tests should be updated accordingly in the same commit; * either implementation can be improved to avoid or lessen query count impact and code should be updated accordingly; * either we have some random queries due to nondeterministic behavior; It seems purpose of the commit was to solve the third case. However we think hiding first two cases can be dangerous compared to solving third case. Moreover having a threshold of 10% does not make sense. It means some complex test case could take 30 queries more without being noticed. Some tests could fail after several commits adding queries and finding them afterwards could be complicated. Another solution based on flagging some tests that have a small random behavior will come soon. --- odoo/tests/common.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/odoo/tests/common.py b/odoo/tests/common.py index af52f615f34..79b1d75f625 100644 --- a/odoo/tests/common.py +++ b/odoo/tests/common.py @@ -207,16 +207,15 @@ class BaseCase(TreeCase, MetaCase('DummyCase', (object,), {})): if self.warm: login = self.env.user.login expected = counters.get(login, default) - tolerance = expected + round(expected * 0.1) # allow a 10% tolerance count0 = self.cr.sql_log_count yield count = self.cr.sql_log_count - count0 - if count > tolerance: - msg = "Too much queries for user %s: %d > %d queries" + if not count <= expected: + msg = "Query count for user %s: got %d instead of %d" self.fail(msg % (login, count, expected)) elif count < expected: logger = logging.getLogger(type(self).__module__) - msg = "Nice job, %s! Got %d queries instead of %d" + msg = "Query count for user %s: got %d instead of %d" logger.info(msg, login, count, expected) else: yield