summaryrefslogtreecommitdiff
path: root/addons/web/tests
diff options
context:
space:
mode:
authorLucas Perais (lpe) <lpe@odoo.com>2020-01-07 16:29:12 +0000
committerLucas Perais (lpe) <lpe@odoo.com>2020-01-13 11:00:45 +0000
commit1770e5095c4d1be7e9231f324e6a4bb8c1bc43b0 (patch)
treed8a3711bed6bca42b0994c02b199007b20392e19 /addons/web/tests
parent5f87499554627ad1c6bd1ab0e2c97c41ff0843af (diff)
[FIX] web: static inheritance testing
Before this commit, there were some tests checking how long it took to compute a bunch of templates Those asserted a time limit, which is undeterministic After this commit, those performance tests are not executed as standard anymore Moreover, only asserts on ratios between computations is done and deemed relevant. closes odoo/odoo#43189 X-original-commit: 329fdf3961ea9e6eddbcba7a78d72102d2d08ac1 Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
Diffstat (limited to 'addons/web/tests')
-rw-r--r--addons/web/tests/test_serving_base.py191
1 files changed, 102 insertions, 89 deletions
diff --git a/addons/web/tests/test_serving_base.py b/addons/web/tests/test_serving_base.py
index a3ede96f507..c6ac2083dbb 100644
--- a/addons/web/tests/test_serving_base.py
+++ b/addons/web/tests/test_serving_base.py
@@ -7,11 +7,13 @@ from unittest.mock import patch
import textwrap
from datetime import datetime, timedelta
from lxml import etree
+import logging
from odoo.tests.common import BaseCase, tagged
from odoo.tools import topological_sort
from odoo.addons.web.controllers.main import HomeStaticTemplateHelpers
+_logger = logging.getLogger(__name__)
def sample(population):
return random.sample(
@@ -44,11 +46,10 @@ class TestModulesLoading(BaseCase):
seen.add(module)
-@tagged('static_templates')
-class TestStaticInheritance(BaseCase):
+class TestStaticInheritanceCommon(BaseCase):
def setUp(self):
- super(TestStaticInheritance, self).setUp()
+ super(TestStaticInheritanceCommon, self).setUp()
# output is "manifest_glob" return
self.modules = [
('module_1_file_1', None, 'module_1'),
@@ -94,7 +95,7 @@ class TestStaticInheritance(BaseCase):
self._reg_replace_ws = r"\s|\t"
def tearDown(self):
- super(TestStaticInheritance, self).tearDown()
+ super(TestStaticInheritanceCommon, self).tearDown()
self._toggle_patchers('stop')
# Custom Assert
@@ -130,6 +131,9 @@ class TestStaticInheritance(BaseCase):
for p in self.patchers:
getattr(p, mode)()
+
+@tagged('static_templates')
+class TestStaticInheritance(TestStaticInheritanceCommon):
# Actual test cases
def test_static_inheritance_01(self):
contents = HomeStaticTemplateHelpers.get_qweb_templates(addons=self._get_module_names(), debug=True)
@@ -446,91 +450,6 @@ class TestStaticInheritance(BaseCase):
'No template found to inherit from. Module module_2 and template name template_2_2'
)
- def _sick_script(self, nMod, nFilePerMod, nTemplatePerFile, stepInheritInModule=2, stepInheritPreviousModule=3):
- """
- Make a sick amount of templates to test perf
- nMod modules
- each module: has nFilesPerModule files, each of which contains nTemplatePerFile templates
- """
- self.modules = []
- self.template_files = {}
- number_templates = 0
- for m in range(nMod):
- for f in range(nFilePerMod):
- mname = 'mod_%s' % m
- fname = 'mod_%s_file_%s' % (m, f)
- self.modules.append((fname, None, mname))
-
- _file = '<templates id="template" xml:space="preserve">'
-
- for t in range(nTemplatePerFile):
- _template = ''
- if t % stepInheritInModule or t % stepInheritPreviousModule or t == 0:
- _template += """
- <div t-name="template_%(t_number)s_mod_%(m_number)s">
- <div>Parent</div>
- </div>
- """
-
- elif not t % stepInheritInModule and t >= 1:
- _template += """
- <div t-name="template_%(t_number)s_mod_%(m_number)s"
- t-inherit="template_%(t_inherit)s_mod_%(m_number)s"
- t-inherit-mode="primary">
- <xpath expr="/div/div[1]" position="before">
- <div>Sick XPath</div>
- </xpath>
- </div>
- """
-
- elif not t % stepInheritPreviousModule and m >= 1:
- _template += """
- <div t-name="template_%(t_number)s_mod_%(m_number)s"
- t-inherit="mod_%(m_module_inherit)s.template_%(t_module_inherit)s_mod_%(m_module_inherit)s"
- t-inherit-mode="primary">
- <xpath expr="/div/div[1]" position="inside">
- <div>Mental XPath</div>
- </xpath>
- </div>
- """
- if _template:
- number_templates += 1
-
- _template_number = 1000 * f + t
- _file += _template % {
- 't_number': _template_number,
- 'm_number': m,
- 't_inherit': _template_number - 1,
- 't_module_inherit': _template_number,
- 'm_module_inherit': m - 1,
- }
- _file += '</templates>'
-
- self.template_files[fname] = _file.encode()
- self.assertEqual(number_templates, nMod * nFilePerMod * nTemplatePerFile)
-
- def test_performance_2500(self):
- nMod, nFilePerMod, nTemplatePerFile = 50, 5, 10
- self._sick_script(nMod, nFilePerMod, nTemplatePerFile)
-
- before = datetime.now()
- contents = HomeStaticTemplateHelpers.get_qweb_templates(addons=self._get_module_names(), debug=True)
- after = datetime.now()
- self.assertLessEqual(after - before, timedelta(milliseconds=130))
-
- whole_tree = etree.fromstring(contents)
- self.assertEqual(len(whole_tree), nMod * nFilePerMod * nTemplatePerFile)
-
- def test_performance_25000(self):
- nMod, nFilePerMod, nTemplatePerFile = 50, 5, 100
- self._sick_script(nMod, nFilePerMod, nTemplatePerFile)
-
- before = datetime.now()
- HomeStaticTemplateHelpers.get_qweb_templates(addons=self._get_module_names(), debug=True)
- after = datetime.now()
-
- self.assertLessEqual(after - before, timedelta(milliseconds=1000))
-
def test_replace_in_debug_mode(self):
"""
Replacing a template's meta definition in place doesn't keep the original attrs of the template
@@ -796,3 +715,97 @@ class TestStaticInheritance(BaseCase):
"""
self.assertXMLEqual(contents, expected)
+
+
+@tagged('-standard', 'static_templates_performance')
+class TestStaticInheritancePerformance(TestStaticInheritanceCommon):
+ def _sick_script(self, nMod, nFilePerMod, nTemplatePerFile, stepInheritInModule=2, stepInheritPreviousModule=3):
+ """
+ Make a sick amount of templates to test perf
+ nMod modules
+ each module: has nFilesPerModule files, each of which contains nTemplatePerFile templates
+ """
+ self.modules = []
+ self.template_files = {}
+ number_templates = 0
+ for m in range(nMod):
+ for f in range(nFilePerMod):
+ mname = 'mod_%s' % m
+ fname = 'mod_%s_file_%s' % (m, f)
+ self.modules.append((fname, None, mname))
+
+ _file = '<templates id="template" xml:space="preserve">'
+
+ for t in range(nTemplatePerFile):
+ _template = ''
+ if t % stepInheritInModule or t % stepInheritPreviousModule or t == 0:
+ _template += """
+ <div t-name="template_%(t_number)s_mod_%(m_number)s">
+ <div>Parent</div>
+ </div>
+ """
+
+ elif not t % stepInheritInModule and t >= 1:
+ _template += """
+ <div t-name="template_%(t_number)s_mod_%(m_number)s"
+ t-inherit="template_%(t_inherit)s_mod_%(m_number)s"
+ t-inherit-mode="primary">
+ <xpath expr="/div/div[1]" position="before">
+ <div>Sick XPath</div>
+ </xpath>
+ </div>
+ """
+
+ elif not t % stepInheritPreviousModule and m >= 1:
+ _template += """
+ <div t-name="template_%(t_number)s_mod_%(m_number)s"
+ t-inherit="mod_%(m_module_inherit)s.template_%(t_module_inherit)s_mod_%(m_module_inherit)s"
+ t-inherit-mode="primary">
+ <xpath expr="/div/div[1]" position="inside">
+ <div>Mental XPath</div>
+ </xpath>
+ </div>
+ """
+ if _template:
+ number_templates += 1
+
+ _template_number = 1000 * f + t
+ _file += _template % {
+ 't_number': _template_number,
+ 'm_number': m,
+ 't_inherit': _template_number - 1,
+ 't_module_inherit': _template_number,
+ 'm_module_inherit': m - 1,
+ }
+ _file += '</templates>'
+
+ self.template_files[fname] = _file.encode()
+ self.assertEqual(number_templates, nMod * nFilePerMod * nTemplatePerFile)
+
+ def test_static_templates_treatment_linearity(self):
+ # With 2500 templates for starters
+ nMod, nFilePerMod, nTemplatePerFile = 50, 5, 10
+ self._sick_script(nMod, nFilePerMod, nTemplatePerFile)
+
+ before = datetime.now()
+ contents = HomeStaticTemplateHelpers.get_qweb_templates(addons=self._get_module_names(), debug=True)
+ after = datetime.now()
+ delta2500 = after - before
+ _logger.log(25, 'Static Templates Inheritance: 2500 templates treated in %s seconds' % delta2500.total_seconds())
+
+ whole_tree = etree.fromstring(contents)
+ self.assertEqual(len(whole_tree), nMod * nFilePerMod * nTemplatePerFile)
+
+ # With 25000 templates next
+ nMod, nFilePerMod, nTemplatePerFile = 50, 5, 100
+ self._sick_script(nMod, nFilePerMod, nTemplatePerFile)
+
+ before = datetime.now()
+ HomeStaticTemplateHelpers.get_qweb_templates(addons=self._get_module_names(), debug=True)
+ after = datetime.now()
+ delta25000 = after - before
+
+ time_ratio = delta25000.total_seconds() / delta2500.total_seconds()
+ _logger.log(25, 'Static Templates Inheritance: 25000 templates treated in %s seconds' % delta25000.total_seconds())
+ _logger.log(25, 'Static Templates Inheritance: Computed linearity ratio: %s' % time_ratio)
+ self.assertLessEqual(time_ratio, 10)