@@ -166,14 +166,14 @@ func TestSelectHost(t *testing.T) {
166
166
167
167
func TestGenericScheduler (t * testing.T ) {
168
168
tests := []struct {
169
- name string
170
- predicates map [string ]algorithm.FitPredicate
171
- prioritizers []algorithm.PriorityConfig
172
- nodes []string
173
- pod * api.Pod
174
- pods []* api.Pod
175
- expectedHost string
176
- expectsErr bool
169
+ name string
170
+ predicates map [string ]algorithm.FitPredicate
171
+ prioritizers []algorithm.PriorityConfig
172
+ nodes []string
173
+ pod * api.Pod
174
+ pods []* api.Pod
175
+ expectedHosts sets. String
176
+ expectsErr bool
177
177
}{
178
178
{
179
179
predicates : map [string ]algorithm.FitPredicate {"false" : falsePredicate },
@@ -183,44 +183,43 @@ func TestGenericScheduler(t *testing.T) {
183
183
name : "test 1" ,
184
184
},
185
185
{
186
- predicates : map [string ]algorithm.FitPredicate {"true" : truePredicate },
187
- prioritizers : []algorithm.PriorityConfig {{Function : EqualPriority , Weight : 1 }},
188
- nodes : []string {"machine1" , "machine2" },
189
- // Random choice between both, the rand seeded above with zero, chooses "machine1"
190
- expectedHost : "machine1" ,
191
- name : "test 2" ,
186
+ predicates : map [string ]algorithm.FitPredicate {"true" : truePredicate },
187
+ prioritizers : []algorithm.PriorityConfig {{Function : EqualPriority , Weight : 1 }},
188
+ nodes : []string {"machine1" , "machine2" },
189
+ expectedHosts : sets .NewString ("machine1" , "machine2" ),
190
+ name : "test 2" ,
192
191
},
193
192
{
194
193
// Fits on a machine where the pod ID matches the machine name
195
- predicates : map [string ]algorithm.FitPredicate {"matches" : matchesPredicate },
196
- prioritizers : []algorithm.PriorityConfig {{Function : EqualPriority , Weight : 1 }},
197
- nodes : []string {"machine1" , "machine2" },
198
- pod : & api.Pod {ObjectMeta : api.ObjectMeta {Name : "machine2" }},
199
- expectedHost : "machine2" ,
200
- name : "test 3" ,
194
+ predicates : map [string ]algorithm.FitPredicate {"matches" : matchesPredicate },
195
+ prioritizers : []algorithm.PriorityConfig {{Function : EqualPriority , Weight : 1 }},
196
+ nodes : []string {"machine1" , "machine2" },
197
+ pod : & api.Pod {ObjectMeta : api.ObjectMeta {Name : "machine2" }},
198
+ expectedHosts : sets . NewString ( "machine2" ) ,
199
+ name : "test 3" ,
201
200
},
202
201
{
203
- predicates : map [string ]algorithm.FitPredicate {"true" : truePredicate },
204
- prioritizers : []algorithm.PriorityConfig {{Function : numericPriority , Weight : 1 }},
205
- nodes : []string {"3" , "2" , "1" },
206
- expectedHost : "3" ,
207
- name : "test 4" ,
202
+ predicates : map [string ]algorithm.FitPredicate {"true" : truePredicate },
203
+ prioritizers : []algorithm.PriorityConfig {{Function : numericPriority , Weight : 1 }},
204
+ nodes : []string {"3" , "2" , "1" },
205
+ expectedHosts : sets . NewString ( "3" ) ,
206
+ name : "test 4" ,
208
207
},
209
208
{
210
- predicates : map [string ]algorithm.FitPredicate {"matches" : matchesPredicate },
211
- prioritizers : []algorithm.PriorityConfig {{Function : numericPriority , Weight : 1 }},
212
- nodes : []string {"3" , "2" , "1" },
213
- pod : & api.Pod {ObjectMeta : api.ObjectMeta {Name : "2" }},
214
- expectedHost : "2" ,
215
- name : "test 5" ,
209
+ predicates : map [string ]algorithm.FitPredicate {"matches" : matchesPredicate },
210
+ prioritizers : []algorithm.PriorityConfig {{Function : numericPriority , Weight : 1 }},
211
+ nodes : []string {"3" , "2" , "1" },
212
+ pod : & api.Pod {ObjectMeta : api.ObjectMeta {Name : "2" }},
213
+ expectedHosts : sets . NewString ( "2" ) ,
214
+ name : "test 5" ,
216
215
},
217
216
{
218
- predicates : map [string ]algorithm.FitPredicate {"true" : truePredicate },
219
- prioritizers : []algorithm.PriorityConfig {{Function : numericPriority , Weight : 1 }, {Function : reverseNumericPriority , Weight : 2 }},
220
- nodes : []string {"3" , "2" , "1" },
221
- pod : & api.Pod {ObjectMeta : api.ObjectMeta {Name : "2" }},
222
- expectedHost : "1" ,
223
- name : "test 6" ,
217
+ predicates : map [string ]algorithm.FitPredicate {"true" : truePredicate },
218
+ prioritizers : []algorithm.PriorityConfig {{Function : numericPriority , Weight : 1 }, {Function : reverseNumericPriority , Weight : 2 }},
219
+ nodes : []string {"3" , "2" , "1" },
220
+ pod : & api.Pod {ObjectMeta : api.ObjectMeta {Name : "2" }},
221
+ expectedHosts : sets . NewString ( "1" ) ,
222
+ name : "test 6" ,
224
223
},
225
224
{
226
225
predicates : map [string ]algorithm.FitPredicate {"true" : truePredicate , "false" : falsePredicate },
@@ -266,8 +265,8 @@ func TestGenericScheduler(t *testing.T) {
266
265
if err != nil {
267
266
t .Errorf ("Unexpected error: %v" , err )
268
267
}
269
- if test .expectedHost != machine {
270
- t .Errorf ("Failed : %s, Expected: %s, Saw: %s" , test .name , test .expectedHost , machine )
268
+ if ! test .expectedHosts . Has ( machine ) {
269
+ t .Errorf ("Failed : %s, Expected: %s, Saw: %s" , test .name , test .expectedHosts , machine )
271
270
}
272
271
}
273
272
}
0 commit comments