Skip to content

Commit f8d0683

Browse files
committed
[IMP] runbot: allow to set a memory limit factor
Some tests can fail randomly because they reach memory limit. Setting a slightly lower memory limit during the nightly will help to detect such tests and provide an easier way to fix them early.
1 parent e4ab69d commit f8d0683

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

runbot/models/build.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,9 @@ def _docker_run(self, step, cmd=None, ro_volumes=None, env_variables=None, **kwa
10211021

10221022
containers_memory_limit = self.env['ir.config_parameter'].sudo().get_param('runbot.runbot_containers_memory', 0)
10231023
if containers_memory_limit and 'memory' not in kwargs:
1024-
kwargs['memory'] = int(float(containers_memory_limit) * 1024 ** 3)
1024+
memory_limit_factor = float(self.params_id.config_data.get('memory_limit_factor', 1))
1025+
containers_memory_limit = int(float(containers_memory_limit) * 1024 ** 3) * memory_limit_factor
1026+
kwargs['memory'] = containers_memory_limit
10251027

10261028
self.docker_start = now()
10271029
if self.job_start:

runbot/tests/test_build_config_step.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,22 +1185,15 @@ def test_network_can_be_enable(self, mock_checkout):
11851185
'job_type': 'install_odoo',
11861186
})
11871187

1188-
# by default, network is disabled
1189-
def first_docker_run(cmd, log_path, *args, **kwargs):
1190-
self.assertFalse(kwargs['network_enabled'])
1191-
1192-
self.docker_run_patch = first_docker_run
11931188
config_step._run_step(self.parent_build)()
1194-
1195-
def second_docker_run(cmd, log_path, *args, **kwargs):
1196-
self.assertTrue(kwargs['network_enabled'])
1197-
1198-
self.docker_run_patch = second_docker_run
1189+
self.assertFalse(self.docker_run_calls[0][3]['network_enabled'])
11991190

12001191
parent_build_params = self.parent_build.params_id.copy({'config_data': {'network_enabled': True}})
12011192
parent_build = self.parent_build.copy({'params_id': parent_build_params.id})
12021193
config_step._run_step(parent_build)()
12031194

1195+
self.assertTrue(self.docker_run_calls[1][3]['network_enabled'])
1196+
12041197

12051198
@patch('odoo.addons.runbot.models.build.BuildResult._checkout')
12061199
def test_run_python_networkcan_be_enabled(self, mock_checkout):
@@ -1241,6 +1234,21 @@ def test_install_custom_parametric_tags(self, mock_checkout, parse_config):
12411234
tags = self.get_test_tags(params)
12421235
self.assertEqual(tags, '"-at_install,/web/foo.py:WebSuite.test_unit_desktop[@bar/test with spaces],-/web/bar.py[@snafu/other test with spaces]"')
12431236

1237+
@patch('odoo.addons.runbot.models.build.BuildResult._checkout')
1238+
def test_memory_limit(self, mock_checkout):
1239+
""" test that network can be disabled with config_data """
1240+
config_step = self.ConfigStep.create({
1241+
'name': 'default',
1242+
'job_type': 'install_odoo',
1243+
})
1244+
self.env['ir.config_parameter'].sudo().set_param('runbot.runbot_containers_memory', 10)
1245+
config_step._run_step(self.parent_build)()
1246+
self.assertEqual(self.docker_run_calls[0][3]['memory'], 10 * 1024 ** 3)
1247+
1248+
parent_build_params = self.parent_build.params_id.copy({'config_data': {'memory_limit_factor': 0.9}})
1249+
parent_build = self.parent_build.copy({'params_id': parent_build_params.id})
1250+
config_step._run_step(parent_build)()
1251+
self.assertEqual(self.docker_run_calls[1][3]['memory'], 9 * 1024 ** 3)
12441252
class TestMakeResult(RunbotCase):
12451253

12461254
def setUp(self):

0 commit comments

Comments
 (0)