@@ -257,3 +257,53 @@ func TestAddNode(t *testing.T) {
257
257
}
258
258
}
259
259
}
260
+
261
+ func TestGetOrCreateJob (t * testing.T ) {
262
+ owner1 := buildOwnerReference ("j1" )
263
+ owner2 := buildOwnerReference ("j2" )
264
+
265
+ pod1 := buildPod ("c1" , "p1" , "n1" , v1 .PodRunning , buildResourceList ("1000m" , "1G" ),
266
+ []metav1.OwnerReference {owner1 }, make (map [string ]string ))
267
+ pi1 := api .NewTaskInfo (pod1 )
268
+ pi1 .Job = "j1" // The job name is set by cache.
269
+
270
+ pod2 := buildPod ("c1" , "p2" , "n1" , v1 .PodRunning , buildResourceList ("1000m" , "1G" ),
271
+ []metav1.OwnerReference {owner2 }, make (map [string ]string ))
272
+ pod2 .Spec .SchedulerName = "kube-batch"
273
+ pi2 := api .NewTaskInfo (pod2 )
274
+
275
+ pod3 := buildPod ("c3" , "p3" , "n1" , v1 .PodRunning , buildResourceList ("1000m" , "1G" ),
276
+ []metav1.OwnerReference {owner2 }, make (map [string ]string ))
277
+ pi3 := api .NewTaskInfo (pod3 )
278
+
279
+ cache := & SchedulerCache {
280
+ Nodes : make (map [string ]* api.NodeInfo ),
281
+ Jobs : make (map [api.JobID ]* api.JobInfo ),
282
+ schedulerName : "kube-batch" ,
283
+ }
284
+
285
+ tests := []struct {
286
+ task * api.TaskInfo
287
+ gotJob bool // whether getOrCreateJob will return job for corresponding task
288
+ }{
289
+ {
290
+ task : pi1 ,
291
+ gotJob : true ,
292
+ },
293
+ {
294
+ task : pi2 ,
295
+ gotJob : true ,
296
+ },
297
+ {
298
+ task : pi3 ,
299
+ gotJob : false ,
300
+ },
301
+ }
302
+ for i , test := range tests {
303
+ result := cache .getOrCreateJob (test .task ) != nil
304
+ if result != test .gotJob {
305
+ t .Errorf ("case %d: \n expected %t, \n got %t \n " ,
306
+ i , test .gotJob , result )
307
+ }
308
+ }
309
+ }
0 commit comments