11# Copyright 2026 ACSONE SA/NV
22# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3- import logging
43from unittest import mock
54
65from odoo .tests import tagged
76
87from odoo .addons .queue_job .controllers .main import RunJobController
8+ from odoo .addons .queue_job .job import ENQUEUED , STARTED
99
1010from .common import JobCommonCase
1111
@@ -27,25 +27,37 @@ def test_acquire_enqueued_job(self):
2727 mock_commit .assert_called_once ()
2828 self .assertIsNotNone (job )
2929 self .assertEqual (job .uuid , "test_enqueued_job" )
30- self .assertEqual (job .state , "started" )
30+ self .assertEqual (job .state , STARTED )
3131 self .assertTrue (
3232 self .env ["queue.job.lock" ].search (
3333 [("queue_job_id" , "=" , job_record .id )]
3434 ),
3535 "A job lock record should exist at this point" ,
3636 )
3737
38+ def test_acquire_any_enqueued_job (self ):
39+ available_job_uuids = (
40+ self .env ["queue.job" ].search ([("state" , "=" , ENQUEUED )]).mapped ("uuid" )
41+ )
42+ with mock .patch .object (
43+ self .env .cr , "commit" , mock .Mock (side_effect = self .env .flush_all )
44+ ) as mock_commit :
45+ job = RunJobController ._acquire_job (self .env )
46+ mock_commit .assert_called_once ()
47+ self .assertIsNotNone (job )
48+ self .assertIn (job .uuid , available_job_uuids )
49+ self .assertEqual (job .state , STARTED )
50+ self .assertTrue (
51+ self .env ["queue.job.lock" ].search (
52+ [("queue_job_id" , "=" , job .db_record ().id )]
53+ ),
54+ "A job lock record should exist at this point" ,
55+ )
56+
3857 def test_acquire_started_job (self ):
39- with (
40- mock .patch .object (
41- self .env .cr , "commit" , mock .Mock (side_effect = self .env .flush_all )
42- ) as mock_commit ,
43- self .assertLogs (level = logging .WARNING ) as logs ,
44- ):
58+ with mock .patch .object (
59+ self .env .cr , "commit" , mock .Mock (side_effect = self .env .flush_all )
60+ ) as mock_commit :
4561 job = RunJobController ._acquire_job (self .env , "test_started_job" )
4662 mock_commit .assert_not_called ()
4763 self .assertIsNone (job )
48- self .assertIn (
49- "was requested to run job test_started_job, but it does not exist" ,
50- logs .output [0 ],
51- )
0 commit comments