File tree Expand file tree Collapse file tree
src/DIRAC/WorkloadManagementSystem/Agent Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -706,7 +706,13 @@ def _checkSubmittedJobs(self):
706706 # Here we iterate over a copy of the keys because we are modifying the dictionary within the loop
707707 for jobID in list (self .jobs .keys ()):
708708 taskID = self .jobs [jobID ].get ("TaskID" )
709- if taskID is None or taskID not in self .computingElement .taskResults :
709+ if taskID is None :
710+ # This generally means that there was an error before the submission
711+ # and the TaskID was not set and will never be.
712+ self .log .info ("No taskID found for job" , jobID )
713+ del self .jobs [jobID ]
714+ continue
715+ if taskID not in self .computingElement .taskResults :
710716 continue
711717
712718 result = self .computingElement .taskResults [taskID ]
Original file line number Diff line number Diff line change @@ -754,3 +754,27 @@ def test_submitAndCheck2Jobs(mocker):
754754
755755 # From here, taskResults should be empty
756756 assert len (jobAgent .computingElement .taskResults ) == 0
757+
758+
759+ def test_failureBeforeSubmission (mocker ):
760+ """Test that a failure before job submission is handled correctly.
761+
762+ We want to make sure that there is no endless loop in the finalize method.
763+ """
764+ # Mock the JobAgent
765+ mocker .patch ("DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__" )
766+
767+ jobAgent = JobAgent ("JobAgent" , "Test" )
768+ jobAgent .log = gLogger .getSubLogger ("JobAgent" )
769+
770+ # Here we simulate a failure before the job submission: no TaskID
771+ jobID = "123"
772+ jobAgent .jobs [jobID ] = {}
773+ jobAgent .jobs [jobID ]["JobReport" ] = JobReport (jobID )
774+
775+ # Make sure that the job is removed from jobAgent.jobs
776+ result = jobAgent ._checkSubmittedJobs ()
777+ assert result ["OK" ]
778+ assert result ["Value" ] == ([], [])
779+
780+ assert jobAgent .jobs == {}
You can’t perform that action at this time.
0 commit comments