|
| 1 | +# Copyright 2026 ACSONE SA/NV |
| 2 | +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
| 3 | +from unittest import mock |
| 4 | + |
| 5 | +from odoo.tests import tagged |
| 6 | + |
| 7 | +from odoo.addons.queue_job.controllers.main import RunJobController |
| 8 | + |
| 9 | +from .common import JobCommonCase |
| 10 | + |
| 11 | + |
| 12 | +@tagged("post_install", "-at_install") |
| 13 | +class TestRequeueDeadJob(JobCommonCase): |
| 14 | + def test_acquire_enqueued_job(self): |
| 15 | + job_record = self._get_demo_job(uuid="test_enqueued_job") |
| 16 | + self.assertFalse( |
| 17 | + self.env["queue.job.lock"].search( |
| 18 | + [("queue_job_id", "=", job_record.id)], |
| 19 | + ), |
| 20 | + "A job lock record should not exist at this point", |
| 21 | + ) |
| 22 | + with mock.patch.object( |
| 23 | + self.env.cr, "commit", mock.Mock(side_effect=self.env.flush_all) |
| 24 | + ) as mock_commit: |
| 25 | + job = RunJobController._acquire_job(self.env, job_uuid="test_enqueued_job") |
| 26 | + mock_commit.assert_called_once() |
| 27 | + self.assertIsNotNone(job) |
| 28 | + self.assertEqual(job.uuid, "test_enqueued_job") |
| 29 | + self.assertEqual(job.state, "started") |
| 30 | + self.assertTrue( |
| 31 | + self.env["queue.job.lock"].search( |
| 32 | + [("queue_job_id", "=", job_record.id)] |
| 33 | + ), |
| 34 | + "A job lock record should exist at this point", |
| 35 | + ) |
| 36 | + |
| 37 | + def test_acquire_started_job(self): |
| 38 | + with mock.patch.object( |
| 39 | + self.env.cr, "commit", mock.Mock(side_effect=self.env.flush_all) |
| 40 | + ) as mock_commit: |
| 41 | + job = RunJobController._acquire_job(self.env, "test_started_job") |
| 42 | + mock_commit.assert_not_called() |
| 43 | + self.assertIsNone(job) |
0 commit comments