13
13
# limitations under the License.
14
14
15
15
import logging
16
- import time
17
- from concurrent .futures import ThreadPoolExecutor
18
16
from contextlib import contextmanager
19
17
from unittest import mock
20
18
@@ -204,24 +202,26 @@ def test_monitor_rulebook_processes(
204
202
get_queue_name_mock .return_value = "activation"
205
203
call_args = [
206
204
mock .call (
207
- "default" ,
208
- "queue_dispatch_" + str (activation .id ),
209
- orchestrator .queue_dispatch ,
205
+ "activation" ,
206
+ orchestrator ._manage_process_job_id (
207
+ ProcessParentType .ACTIVATION , activation .id
208
+ ),
209
+ orchestrator ._manage ,
210
210
ProcessParentType .ACTIVATION ,
211
211
activation .id ,
212
- ActivationRequest .START ,
213
212
"" ,
214
213
)
215
214
]
216
215
for running in bulk_running_processes :
217
216
call_args .append (
218
217
mock .call (
219
- "default" ,
220
- "queue_dispatch_" + str (running .activation .id ),
221
- orchestrator .queue_dispatch ,
218
+ "activation" ,
219
+ orchestrator ._manage_process_job_id (
220
+ ProcessParentType .ACTIVATION , running .activation .id
221
+ ),
222
+ orchestrator ._manage ,
222
223
ProcessParentType .ACTIVATION ,
223
224
running .activation .id ,
224
- ActivationRequest .START ,
225
225
"" ,
226
226
)
227
227
)
@@ -237,21 +237,6 @@ def test_monitor_rulebook_processes(
237
237
)
238
238
orchestrator .monitor_rulebook_processes ()
239
239
240
- # Also expect calls for running processes
241
- # (these will have None as request type)
242
- for running in bulk_running_processes :
243
- call_args .append (
244
- mock .call (
245
- "default" ,
246
- "queue_dispatch_" + str (running .activation .id ),
247
- orchestrator .queue_dispatch ,
248
- str (running .parent_type ),
249
- running .activation .id ,
250
- None ,
251
- mock .ANY , # UUID string
252
- )
253
- )
254
-
255
240
enqueue_mock .assert_has_calls (call_args , any_order = True )
256
241
257
242
@@ -283,45 +268,6 @@ def advisory_lock_mock(*args, **kwargs):
283
268
)
284
269
285
270
enqueue_mock .assert_not_called ()
286
- assert (
287
- f"queue_dispatch({ job_id } ) already being ran, " in eda_caplog .text
288
- )
271
+ assert f"_manage({ job_id } ) already being ran, " in eda_caplog .text
289
272
activation .refresh_from_db ()
290
273
assert activation .status == ActivationStatus .STOPPED
291
-
292
-
293
- @pytest .mark .django_db
294
- def test_queue_dispatch_advisory_lock (activation , eda_caplog ):
295
- """Test that queue_dispatch advisory lock prevents duplicate execution."""
296
- execution_count = 0
297
-
298
- def mock_queue_dispatch_no_lock (* args , ** kwargs ):
299
- nonlocal execution_count
300
- execution_count += 1
301
- time .sleep (1.0 )
302
- return True
303
-
304
- def concurrent_dispatch ():
305
- """Function to run queue_dispatch concurrently."""
306
- with mock .patch (
307
- "aap_eda.tasks.orchestrator.queue_dispatch_no_lock" ,
308
- side_effect = mock_queue_dispatch_no_lock ,
309
- ):
310
- orchestrator .queue_dispatch (
311
- ProcessParentType .ACTIVATION ,
312
- activation .id ,
313
- ActivationRequest .START ,
314
- "test-request" ,
315
- )
316
-
317
- with ThreadPoolExecutor (max_workers = 3 ) as executor :
318
- futures = [executor .submit (concurrent_dispatch ) for _ in range (3 )]
319
- for future in futures :
320
- future .result ()
321
-
322
- assert execution_count == 1 , f"Expected 1 execution, got { execution_count } "
323
-
324
- assert (
325
- "queue_dispatch" in eda_caplog .text
326
- and "already being ran" in eda_caplog .text
327
- )
0 commit comments