|
2 | 2 | # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html) |
3 | 3 | import doctest |
4 | 4 | import os |
| 5 | +from unittest import mock |
5 | 6 |
|
6 | 7 | from odoo.tests import BaseCase, tagged |
7 | 8 |
|
@@ -61,3 +62,53 @@ def test_runner_file_closed_write_descriptor(self): |
61 | 62 |
|
62 | 63 | self.assertFalse(self._is_open_file_descriptor(read_fd)) |
63 | 64 | self.assertFalse(self._is_open_file_descriptor(write_fd)) |
| 65 | + |
| 66 | + def test_max_capacity_from_env_channels(self): |
| 67 | + with ( |
| 68 | + mock.patch.dict( |
| 69 | + os.environ, {"ODOO_QUEUE_JOB_CHANNELS": "root:7,sub:2"}, clear=True |
| 70 | + ), |
| 71 | + mock.patch.object(runner, "queue_job_config", {}), |
| 72 | + ): |
| 73 | + self.assertEqual(runner._max_capacity(), 7) |
| 74 | + |
| 75 | + def test_max_capacity_from_env_channels_without_root(self): |
| 76 | + with ( |
| 77 | + mock.patch.dict( |
| 78 | + os.environ, {"ODOO_QUEUE_JOB_CHANNELS": "sub:2"}, clear=True |
| 79 | + ), |
| 80 | + mock.patch.object(runner, "queue_job_config", {}), |
| 81 | + ): |
| 82 | + self.assertEqual(runner._max_capacity(), 1) |
| 83 | + |
| 84 | + def test_max_capacity_from_env(self): |
| 85 | + with ( |
| 86 | + mock.patch.dict( |
| 87 | + os.environ, {"ODOO_QUEUE_JOB_MAX_CAPACITY": "5"}, clear=True |
| 88 | + ), |
| 89 | + mock.patch.object(runner, "queue_job_config", {}), |
| 90 | + ): |
| 91 | + self.assertEqual(runner._max_capacity(), 5) |
| 92 | + |
| 93 | + def test_max_capacity_from_odoo_config(self): |
| 94 | + with ( |
| 95 | + mock.patch.dict(os.environ, {}, clear=True), |
| 96 | + mock.patch.object(runner, "queue_job_config", {"max_capacity": "3"}), |
| 97 | + ): |
| 98 | + self.assertEqual(runner._max_capacity(), 3) |
| 99 | + |
| 100 | + def test_max_capacity_env_priority_over_odoo_config(self): |
| 101 | + with ( |
| 102 | + mock.patch.dict( |
| 103 | + os.environ, {"ODOO_QUEUE_JOB_MAX_CAPACITY": "5"}, clear=True |
| 104 | + ), |
| 105 | + mock.patch.object(runner, "queue_job_config", {"max_capacity": "3"}), |
| 106 | + ): |
| 107 | + self.assertEqual(runner._max_capacity(), 5) |
| 108 | + |
| 109 | + def test_max_capacity_default(self): |
| 110 | + with ( |
| 111 | + mock.patch.dict(os.environ, {}, clear=True), |
| 112 | + mock.patch.object(runner, "queue_job_config", {}), |
| 113 | + ): |
| 114 | + self.assertEqual(runner._max_capacity(), 0) |
0 commit comments