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 @@ -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 ]
Original file line number Diff line number Diff 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 == {}
You can’t perform that action at this time.
0 commit comments