mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 18:00:08 +00:00
scheduler test: fix test due to nil pod assumption
This commit is contained in:
parent
a2426bd48a
commit
479f507532
@ -164,8 +164,6 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
|
|||||||
extenderPredicates []fitPredicate
|
extenderPredicates []fitPredicate
|
||||||
extenderPrioritizers []priorityConfig
|
extenderPrioritizers []priorityConfig
|
||||||
nodes []string
|
nodes []string
|
||||||
pod *v1.Pod
|
|
||||||
pods []*v1.Pod
|
|
||||||
expectedHost string
|
expectedHost string
|
||||||
expectsErr bool
|
expectsErr bool
|
||||||
}{
|
}{
|
||||||
@ -284,15 +282,13 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
|
|||||||
extenders = append(extenders, &test.extenders[ii])
|
extenders = append(extenders, &test.extenders[ii])
|
||||||
}
|
}
|
||||||
cache := schedulercache.New(time.Duration(0), wait.NeverStop)
|
cache := schedulercache.New(time.Duration(0), wait.NeverStop)
|
||||||
for _, pod := range test.pods {
|
|
||||||
cache.AddPod(pod)
|
|
||||||
}
|
|
||||||
for _, name := range test.nodes {
|
for _, name := range test.nodes {
|
||||||
cache.AddNode(&v1.Node{ObjectMeta: v1.ObjectMeta{Name: name}})
|
cache.AddNode(&v1.Node{ObjectMeta: v1.ObjectMeta{Name: name}})
|
||||||
}
|
}
|
||||||
scheduler := NewGenericScheduler(
|
scheduler := NewGenericScheduler(
|
||||||
cache, test.predicates, algorithm.EmptyMetadataProducer, test.prioritizers, algorithm.EmptyMetadataProducer, extenders)
|
cache, test.predicates, algorithm.EmptyMetadataProducer, test.prioritizers, algorithm.EmptyMetadataProducer, extenders)
|
||||||
machine, err := scheduler.Schedule(test.pod, algorithm.FakeNodeLister(makeNodeList(test.nodes)))
|
podIgnored := &v1.Pod{}
|
||||||
|
machine, err := scheduler.Schedule(podIgnored, algorithm.FakeNodeLister(makeNodeList(test.nodes)))
|
||||||
if test.expectsErr {
|
if test.expectsErr {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("Unexpected non-error for %s, machine %s", test.name, machine)
|
t.Errorf("Unexpected non-error for %s, machine %s", test.name, machine)
|
||||||
@ -300,6 +296,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
|
|||||||
} else {
|
} else {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if test.expectedHost != machine {
|
if test.expectedHost != machine {
|
||||||
t.Errorf("Failed : %s, Expected: %s, Saw: %s", test.name, test.expectedHost, machine)
|
t.Errorf("Failed : %s, Expected: %s, Saw: %s", test.name, test.expectedHost, machine)
|
||||||
|
@ -205,6 +205,7 @@ func TestGenericScheduler(t *testing.T) {
|
|||||||
predicates: map[string]algorithm.FitPredicate{"true": truePredicate},
|
predicates: map[string]algorithm.FitPredicate{"true": truePredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
prioritizers: []algorithm.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
||||||
nodes: []string{"machine1", "machine2"},
|
nodes: []string{"machine1", "machine2"},
|
||||||
|
pod: &v1.Pod{ObjectMeta: v1.ObjectMeta{Name: "ignore"}},
|
||||||
expectedHosts: sets.NewString("machine1", "machine2"),
|
expectedHosts: sets.NewString("machine1", "machine2"),
|
||||||
name: "test 2",
|
name: "test 2",
|
||||||
wErr: nil,
|
wErr: nil,
|
||||||
@ -223,6 +224,7 @@ func TestGenericScheduler(t *testing.T) {
|
|||||||
predicates: map[string]algorithm.FitPredicate{"true": truePredicate},
|
predicates: map[string]algorithm.FitPredicate{"true": truePredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Function: numericPriority, Weight: 1}},
|
prioritizers: []algorithm.PriorityConfig{{Function: numericPriority, Weight: 1}},
|
||||||
nodes: []string{"3", "2", "1"},
|
nodes: []string{"3", "2", "1"},
|
||||||
|
pod: &v1.Pod{ObjectMeta: v1.ObjectMeta{Name: "ignore"}},
|
||||||
expectedHosts: sets.NewString("3"),
|
expectedHosts: sets.NewString("3"),
|
||||||
name: "test 4",
|
name: "test 4",
|
||||||
wErr: nil,
|
wErr: nil,
|
||||||
|
Loading…
Reference in New Issue
Block a user