Skip to content

Commit

Permalink
ut
Browse files Browse the repository at this point in the history
  • Loading branch information
hzxuzhonghu committed Jul 23, 2019
1 parent f5f9c37 commit 8161694
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 60 deletions.
114 changes: 58 additions & 56 deletions pkg/scheduler/actions/allocate/allocate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,67 +146,69 @@ func TestAllocate(t *testing.T) {

allocate := New()

for i, test := range tests {
binder := &util.FakeBinder{
Binds: map[string]string{},
Channel: make(chan string),
}
schedulerCache := &cache.SchedulerCache{
Nodes: make(map[string]*api.NodeInfo),
Jobs: make(map[api.JobID]*api.JobInfo),
Queues: make(map[api.QueueID]*api.QueueInfo),
Binder: binder,
StatusUpdater: &util.FakeStatusUpdater{},
VolumeBinder: &util.FakeVolumeBinder{},

Recorder: record.NewFakeRecorder(100),
}
for _, node := range test.nodes {
schedulerCache.AddNode(node)
}
for _, pod := range test.pods {
schedulerCache.AddPod(pod)
}

for _, ss := range test.podGroups {
schedulerCache.AddPodGroupV1alpha1(ss)
}

for _, q := range test.queues {
schedulerCache.AddQueueV1alpha1(q)
}

trueValue := true
ssn := framework.OpenSession(schedulerCache, []conf.Tier{
{
Plugins: []conf.PluginOption{
{
Name: "drf",
EnabledPreemptable: &trueValue,
EnabledJobOrder: &trueValue,
},
{
Name: "proportion",
EnabledQueueOrder: &trueValue,
EnabledReclaimable: &trueValue,
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
binder := &util.FakeBinder{
Binds: map[string]string{},
Channel: make(chan string),
}
schedulerCache := &cache.SchedulerCache{
Nodes: make(map[string]*api.NodeInfo),
Jobs: make(map[api.JobID]*api.JobInfo),
Queues: make(map[api.QueueID]*api.QueueInfo),
Binder: binder,
StatusUpdater: &util.FakeStatusUpdater{},
VolumeBinder: &util.FakeVolumeBinder{},

Recorder: record.NewFakeRecorder(100),
}
for _, node := range test.nodes {
schedulerCache.AddNode(node)
}
for _, pod := range test.pods {
schedulerCache.AddPod(pod)
}

for _, ss := range test.podGroups {
schedulerCache.AddPodGroupV1alpha2(ss)
}

for _, q := range test.queues {
schedulerCache.AddQueueV1alpha2(q)
}

trueValue := true
ssn := framework.OpenSession(schedulerCache, []conf.Tier{
{
Plugins: []conf.PluginOption{
{
Name: "drf",
EnabledPreemptable: &trueValue,
EnabledJobOrder: &trueValue,
},
{
Name: "proportion",
EnabledQueueOrder: &trueValue,
EnabledReclaimable: &trueValue,
},
},
},
},
})
defer framework.CloseSession(ssn)
})
defer framework.CloseSession(ssn)

allocate.Execute(ssn)
allocate.Execute(ssn)

for i := 0; i < len(test.expected); i++ {
select {
case <-binder.Channel:
case <-time.After(3 * time.Second):
t.Errorf("Failed to get binding request.")
for i := 0; i < len(test.expected); i++ {
select {
case <-binder.Channel:
case <-time.After(3 * time.Second):
t.Errorf("Failed to get binding request.")
}
}
}

if !reflect.DeepEqual(test.expected, binder.Binds) {
t.Errorf("case %d (%s): expected: %v, got %v ", i, test.name, test.expected, binder.Binds)
}
if !reflect.DeepEqual(test.expected, binder.Binds) {
t.Errorf("expected: %v, got %v ", test.expected, binder.Binds)
}
})
}
}
4 changes: 2 additions & 2 deletions pkg/scheduler/actions/preempt/preempt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ func TestPreempt(t *testing.T) {
}

for _, ss := range test.podGroups {
schedulerCache.AddPodGroupV1alpha1(ss)
schedulerCache.AddPodGroupV1alpha2(ss)
}

for _, q := range test.queues {
schedulerCache.AddQueueV1alpha1(q)
schedulerCache.AddQueueV1alpha2(q)
}

trueValue := true
Expand Down
4 changes: 2 additions & 2 deletions pkg/scheduler/actions/reclaim/reclaim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ func TestReclaim(t *testing.T) {
}

for _, ss := range test.podGroups {
schedulerCache.AddPodGroupV1alpha1(ss)
schedulerCache.AddPodGroupV1alpha2(ss)
}

for _, q := range test.queues {
schedulerCache.AddQueueV1alpha1(q)
schedulerCache.AddQueueV1alpha2(q)
}

trueValue := true
Expand Down

0 comments on commit 8161694

Please sign in to comment.