|
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,
|
|
25 | 28 | WAIT_DEPENDENCIES,
|
26 | 29 | Job,
|
27 | 30 | )
|
| 31 | +from odoo.addons.queue_job.tests.common import trap_jobs |
28 | 32 |
|
29 | 33 | from .common import JobCommonCase
|
30 | 34 |
|
| 35 | +_logger = logging.getLogger(__name__) |
| 36 | + |
31 | 37 |
|
32 | 38 | class TestJobsOnTestingMethod(JobCommonCase):
|
33 | 39 | """Test Job"""
|
@@ -383,6 +389,25 @@ def test_job_identity_key_func_exact(self):
|
383 | 389 | job1 = Job.load(self.env, test_job_1.uuid)
|
384 | 390 | self.assertEqual(job1.identity_key, expected_key)
|
385 | 391 |
|
| 392 | + def test_failed_job_perform(self): |
| 393 | + with trap_jobs() as trap: |
| 394 | + model = self.env["test.queue.job"] |
| 395 | + job = model.with_delay(priority=1, max_retries=1).testing_method() |
| 396 | + trap.assert_jobs_count(1) |
| 397 | + with patch.object(type(job), "perform", side_effect=IOError), patch( |
| 398 | + "odoo.sql_db.Cursor.commit", return_value=None |
| 399 | + ): # avoid odoo.sql_db: bad query: ROLLBACK TO SAVEPOINT test_0 |
| 400 | + controller = RunJobController() |
| 401 | + try: |
| 402 | + controller._try_perform_job(self.env, job) |
| 403 | + with patch( |
| 404 | + "odoo.addons.test_queue_job.models.test_models.QueueJob" |
| 405 | + ".testing_error_handler" |
| 406 | + ) as patched: |
| 407 | + patched.assert_called_once() |
| 408 | + except Exception: |
| 409 | + _logger.info("Job fails") |
| 410 | + |
386 | 411 |
|
387 | 412 | class TestJobs(JobCommonCase):
|
388 | 413 | """Test jobs on other methods or with different job configuration"""
|
|
0 commit comments