@@ -418,32 +418,101 @@ def test__getJDLParameters(mocker):
418
418
assert result ["Value" ]["Tags" ] == ["16Processors" , "MultiProcessor" ]
419
419
420
420
421
- @pytest .mark .parametrize (
422
- "mockJMInput, expected" ,
423
- [
424
- ({"OK" : True }, {"OK" : True , "Value" : "Problem Rescheduling Job" }),
425
- (
426
- {"OK" : False , "Message" : "Test" },
427
- {"OK" : True , "Value" : "Problem Rescheduling Job" },
428
- ),
429
- ],
430
- )
431
- def test__rescheduleFailedJob (mocker , mockJMInput , expected ):
432
- """Testing JobAgent()._rescheduleFailedJob()"""
421
+ #############################################################################
422
+
423
+
424
+ def test__rescheduleFailedJob_success (mocker ):
425
+ """Testing rescheduleFailedJob success"""
426
+ mocker .patch ("DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__" )
427
+ mocker .patch (
428
+ "DIRAC.WorkloadManagementSystem.Client.JobManagerClient.JobManagerClient.rescheduleJob" , return_value = S_OK ()
429
+ )
430
+
431
+ jobAgent = JobAgent ("Test" , "Test1" )
432
+
433
+ jobID = 101
434
+ message = "An error occurred"
435
+
436
+ jobAgent .log = gLogger
437
+ jobAgent .log .setLevel ("DEBUG" )
438
+ jobAgent .jobReport = JobReport (jobID )
439
+
440
+ result = jobAgent ._rescheduleFailedJob (jobID , message )
441
+
442
+ assert not result ["OK" ], result
443
+ assert result ["Message" ] == "Job Rescheduled" , result
444
+
445
+ # Because the jobReport cannot communicate with the JobManager, we are supposed to have the report info here
446
+ assert len (jobAgent .jobReport .jobStatusInfo ) == 1 , jobAgent .jobReport .jobStatusInfo
447
+ assert jobAgent .jobReport .jobStatusInfo [0 ][0 ] == "Rescheduled" , jobAgent .jobReport .jobStatusInfo [0 ][0 ]
448
+ assert jobAgent .jobReport .jobStatusInfo [0 ][1 ] == "" , jobAgent .jobReport .jobStatusInfo [0 ][1 ]
449
+
450
+ assert len (jobAgent .jobReport .appStatusInfo ) == 1 , jobAgent .jobReport .appStatusInfo
451
+ assert jobAgent .jobReport .appStatusInfo [0 ][0 ] == message , jobAgent .jobReport .appStatusInfo [0 ][0 ]
452
+
453
+
454
+ def test__rescheduleFailedJob_fail (mocker ):
455
+ """Testing rescheduleFailedJob when the job fails to be rescheduled."""
433
456
mocker .patch ("DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__" )
457
+ mocker .patch (
458
+ "DIRAC.WorkloadManagementSystem.Client.JobManagerClient.JobManagerClient.rescheduleJob" ,
459
+ return_value = S_ERROR ("Cannot contact JobManager" ),
460
+ )
461
+
434
462
jobAgent = JobAgent ("Test" , "Test1" )
435
463
436
464
jobID = 101
437
- message = "Test "
465
+ message = "An error occurred "
438
466
439
467
jobAgent .log = gLogger
440
468
jobAgent .log .setLevel ("DEBUG" )
441
469
jobAgent .jobReport = JobReport (jobID )
442
470
443
471
result = jobAgent ._rescheduleFailedJob (jobID , message )
444
- result = jobAgent ._finish (result ["Message" ], False )
445
472
446
- assert result == expected
473
+ assert not result ["OK" ], result
474
+ assert result ["Message" ] == "Problem Rescheduling Job"
475
+
476
+ # The JobManager could not be contacted to reschedule the jobs
477
+ # In such a case, we do not expect any status in the jobReport job/appStatusInfo
478
+ assert len (jobAgent .jobReport .jobStatusInfo ) == 0
479
+ assert len (jobAgent .jobReport .appStatusInfo ) == 0
480
+
481
+
482
+ def test__rescheduleFailedJob_multipleJobIDs (mocker ):
483
+ """Testing rescheduleFailedJob() with multiple jobIDs"""
484
+ mocker .patch ("DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__" )
485
+ mocker .patch (
486
+ "DIRAC.WorkloadManagementSystem.Client.JobManagerClient.JobManagerClient.rescheduleJob" ,
487
+ return_value = S_ERROR ("Cannot contact JobManager" ),
488
+ )
489
+
490
+ jobAgent = JobAgent ("Test" , "Test1" )
491
+
492
+ jobID1 = 101
493
+ jobID2 = 102
494
+ message = "An error occurred"
495
+
496
+ jobAgent .log = gLogger
497
+ jobAgent .log .setLevel ("DEBUG" )
498
+
499
+ # First rescheduled job
500
+ jobAgent .jobReport = JobReport (jobID1 )
501
+ result = jobAgent ._rescheduleFailedJob (jobID1 , message )
502
+
503
+ # Second rescheduled job: here we use the same JobReport but we set the jobID to a different value
504
+ jobAgent .jobReport .setJob (jobID2 )
505
+ result = jobAgent ._rescheduleFailedJob (jobID2 , message )
506
+
507
+ assert not result ["OK" ], result
508
+ assert result ["Message" ] == "Problem Rescheduling Job"
509
+
510
+ # Here we want to make sure that jobID1 is not part of the jobReport as we set another jobID
511
+ assert len (jobAgent .jobReport .jobStatusInfo ) == 1 , jobAgent .jobReport .jobStatusInfo
512
+ assert len (jobAgent .jobReport .appStatusInfo ) == 1 , jobAgent .jobReport .appStatusInfo
513
+
514
+
515
+ #############################################################################
447
516
448
517
449
518
@pytest .mark .parametrize (
0 commit comments