From 10cccd1cb7d4ed6c925cdd6880a3f4a6b7a40c29 Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Tue, 2 May 2023 19:06:32 +0000 Subject: [PATCH] [IMP] base: add test for routing_map perfs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This test will help making stats on routing_map generation performances This will help to mesure the time for the main `None` routing map as well as for website1, the idea being that it would be possible to mutualize a part of this computation between routing maps. closes odoo/odoo#120591 X-original-commit: 6646fa7e2ef64e5f060bf38b0d85bf1188d79e4f Signed-off-by: Xavier Dollé (xdo) --- odoo/addons/base/tests/__init__.py | 1 + odoo/addons/base/tests/test_ir_http.py | 30 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 odoo/addons/base/tests/test_ir_http.py diff --git a/odoo/addons/base/tests/__init__.py b/odoo/addons/base/tests/__init__.py index b47f40957e1..49b05903c9b 100644 --- a/odoo/addons/base/tests/__init__.py +++ b/odoo/addons/base/tests/__init__.py @@ -20,6 +20,7 @@ from . import test_ir_actions from . import test_ir_attachment from . import test_ir_cron from . import test_ir_filters +from . import test_ir_http from . import test_ir_mail_server from . import test_ir_model from . import test_ir_sequence diff --git a/odoo/addons/base/tests/test_ir_http.py b/odoo/addons/base/tests/test_ir_http.py new file mode 100644 index 00000000000..692302c2632 --- /dev/null +++ b/odoo/addons/base/tests/test_ir_http.py @@ -0,0 +1,30 @@ +import logging +import re +import time + +from odoo.tests import tagged +from odoo.tests.common import TransactionCase + +_logger = logging.getLogger(__name__) + + +@tagged('-at_install', 'post_install') +class TestIrHttpPerformances(TransactionCase): + + def test_routing_map_performance(self): + self.env['ir.http']._clear_routing_map() + # if the routing map was already generated it is possible that some compiled regex are in cache. + # we want to mesure the cold state, when the worker just spawned, we need to empty the re cache + re._cache.clear() + + self.env['ir.http']._clear_routing_map() + start = time.time() + self.env['ir.http'].routing_map() + duration = time.time() - start + _logger.info('Routing map web generated in %.3fs', duration) + + # generate the routing map of another website, to check if we can benefit from anything computed by the previous routing map + start = time.time() + self.env['ir.http'].routing_map(key=1) + duration = time.time() - start + _logger.info('Routing map website1 generated in %.3fs', duration)