@@ -343,25 +343,40 @@ def test_processQuickExecutionNoWatchdog(mocker):
343
343
assert not result ["Value" ]["watchdogStats" ]
344
344
345
345
346
- @pytest .mark .slow
347
- def test_processSubprocessFailureNoPid (mocker ):
348
- """Test the process method of the JobWrapper class: the subprocess fails and no PID is returned."""
346
+ @pytest .mark .parametrize ("expect_failure" , [True , False ])
347
+ def test_processSubprocessFailureNoPid (mocker , monkeypatch , expect_failure ):
348
+ """Test the process method of the JobWrapper class: the subprocess fails and no PID is returned.
349
+
350
+ expect_failure is used to ensure that the JobWrapper is functioning correctly even with the other patching
351
+ that is applied in the test (e.g. CHILD_PID_POLL_INTERVALS).
352
+ """
349
353
# Test failure in starting the payload process
350
354
jw = JobWrapper ()
351
355
jw .jobArgs = {}
352
356
353
357
mocker .patch .object (jw , "_JobWrapper__report" )
354
358
mocker .patch .object (jw , "_JobWrapper__setJobParam" )
359
+ monkeypatch .setattr (
360
+ "DIRAC.WorkloadManagementSystem.JobWrapper.JobWrapper.CHILD_PID_POLL_INTERVALS" , [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]
361
+ )
362
+
355
363
mock_exeThread = mocker .Mock ()
356
364
mock_exeThread .start .side_effect = lambda : time .sleep (0.1 )
357
- mocker .patch ("DIRAC.WorkloadManagementSystem.JobWrapper.JobWrapper.ExecutionThread" , return_value = mock_exeThread )
365
+ if expect_failure :
366
+ mocker .patch (
367
+ "DIRAC.WorkloadManagementSystem.JobWrapper.JobWrapper.ExecutionThread" , return_value = mock_exeThread
368
+ )
358
369
359
370
with tempfile .NamedTemporaryFile (delete = True ) as std_out , tempfile .NamedTemporaryFile (delete = True ) as std_err :
360
371
jw .outputFile = std_out .name
361
372
jw .errorFile = std_err .name
362
373
result = jw .process (command = "mock_command" , env = {})
363
- assert not result ["OK" ]
364
- assert "Payload process could not start after 140 seconds" in result ["Message" ]
374
+
375
+ if expect_failure :
376
+ assert not result ["OK" ]
377
+ assert "Payload process could not start after 1.5 seconds" in result ["Message" ]
378
+ else :
379
+ assert result ["OK" ]
365
380
366
381
367
382
# -------------------------------------------------------------------------------------------------
0 commit comments