Skip to content

Commit 2387592

Browse files
authored
Unitest fix - TestDefaultStatusUpdater_RecordJobStatusEvent (#232)
In the TestDefaultStatusUpdater_RecordJobStatusEvent unitest, set the right amout of calls for podGroup update waitGroup
1 parent 09b60aa commit 2387592

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

pkg/scheduler/cache/status_updater/default_status_updater_test.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,11 @@ func (r *SimpleRecorder) AnnotatedEventf(object runtime.Object, annotations map[
503503

504504
func TestDefaultStatusUpdater_RecordJobStatusEvent(t *testing.T) {
505505
tests := []struct {
506-
name string
507-
job jobs_fake.TestJobBasic
508-
expectedEventActions []string
509-
expectedInFlightPodGroups int
510-
expectedInFlightPods int
506+
name string
507+
job jobs_fake.TestJobBasic
508+
numPodGroupStatusUpdateCalled int
509+
expectedEventActions []string
510+
expectedInFlightPodGroups int
511511
}{
512512
{
513513
name: "Running job",
@@ -525,7 +525,6 @@ func TestDefaultStatusUpdater_RecordJobStatusEvent(t *testing.T) {
525525
},
526526
expectedEventActions: []string{},
527527
expectedInFlightPodGroups: 1,
528-
expectedInFlightPods: 0,
529528
},
530529
{
531530
name: "No ready job",
@@ -543,7 +542,6 @@ func TestDefaultStatusUpdater_RecordJobStatusEvent(t *testing.T) {
543542
},
544543
expectedEventActions: []string{"Normal NotReady Job is not ready for scheduling. Waiting for 2 pods, currently 1 exist, 0 are gated"},
545544
expectedInFlightPodGroups: 0,
546-
expectedInFlightPods: 0,
547545
},
548546
{
549547
name: "Unscheduleable job",
@@ -559,9 +557,9 @@ func TestDefaultStatusUpdater_RecordJobStatusEvent(t *testing.T) {
559557
},
560558
},
561559
},
562-
expectedEventActions: []string{"Warning Unschedulable Unable to schedule pod", "Normal Unschedulable Unable to schedule podgroup"},
563-
expectedInFlightPodGroups: 1,
564-
expectedInFlightPods: 1,
560+
numPodGroupStatusUpdateCalled: 1,
561+
expectedEventActions: []string{"Warning Unschedulable Unable to schedule pod", "Normal Unschedulable Unable to schedule podgroup"},
562+
expectedInFlightPodGroups: 1,
565563
},
566564
}
567565
for _, test := range tests {
@@ -571,6 +569,9 @@ func TestDefaultStatusUpdater_RecordJobStatusEvent(t *testing.T) {
571569
recorder := record.NewFakeRecorder(100)
572570
statusUpdater := New(kubeClient, kubeAiSchedClient, recorder, 1, false, nodePoolLabelKey)
573571
wg := sync.WaitGroup{}
572+
if test.numPodGroupStatusUpdateCalled > 0 {
573+
wg.Add(test.numPodGroupStatusUpdateCalled)
574+
}
574575
finishUpdatesChan := make(chan struct{})
575576
// wait with pod groups update until signal is given.
576577
kubeAiSchedClient.SchedulingV2alpha2().(*fakeschedulingv2alpha2.FakeSchedulingV2alpha2).PrependReactor(
@@ -600,12 +601,6 @@ func TestDefaultStatusUpdater_RecordJobStatusEvent(t *testing.T) {
600601
return true
601602
})
602603
assert.Equal(t, test.expectedInFlightPodGroups, inFlightPodGroups)
603-
inFlightPods := 0
604-
statusUpdater.inFlightPods.Range(func(key, value any) bool {
605-
inFlightPods += 1
606-
return true
607-
})
608-
assert.Equal(t, test.expectedInFlightPods, inFlightPods)
609604

610605
close(finishUpdatesChan)
611606
wg.Wait()

0 commit comments

Comments
 (0)