@@ -90,93 +90,71 @@ func getTestCriticalPodAdmissionHandler(podProvider *fakePodProvider, podKiller
90
90
}
91
91
}
92
92
93
- func TestEvictPodsToFreeRequestsWithError (t * testing.T ) {
94
- type testRun struct {
95
- testName string
96
- inputPods []* v1.Pod
97
- insufficientResources admissionRequirementList
98
- expectErr bool
99
- expectedOutput []* v1.Pod
100
- }
101
- podProvider := newFakePodProvider ()
102
- podKiller := newFakePodKiller (true )
103
- criticalPodAdmissionHandler := getTestCriticalPodAdmissionHandler (podProvider , podKiller )
104
- allPods := getTestPods ()
105
- runs := []testRun {
106
- {
107
- testName : "multiple pods eviction error" ,
108
- inputPods : []* v1.Pod {
109
- allPods [clusterCritical ], allPods [bestEffort ], allPods [burstable ], allPods [highRequestBurstable ],
110
- allPods [guaranteed ], allPods [highRequestGuaranteed ]},
111
- insufficientResources : getAdmissionRequirementList (0 , 550 , 0 ),
112
- expectErr : false ,
113
- expectedOutput : nil ,
114
- },
115
- }
116
- for _ , r := range runs {
117
- podProvider .setPods (r .inputPods )
118
- outErr := criticalPodAdmissionHandler .evictPodsToFreeRequests (allPods [clusterCritical ], r .insufficientResources )
119
- outputPods := podKiller .getKilledPods ()
120
- if ! r .expectErr && outErr != nil {
121
- t .Errorf ("evictPodsToFreeRequests returned an unexpected error during the %s test. Err: %v" , r .testName , outErr )
122
- } else if r .expectErr && outErr == nil {
123
- t .Errorf ("evictPodsToFreeRequests expected an error but returned a successful output=%v during the %s test." , outputPods , r .testName )
124
- } else if ! podListEqual (r .expectedOutput , outputPods ) {
125
- t .Errorf ("evictPodsToFreeRequests expected %v but got %v during the %s test." , r .expectedOutput , outputPods , r .testName )
126
- }
127
- podKiller .clear ()
128
- }
129
- }
130
-
131
93
func TestEvictPodsToFreeRequests (t * testing.T ) {
132
94
type testRun struct {
133
95
testName string
96
+ isPodKillerWithError bool
134
97
inputPods []* v1.Pod
135
98
insufficientResources admissionRequirementList
136
99
expectErr bool
137
100
expectedOutput []* v1.Pod
138
101
}
139
- podProvider := newFakePodProvider ()
140
- podKiller := newFakePodKiller (false )
141
- criticalPodAdmissionHandler := getTestCriticalPodAdmissionHandler (podProvider , podKiller )
142
102
allPods := getTestPods ()
143
103
runs := []testRun {
144
104
{
145
105
testName : "critical pods cannot be preempted" ,
106
+ isPodKillerWithError : false ,
146
107
inputPods : []* v1.Pod {allPods [clusterCritical ]},
147
108
insufficientResources : getAdmissionRequirementList (0 , 0 , 1 ),
148
109
expectErr : true ,
149
110
expectedOutput : nil ,
150
111
},
151
112
{
152
113
testName : "best effort pods are not preempted when attempting to free resources" ,
114
+ isPodKillerWithError : false ,
153
115
inputPods : []* v1.Pod {allPods [bestEffort ]},
154
116
insufficientResources : getAdmissionRequirementList (0 , 1 , 0 ),
155
117
expectErr : true ,
156
118
expectedOutput : nil ,
157
119
},
158
120
{
159
- testName : "multiple pods evicted" ,
121
+ testName : "multiple pods evicted" ,
122
+ isPodKillerWithError : false ,
160
123
inputPods : []* v1.Pod {
161
124
allPods [clusterCritical ], allPods [bestEffort ], allPods [burstable ], allPods [highRequestBurstable ],
162
125
allPods [guaranteed ], allPods [highRequestGuaranteed ]},
163
126
insufficientResources : getAdmissionRequirementList (0 , 550 , 0 ),
164
127
expectErr : false ,
165
128
expectedOutput : []* v1.Pod {allPods [highRequestBurstable ], allPods [highRequestGuaranteed ]},
166
129
},
130
+ {
131
+ testName : "multiple pods with eviction error" ,
132
+ isPodKillerWithError : true ,
133
+ inputPods : []* v1.Pod {
134
+ allPods [clusterCritical ], allPods [bestEffort ], allPods [burstable ], allPods [highRequestBurstable ],
135
+ allPods [guaranteed ], allPods [highRequestGuaranteed ]},
136
+ insufficientResources : getAdmissionRequirementList (0 , 550 , 0 ),
137
+ expectErr : false ,
138
+ expectedOutput : nil ,
139
+ },
167
140
}
168
141
for _ , r := range runs {
169
- podProvider .setPods (r .inputPods )
170
- outErr := criticalPodAdmissionHandler .evictPodsToFreeRequests (allPods [clusterCritical ], r .insufficientResources )
171
- outputPods := podKiller .getKilledPods ()
172
- if ! r .expectErr && outErr != nil {
173
- t .Errorf ("evictPodsToFreeRequests returned an unexpected error during the %s test. Err: %v" , r .testName , outErr )
174
- } else if r .expectErr && outErr == nil {
175
- t .Errorf ("evictPodsToFreeRequests expected an error but returned a successful output=%v during the %s test." , outputPods , r .testName )
176
- } else if ! podListEqual (r .expectedOutput , outputPods ) {
177
- t .Errorf ("evictPodsToFreeRequests expected %v but got %v during the %s test." , r .expectedOutput , outputPods , r .testName )
178
- }
179
- podKiller .clear ()
142
+ t .Run (r .testName , func (t * testing.T ) {
143
+ podProvider := newFakePodProvider ()
144
+ podKiller := newFakePodKiller (r .isPodKillerWithError )
145
+ criticalPodAdmissionHandler := getTestCriticalPodAdmissionHandler (podProvider , podKiller )
146
+ podProvider .setPods (r .inputPods )
147
+ outErr := criticalPodAdmissionHandler .evictPodsToFreeRequests (allPods [clusterCritical ], r .insufficientResources )
148
+ outputPods := podKiller .getKilledPods ()
149
+ if ! r .expectErr && outErr != nil {
150
+ t .Errorf ("evictPodsToFreeRequests returned an unexpected error during the %s test. Err: %v" , r .testName , outErr )
151
+ } else if r .expectErr && outErr == nil {
152
+ t .Errorf ("evictPodsToFreeRequests expected an error but returned a successful output=%v during the %s test." , outputPods , r .testName )
153
+ } else if ! podListEqual (r .expectedOutput , outputPods ) {
154
+ t .Errorf ("evictPodsToFreeRequests expected %v but got %v during the %s test." , r .expectedOutput , outputPods , r .testName )
155
+ }
156
+ podKiller .clear ()
157
+ })
180
158
}
181
159
}
182
160
@@ -305,14 +283,16 @@ func TestGetPodsToPreempt(t *testing.T) {
305
283
}
306
284
307
285
for _ , r := range runs {
308
- outputPods , outErr := getPodsToPreempt (r .preemptor , r .inputPods , r .insufficientResources )
309
- if ! r .expectErr && outErr != nil {
310
- t .Errorf ("getPodsToPreempt returned an unexpected error during the %s test. Err: %v" , r .testName , outErr )
311
- } else if r .expectErr && outErr == nil {
312
- t .Errorf ("getPodsToPreempt expected an error but returned a successful output=%v during the %s test." , outputPods , r .testName )
313
- } else if ! podListEqual (r .expectedOutput , outputPods ) {
314
- t .Errorf ("getPodsToPreempt expected %v but got %v during the %s test." , r .expectedOutput , outputPods , r .testName )
315
- }
286
+ t .Run (r .testName , func (t * testing.T ) {
287
+ outputPods , outErr := getPodsToPreempt (r .preemptor , r .inputPods , r .insufficientResources )
288
+ if ! r .expectErr && outErr != nil {
289
+ t .Errorf ("getPodsToPreempt returned an unexpected error during the %s test. Err: %v" , r .testName , outErr )
290
+ } else if r .expectErr && outErr == nil {
291
+ t .Errorf ("getPodsToPreempt expected an error but returned a successful output=%v during the %s test." , outputPods , r .testName )
292
+ } else if ! podListEqual (r .expectedOutput , outputPods ) {
293
+ t .Errorf ("getPodsToPreempt expected %v but got %v during the %s test." , r .expectedOutput , outputPods , r .testName )
294
+ }
295
+ })
316
296
}
317
297
}
318
298
@@ -351,10 +331,12 @@ func TestAdmissionRequirementsDistance(t *testing.T) {
351
331
},
352
332
}
353
333
for _ , run := range runs {
354
- output := run .requirements .distance (run .inputPod )
355
- if output != run .expectedOutput {
356
- t .Errorf ("expected: %f, got: %f for %s test" , run .expectedOutput , output , run .testName )
357
- }
334
+ t .Run (run .testName , func (t * testing.T ) {
335
+ output := run .requirements .distance (run .inputPod )
336
+ if output != run .expectedOutput {
337
+ t .Errorf ("expected: %f, got: %f for %s test" , run .expectedOutput , output , run .testName )
338
+ }
339
+ })
358
340
}
359
341
}
360
342
@@ -399,10 +381,12 @@ func TestAdmissionRequirementsSubtract(t *testing.T) {
399
381
},
400
382
}
401
383
for _ , run := range runs {
402
- output := run .initial .subtract (run .inputPod )
403
- if ! admissionRequirementListEqual (output , run .expectedOutput ) {
404
- t .Errorf ("expected: %s, got: %s for %s test" , run .expectedOutput .toString (), output .toString (), run .testName )
405
- }
384
+ t .Run (run .testName , func (t * testing.T ) {
385
+ output := run .initial .subtract (run .inputPod )
386
+ if ! admissionRequirementListEqual (output , run .expectedOutput ) {
387
+ t .Errorf ("expected: %s, got: %s for %s test" , run .expectedOutput .toString (), output .toString (), run .testName )
388
+ }
389
+ })
406
390
}
407
391
}
408
392
0 commit comments