Fix and improve preemption test to work with the new logic

pull/564/head
Bobby (Babak) Salamat 2019-01-14 14:27:16 -08:00
parent e3f4e1e378
commit 127321296c
1 changed files with 6 additions and 1 deletions

View File

@ -1407,6 +1407,7 @@ func TestPreempt(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Logf("===== Running test %v", t.Name())
stop := make(chan struct{})
cache := schedulerinternalcache.New(time.Duration(0), stop)
for _, pod := range test.pods {
@ -1443,14 +1444,18 @@ func TestPreempt(t *testing.T) {
false,
false,
schedulerapi.DefaultPercentageOfNodesToScore)
scheduler.(*genericScheduler).snapshot()
// Call Preempt and check the expected results.
node, victims, _, err := scheduler.Preempt(test.pod, schedulertesting.FakeNodeLister(makeNodeList(nodeNames)), error(&FitError{Pod: test.pod, FailedPredicates: failedPredMap}))
if err != nil {
t.Errorf("unexpected error in preemption: %v", err)
}
if (node != nil && node.Name != test.expectedNode) || (node == nil && len(test.expectedNode) != 0) {
if node != nil && node.Name != test.expectedNode {
t.Errorf("expected node: %v, got: %v", test.expectedNode, node.GetName())
}
if node == nil && len(test.expectedNode) != 0 {
t.Errorf("expected node: %v, got: nothing", test.expectedNode)
}
if len(victims) != len(test.expectedPods) {
t.Errorf("expected %v pods, got %v.", len(test.expectedPods), len(victims))
}