Skip to content

Commit 5005b25

Browse files
aldbrweb-flow
authored andcommitted
sweep: #8168 fix: job agent fix endless loop finalize
1 parent ead08ab commit 5005b25

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/DIRAC/WorkloadManagementSystem/Agent/JobAgent.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,13 @@ def _checkSubmittedJobs(self):
693693
# Here we iterate over a copy of the keys because we are modifying the dictionary within the loop
694694
for jobID in list(self.jobs.keys()):
695695
taskID = self.jobs[jobID].get("TaskID")
696-
if taskID is None or taskID not in self.computingElement.taskResults:
696+
if taskID is None:
697+
# This generally means that there was an error before the submission
698+
# and the TaskID was not set and will never be.
699+
self.log.info("No taskID found for job", jobID)
700+
del self.jobs[jobID]
701+
continue
702+
if taskID not in self.computingElement.taskResults:
697703
continue
698704

699705
result = self.computingElement.taskResults[taskID]

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,3 +803,27 @@ def make_empty_file(*args, **kwargs):
803803

804804
# From here, taskResults should be empty
805805
assert len(jobAgent.computingElement.taskResults) == 0
806+
807+
808+
def test_failureBeforeSubmission(mocker):
809+
"""Test that a failure before job submission is handled correctly.
810+
811+
We want to make sure that there is no endless loop in the finalize method.
812+
"""
813+
# Mock the JobAgent
814+
mocker.patch("DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__")
815+
816+
jobAgent = JobAgent("JobAgent", "Test")
817+
jobAgent.log = gLogger.getSubLogger("JobAgent")
818+
819+
# Here we simulate a failure before the job submission: no TaskID
820+
jobID = "123"
821+
jobAgent.jobs[jobID] = {}
822+
jobAgent.jobs[jobID]["JobReport"] = JobReport(jobID)
823+
824+
# Make sure that the job is removed from jobAgent.jobs
825+
result = jobAgent._checkSubmittedJobs()
826+
assert result["OK"]
827+
assert result["Value"] == ([], [])
828+
829+
assert jobAgent.jobs == {}

0 commit comments

Comments
 (0)