@@ -344,24 +344,40 @@ def test_processQuickExecutionNoWatchdog(mocker):
344344
345345
346346@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."""
347+ @pytest .mark .parametrize ("expect_failure" , [True , False ])
348+ def test_processSubprocessFailureNoPid (mocker , monkeypatch , expect_failure ):
349+ """Test the process method of the JobWrapper class: the subprocess fails and no PID is returned.
350+
351+ expect_failure is used to ensure that the JobWrapper is functioning correctly even with the other patching
352+ that is applied in the test (e.g. CHILD_PID_POLL_INTERVALS).
353+ """
349354 # Test failure in starting the payload process
350355 jw = JobWrapper ()
351356 jw .jobArgs = {}
352357
353358 mocker .patch .object (jw , "_JobWrapper__report" )
354359 mocker .patch .object (jw , "_JobWrapper__setJobParam" )
360+ monkeypatch .setattr (
361+ "DIRAC.WorkloadManagementSystem.JobWrapper.JobWrapper.CHILD_PID_POLL_INTERVALS" , [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]
362+ )
363+
355364 mock_exeThread = mocker .Mock ()
356365 mock_exeThread .start .side_effect = lambda : time .sleep (0.1 )
357- mocker .patch ("DIRAC.WorkloadManagementSystem.JobWrapper.JobWrapper.ExecutionThread" , return_value = mock_exeThread )
366+ if expect_failure :
367+ mocker .patch (
368+ "DIRAC.WorkloadManagementSystem.JobWrapper.JobWrapper.ExecutionThread" , return_value = mock_exeThread
369+ )
358370
359371 with tempfile .NamedTemporaryFile (delete = True ) as std_out , tempfile .NamedTemporaryFile (delete = True ) as std_err :
360372 jw .outputFile = std_out .name
361373 jw .errorFile = std_err .name
362374 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" ]
375+
376+ if expect_failure :
377+ assert not result ["OK" ]
378+ assert "Payload process could not start after 1.5 seconds" in result ["Message" ]
379+ else :
380+ assert result ["OK" ]
365381
366382
367383# -------------------------------------------------------------------------------------------------
0 commit comments