Skip to content

Commit 5d8c98c

Browse files
committed
feat: add a test to make sure the correct job is rescheduled by JobAgent
1 parent f47c2b9 commit 5d8c98c

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_JobAgent.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,3 +578,73 @@ def test_submitAndCheckJob(mocker, localCE, job, expectedResult1, expectedResult
578578
# From here, taskResults should be empty
579579
assert jobID in jobAgent.submissionDict
580580
assert len(jobAgent.computingElement.taskResults) == 0
581+
582+
583+
def test_submitAndCheck2Jobs(mocker):
584+
"""Test the submission and the management of the job status.
585+
586+
This time, a first job is successfully submitted, but the second submission fails.
587+
We want to make sure that both jobs are correctly managed.
588+
"""
589+
# Mock the JobAgent
590+
mocker.patch("DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__")
591+
mocker.patch("DIRAC.WorkloadManagementSystem.Agent.JobAgent.JobAgent.am_stopExecution")
592+
mocker.patch("DIRAC.WorkloadManagementSystem.Agent.JobAgent.createJobWrapper", return_value=S_OK(["jobWrapper.py"]))
593+
mocker.patch("DIRAC.Core.Security.X509Chain.X509Chain.dumpAllToString", return_value=S_OK())
594+
mocker.patch(
595+
"DIRAC.Resources.Computing.InProcessComputingElement.InProcessComputingElement.submitJob",
596+
side_effect=[S_OK(), S_ERROR("ComputingElement error")],
597+
)
598+
599+
jobAgent = JobAgent("JobAgent", "Test")
600+
jobAgent.log = gLogger.getSubLogger("JobAgent")
601+
jobAgent._initializeComputingElement("InProcess")
602+
jobAgent.ceName = "InProcess"
603+
jobAgent.jobSubmissionDelay = 0
604+
605+
jobAgent.jobReport = JobReport(0)
606+
mocker.patch.object(jobAgent, "jobReport", autospec=True)
607+
mock_rescheduleFailedJob = mocker.patch.object(jobAgent, "_rescheduleFailedJob")
608+
609+
# Submit a first job: should be successful
610+
jobID = "123"
611+
result = jobAgent._submitJob(
612+
jobID=jobID, jobParams={}, resourceParams={}, optimizerParams={}, proxyChain=X509Chain()
613+
)
614+
# Check that no error occurred during the submission process
615+
# at the level of the JobAgent
616+
assert result["OK"]
617+
618+
# Check that the job was added to jobAgent.submissionDict
619+
assert len(jobAgent.submissionDict) == 1
620+
assert jobID in jobAgent.submissionDict
621+
622+
# The submission is synchronous taskResults should already contain the result
623+
assert len(jobAgent.computingElement.taskResults) == 1
624+
625+
# Check errors that could have occurred in the innerCE
626+
result = jobAgent._checkSubmittedJobs()
627+
assert result["OK"]
628+
assert result["Value"] == ([], [])
629+
630+
mock_rescheduleFailedJob.assert_not_called()
631+
632+
# Submit a second job: should fail
633+
jobID = "456"
634+
result = jobAgent._submitJob(
635+
jobID=jobID, jobParams={}, resourceParams={}, optimizerParams={}, proxyChain=X509Chain()
636+
)
637+
# Check that no error occurred during the submission process
638+
# at the level of the JobAgent
639+
assert result["OK"]
640+
641+
# Check errors that could have occurred in the innerCE
642+
result = jobAgent._checkSubmittedJobs()
643+
assert result["OK"]
644+
assert result["Value"] == (["ComputingElement error"], [])
645+
646+
# Make sure that the correct job is rescheduled
647+
mock_rescheduleFailedJob.assert_called_with(jobID, "ComputingElement error")
648+
649+
# From here, taskResults should be empty
650+
assert len(jobAgent.computingElement.taskResults) == 0

0 commit comments

Comments
 (0)