Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Lei Xue <vfs@live.com>
  • Loading branch information
carmark committed Jun 10, 2020
1 parent fded671 commit f4d6b97
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 26 deletions.
42 changes: 27 additions & 15 deletions pkg/scheduler/actions/preempt/preempt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

v1 "k8s.io/api/core/v1"
"k8s.io/api/scheduling/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/record"

Expand Down Expand Up @@ -144,8 +145,9 @@ func TestPreempt(t *testing.T) {
Namespace: "c1",
},
Spec: schedulingv1.PodGroupSpec{
MinMember: 1,
Queue: "q1",
MinMember: 1,
Queue: "q1",
PriorityClassName: "low-priority",
},
},
{
Expand All @@ -154,8 +156,9 @@ func TestPreempt(t *testing.T) {
Namespace: "c1",
},
Spec: schedulingv1.PodGroupSpec{
MinMember: 1,
Queue: "q1",
MinMember: 1,
Queue: "q1",
PriorityClassName: "high-priority",
},
},
},
Expand Down Expand Up @@ -190,8 +193,9 @@ func TestPreempt(t *testing.T) {
Namespace: "c1",
},
Spec: schedulingv1.PodGroupSpec{
MinMember: 1,
Queue: "q1",
MinMember: 1,
Queue: "q1",
PriorityClassName: "low-priority",
},
},
{
Expand All @@ -200,8 +204,9 @@ func TestPreempt(t *testing.T) {
Namespace: "c1",
},
Spec: schedulingv1.PodGroupSpec{
MinMember: 1,
Queue: "q1",
MinMember: 1,
Queue: "q1",
PriorityClassName: "high-priority",
},
},
},
Expand Down Expand Up @@ -242,16 +247,23 @@ func TestPreempt(t *testing.T) {
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,
Evictor: evictor,
StatusUpdater: &util.FakeStatusUpdater{},
VolumeBinder: &util.FakeVolumeBinder{},
Nodes: make(map[string]*api.NodeInfo),
Jobs: make(map[api.JobID]*api.JobInfo),
Queues: make(map[api.QueueID]*api.QueueInfo),
Binder: binder,
Evictor: evictor,
StatusUpdater: &util.FakeStatusUpdater{},
VolumeBinder: &util.FakeVolumeBinder{},
PriorityClasses: make(map[string]*v1beta1.PriorityClass),

Recorder: record.NewFakeRecorder(100),
}
schedulerCache.PriorityClasses["high-priority"] = &v1beta1.PriorityClass{
Value: 100000,
}
schedulerCache.PriorityClasses["low-priority"] = &v1beta1.PriorityClass{
Value: 10,
}
for _, node := range test.nodes {
schedulerCache.AddNode(node)
}
Expand Down
28 changes: 19 additions & 9 deletions pkg/scheduler/actions/reclaim/reclaim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

v1 "k8s.io/api/core/v1"
"k8s.io/api/scheduling/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/record"

Expand Down Expand Up @@ -56,7 +57,8 @@ func TestReclaim(t *testing.T) {
Namespace: "c1",
},
Spec: schedulingv1.PodGroupSpec{
Queue: "q1",
Queue: "q1",
PriorityClassName: "low-priority",
},
},
{
Expand All @@ -65,7 +67,8 @@ func TestReclaim(t *testing.T) {
Namespace: "c1",
},
Spec: schedulingv1.PodGroupSpec{
Queue: "q2",
Queue: "q2",
PriorityClassName: "high-priority",
},
},
},
Expand Down Expand Up @@ -111,16 +114,23 @@ func TestReclaim(t *testing.T) {
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,
Evictor: evictor,
StatusUpdater: &util.FakeStatusUpdater{},
VolumeBinder: &util.FakeVolumeBinder{},
Nodes: make(map[string]*api.NodeInfo),
Jobs: make(map[api.JobID]*api.JobInfo),
Queues: make(map[api.QueueID]*api.QueueInfo),
Binder: binder,
Evictor: evictor,
StatusUpdater: &util.FakeStatusUpdater{},
VolumeBinder: &util.FakeVolumeBinder{},
PriorityClasses: make(map[string]*v1beta1.PriorityClass),

Recorder: record.NewFakeRecorder(100),
}
schedulerCache.PriorityClasses["high-priority"] = &v1beta1.PriorityClass{
Value: 100000,
}
schedulerCache.PriorityClasses["low-priority"] = &v1beta1.PriorityClass{
Value: 10,
}
for _, node := range test.nodes {
schedulerCache.AddNode(node)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (de *defaultEvictor) Evict(p *v1.Pod, reason string) error {
return nil
}
if _, err := de.kubeclient.CoreV1().Pods(p.Namespace).UpdateStatus(pod); err != nil {
klog.Errorf("Failed to update pod <%v/%v> status: %v", err)
klog.Errorf("Failed to update pod <%v/%v> status: %v", pod.Namespace, pod.Name, err)
return err
}
if err := de.kubeclient.CoreV1().Pods(p.Namespace).Delete(p.Name, &metav1.DeleteOptions{}); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/util/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (fe *FakeEvictor) Evicts() []string {
}

// Evict is used by fake evictor to evict pods
func (fe *FakeEvictor) Evict(p *v1.Pod) error {
func (fe *FakeEvictor) Evict(p *v1.Pod, reason string) error {
fe.Lock()
defer fe.Unlock()

Expand Down

0 comments on commit f4d6b97

Please # to comment.