@@ -991,7 +991,7 @@ func TestJobRunHandler(t *testing.T) {
991991 NumberOfUpstreamPerLevel : 5 ,
992992 }
993993
994- jobLineageService .On ("GetJobExecutionSummary" , ctx , mock .Anything , 5 ).
994+ jobLineageService .On ("GetJobExecutionSummary" , ctx , mock .Anything , scheduler. LineageSummaryOptions { TopUpstreamsPerJob : 5 } ).
995995 Return (nil , errors .New ("service error" ))
996996
997997 resp , err := handler .GetJobRunLineageSummary (ctx , req )
@@ -1036,14 +1036,83 @@ func TestJobRunHandler(t *testing.T) {
10361036 },
10371037 }
10381038
1039- jobLineageService .On ("GetJobExecutionSummary" , ctx , mock .Anything , 5 ).
1039+ jobLineageService .On ("GetJobExecutionSummary" , ctx , mock .Anything , scheduler. LineageSummaryOptions { TopUpstreamsPerJob : 5 } ).
10401040 Return (mockLineages , nil )
10411041
10421042 resp , err := handler .GetJobRunLineageSummary (ctx , req )
10431043 assert .Nil (t , err )
10441044 assert .NotNil (t , resp )
10451045 assert .Equal (t , len (mockLineages ), len (resp .Jobs ))
10461046 })
1047+
1048+ t .Run ("should prefer max_nodes over the deprecated per-level field and pass the window" , func (t * testing.T ) {
1049+ jobRunService := new (mockJobRunService )
1050+ jobLineageService := new (mockJobLineageService )
1051+ defer jobLineageService .AssertExpectations (t )
1052+
1053+ handler := v1beta1 .NewJobRunHandler (logger , jobRunService , nil , nil , jobLineageService , nil , nil , nil )
1054+
1055+ req := & pb.GetJobRunLineageSummaryRequest {
1056+ TargetJobs : []* pb.TargetJobRunIdentifier {{JobName : "test-job" , ScheduledAt : timestamppb .Now ()}},
1057+ NumberOfUpstreamPerLevel : 5 ,
1058+ MaxNodes : 40 ,
1059+ LineageWindowHours : 10 ,
1060+ }
1061+
1062+ jobLineageService .On ("GetJobExecutionSummary" , ctx , mock .Anything , scheduler.LineageSummaryOptions {MaxNodes : 40 , TopUpstreamsPerJob : 5 , WindowHours : 10 }).
1063+ Return ([]* scheduler.JobRunLineage {}, nil )
1064+
1065+ _ , err := handler .GetJobRunLineageSummary (ctx , req )
1066+ assert .Nil (t , err )
1067+ })
1068+
1069+ t .Run ("should map run state, blocking flag and downstream refs onto the response" , func (t * testing.T ) {
1070+ jobRunService := new (mockJobRunService )
1071+ jobLineageService := new (mockJobLineageService )
1072+ defer jobLineageService .AssertExpectations (t )
1073+
1074+ handler := v1beta1 .NewJobRunHandler (logger , jobRunService , nil , nil , jobLineageService , nil , nil , nil )
1075+
1076+ scheduledAt := timestamppb .Now ()
1077+ upstreamScheduledAt := scheduledAt .AsTime ().Add (- 1 * time .Hour )
1078+ req := & pb.GetJobRunLineageSummaryRequest {
1079+ TargetJobs : []* pb.TargetJobRunIdentifier {{JobName : "test-job" , ScheduledAt : scheduledAt }},
1080+ }
1081+
1082+ mockLineages := []* scheduler.JobRunLineage {
1083+ {
1084+ JobName : "test-job" ,
1085+ ScheduledAt : scheduledAt .AsTime (),
1086+ JobRuns : []* scheduler.JobExecutionSummary {
1087+ {
1088+ JobName : "upstream-job" ,
1089+ State : scheduler .StateRunning ,
1090+ IsBlocking : true ,
1091+ DownstreamRefs : []scheduler.JobRunKey {
1092+ {JobName : "test-job" , ScheduledAt : upstreamScheduledAt },
1093+ },
1094+ JobRunSummary : & scheduler.JobRunSummary {
1095+ JobName : "upstream-job" ,
1096+ ScheduledAt : upstreamScheduledAt ,
1097+ },
1098+ },
1099+ },
1100+ ExecutionSummary : & scheduler.LineageExecutionSummary {},
1101+ },
1102+ }
1103+
1104+ jobLineageService .On ("GetJobExecutionSummary" , ctx , mock .Anything , scheduler.LineageSummaryOptions {}).Return (mockLineages , nil )
1105+
1106+ resp , err := handler .GetJobRunLineageSummary (ctx , req )
1107+ assert .Nil (t , err )
1108+
1109+ pbRun := resp .Jobs [0 ].JobRuns [0 ]
1110+ assert .Equal (t , pb .JobRunState_JOB_RUN_STATE_RUNNING , pbRun .RunState )
1111+ assert .True (t , pbRun .IsBlocking )
1112+ assert .Len (t , pbRun .DownstreamRefs , 1 )
1113+ assert .Equal (t , "test-job" , pbRun .DownstreamRefs [0 ].JobName )
1114+ assert .Equal (t , upstreamScheduledAt .UTC (), pbRun .DownstreamRefs [0 ].ScheduledAt .AsTime ().UTC ())
1115+ })
10471116 })
10481117
10491118 t .Run ("GenerateExpectedFinishTime" , func (t * testing.T ) {
@@ -1135,8 +1204,8 @@ type mockJobLineageService struct {
11351204 mock.Mock
11361205}
11371206
1138- func (m * mockJobLineageService ) GetJobExecutionSummary (ctx context.Context , jobSchedules []* scheduler.JobSchedule , numberOfUpstreamPerLevel int ) ([]* scheduler.JobRunLineage , error ) {
1139- args := m .Called (ctx , jobSchedules , numberOfUpstreamPerLevel )
1207+ func (m * mockJobLineageService ) GetJobExecutionSummary (ctx context.Context , jobSchedules []* scheduler.JobSchedule , opts scheduler. LineageSummaryOptions ) ([]* scheduler.JobRunLineage , error ) {
1208+ args := m .Called (ctx , jobSchedules , opts )
11401209 if args .Get (0 ) == nil {
11411210 return nil , args .Error (1 )
11421211 }
0 commit comments