Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve unit test TestZeroRequest #66471

Merged
merged 1 commit into from
Jul 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 10 additions & 13 deletions pkg/scheduler/core/generic_scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,11 @@ func TestZeroRequest(t *testing.T) {
large2 := large
large2.NodeName = "machine2"
tests := []struct {
pod *v1.Pod
pods []*v1.Pod
nodes []*v1.Node
name string
pod *v1.Pod
pods []*v1.Pod
nodes []*v1.Node
name string
expectedScore int
}{
// The point of these next two tests is to show you get the same priority for a zero-request pod
// as for a pod with the defaults requests, both when the zero-request pod is already on the machine
Expand All @@ -627,6 +628,7 @@ func TestZeroRequest(t *testing.T) {
{Spec: large1}, {Spec: noResources1},
{Spec: large2}, {Spec: small2},
},
expectedScore: 25,
},
{
pod: &v1.Pod{Spec: small},
Expand All @@ -636,6 +638,7 @@ func TestZeroRequest(t *testing.T) {
{Spec: large1}, {Spec: noResources1},
{Spec: large2}, {Spec: small2},
},
expectedScore: 25,
},
// The point of this test is to verify that we're not just getting the same score no matter what we schedule.
{
Expand All @@ -646,10 +649,10 @@ func TestZeroRequest(t *testing.T) {
{Spec: large1}, {Spec: noResources1},
{Spec: large2}, {Spec: small2},
},
expectedScore: 23,
},
}

const expectedPriority int = 25
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
// This should match the configuration in defaultPriorities() in
Expand Down Expand Up @@ -683,14 +686,8 @@ func TestZeroRequest(t *testing.T) {
t.Errorf("unexpected error: %v", err)
}
for _, hp := range list {
if test.name == "test priority of larger pod with machine with zero-request pod" {
if hp.Score == expectedPriority {
t.Errorf("expected non-%d for all priorities, got list %#v", expectedPriority, list)
}
} else {
if hp.Score != expectedPriority {
t.Errorf("expected %d for all priorities, got list %#v", expectedPriority, list)
}
if hp.Score != test.expectedScore {
t.Errorf("expected %d for all priorities, got list %#v", test.expectedScore, list)
}
}
})
Expand Down