diff --git a/src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_JobAgent.py b/src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_JobAgent.py index 11172103d04..0495fb495de 100644 --- a/src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_JobAgent.py +++ b/src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_JobAgent.py @@ -578,3 +578,73 @@ def test_submitAndCheckJob(mocker, localCE, job, expectedResult1, expectedResult # From here, taskResults should be empty assert jobID in jobAgent.submissionDict assert len(jobAgent.computingElement.taskResults) == 0 + + +def test_submitAndCheck2Jobs(mocker): + """Test the submission and the management of the job status. + + This time, a first job is successfully submitted, but the second submission fails. + We want to make sure that both jobs are correctly managed. + """ + # Mock the JobAgent + mocker.patch("DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__") + mocker.patch("DIRAC.WorkloadManagementSystem.Agent.JobAgent.JobAgent.am_stopExecution") + mocker.patch("DIRAC.WorkloadManagementSystem.Agent.JobAgent.createJobWrapper", return_value=S_OK(["jobWrapper.py"])) + mocker.patch("DIRAC.Core.Security.X509Chain.X509Chain.dumpAllToString", return_value=S_OK()) + mocker.patch( + "DIRAC.Resources.Computing.InProcessComputingElement.InProcessComputingElement.submitJob", + side_effect=[S_OK(), S_ERROR("ComputingElement error")], + ) + + jobAgent = JobAgent("JobAgent", "Test") + jobAgent.log = gLogger.getSubLogger("JobAgent") + jobAgent._initializeComputingElement("InProcess") + jobAgent.ceName = "InProcess" + jobAgent.jobSubmissionDelay = 0 + + jobAgent.jobReport = JobReport(0) + mocker.patch.object(jobAgent, "jobReport", autospec=True) + mock_rescheduleFailedJob = mocker.patch.object(jobAgent, "_rescheduleFailedJob") + + # Submit a first job: should be successful + jobID = "123" + result = jobAgent._submitJob( + jobID=jobID, jobParams={}, resourceParams={}, optimizerParams={}, proxyChain=X509Chain() + ) + # Check that no error occurred during the submission process + # at the level of the JobAgent + assert result["OK"] + + # Check that the job was added to jobAgent.submissionDict + assert len(jobAgent.submissionDict) == 1 + assert jobID in jobAgent.submissionDict + + # The submission is synchronous taskResults should already contain the result + assert len(jobAgent.computingElement.taskResults) == 1 + + # Check errors that could have occurred in the innerCE + result = jobAgent._checkSubmittedJobs() + assert result["OK"] + assert result["Value"] == ([], []) + + mock_rescheduleFailedJob.assert_not_called() + + # Submit a second job: should fail + jobID = "456" + result = jobAgent._submitJob( + jobID=jobID, jobParams={}, resourceParams={}, optimizerParams={}, proxyChain=X509Chain() + ) + # Check that no error occurred during the submission process + # at the level of the JobAgent + assert result["OK"] + + # Check errors that could have occurred in the innerCE + result = jobAgent._checkSubmittedJobs() + assert result["OK"] + assert result["Value"] == (["ComputingElement error"], []) + + # Make sure that the correct job is rescheduled + mock_rescheduleFailedJob.assert_called_with(jobID, "ComputingElement error") + + # From here, taskResults should be empty + assert len(jobAgent.computingElement.taskResults) == 0