|
2 | 2 | # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
|
3 | 3 |
|
4 | 4 | import hashlib
|
| 5 | +import logging |
5 | 6 | from datetime import datetime, timedelta
|
6 | 7 | from unittest import mock
|
| 8 | +from unittest.mock import patch |
7 | 9 |
|
8 | 10 | import odoo.tests.common as common
|
9 | 11 |
|
10 | 12 | from odoo.addons.queue_job import identity_exact
|
| 13 | +from odoo.addons.queue_job.controllers.main import RunJobController |
11 | 14 | from odoo.addons.queue_job.delay import DelayableGraph
|
12 | 15 | from odoo.addons.queue_job.exception import (
|
13 | 16 | FailedJobError,
|
|
24 | 27 | WAIT_DEPENDENCIES,
|
25 | 28 | Job,
|
26 | 29 | )
|
| 30 | +from odoo.addons.queue_job.tests.common import trap_jobs |
27 | 31 |
|
28 | 32 | from .common import JobCommonCase
|
29 | 33 |
|
| 34 | +_logger = logging.getLogger(__name__) |
| 35 | + |
30 | 36 |
|
31 | 37 | class TestJobsOnTestingMethod(JobCommonCase):
|
32 | 38 | """Test Job"""
|
@@ -341,6 +347,25 @@ def test_job_identity_key_func_exact(self):
|
341 | 347 | job1 = Job.load(self.env, test_job_1.uuid)
|
342 | 348 | self.assertEqual(job1.identity_key, expected_key)
|
343 | 349 |
|
| 350 | + def test_failed_job_perform(self): |
| 351 | + with trap_jobs() as trap: |
| 352 | + model = self.env["test.queue.job"] |
| 353 | + job = model.with_delay(priority=1, max_retries=1).testing_method() |
| 354 | + trap.assert_jobs_count(1) |
| 355 | + with patch.object(type(job), "perform", side_effect=IOError,), patch( |
| 356 | + "odoo.sql_db.Cursor.commit", return_value=None |
| 357 | + ): # avoid odoo.sql_db: bad query: ROLLBACK TO SAVEPOINT test_0 |
| 358 | + controller = RunJobController() |
| 359 | + try: |
| 360 | + controller._try_perform_job(self.env, job) |
| 361 | + with patch( |
| 362 | + "odoo.addons.test_queue_job.models.test_models.QueueJob" |
| 363 | + ".testing_error_handler" |
| 364 | + ) as patched: |
| 365 | + patched.assert_called_once() |
| 366 | + except Exception: |
| 367 | + _logger.info("Job fails") |
| 368 | + |
344 | 369 |
|
345 | 370 | class TestJobs(JobCommonCase):
|
346 | 371 | """Test jobs on other methods or with different job configuration"""
|
|
0 commit comments