@@ -30,16 +30,24 @@ import (
3030)
3131
3232func TestSchedulePlugins (t * testing.T ) {
33- tp1 := newTestPlugin ("test1" , 0.3 ,
34- []k8stypes.NamespacedName {{Name : "pod1" }, {Name : "pod2" }, {Name : "pod3" }},
35- k8stypes.NamespacedName {})
36- tp2 := newTestPlugin ("test2" , 0.8 ,
37- []k8stypes.NamespacedName {{Name : "pod1" }, {Name : "pod2" }},
38- k8stypes.NamespacedName {})
39- tp_filterAll := newTestPlugin ("filter all" , 0.0 ,
40- []k8stypes.NamespacedName {}, k8stypes.NamespacedName {})
41- pickerPlugin := newTestPlugin ("picker" , 0.0 ,
42- []k8stypes.NamespacedName {}, k8stypes.NamespacedName {Name : "pod1" })
33+ tp1 := & testPlugin {
34+ TypeRes : "test1" ,
35+ ScoreRes : 0.3 ,
36+ FilterRes : []k8stypes.NamespacedName {{Name : "pod1" }, {Name : "pod2" }, {Name : "pod3" }},
37+ }
38+ tp2 := & testPlugin {
39+ TypeRes : "test2" ,
40+ ScoreRes : 0.8 ,
41+ FilterRes : []k8stypes.NamespacedName {{Name : "pod1" }, {Name : "pod2" }},
42+ }
43+ tp_filterAll := & testPlugin {
44+ TypeRes : "filter all" ,
45+ FilterRes : []k8stypes.NamespacedName {},
46+ }
47+ pickerPlugin := & testPlugin {
48+ TypeRes : "picker" ,
49+ PickRes : k8stypes.NamespacedName {Name : "pod1" },
50+ }
4351
4452 tests := []struct {
4553 name string
@@ -137,7 +145,7 @@ func TestSchedulePlugins(t *testing.T) {
137145 wantRes := & types.ProfileRunResult {
138146 TargetPods : []types.Pod {
139147 & types.PodMetrics {
140- Pod : & backend.Pod {NamespacedName : test .wantTargetPod , Labels : make ( map [ string ] string ) },
148+ Pod : & backend.Pod {NamespacedName : test .wantTargetPod },
141149 },
142150 },
143151 }
@@ -149,32 +157,32 @@ func TestSchedulePlugins(t *testing.T) {
149157 for _ , plugin := range test .profile .filters {
150158 tp , _ := plugin .(* testPlugin )
151159 if tp .FilterCallCount != 1 {
152- t .Errorf ("Plugin %s Filter() called %d times, expected 1" , plugin .TypedName (), tp .FilterCallCount )
160+ t .Errorf ("Plugin '%s' Filter() called %d times, expected 1" , plugin .TypedName (), tp .FilterCallCount )
153161 }
154162 }
155163 for _ , plugin := range test .profile .scorers {
156164 tp , _ := plugin .Scorer .(* testPlugin )
157165 if tp .ScoreCallCount != 1 {
158- t .Errorf ("Plugin %s Score() called %d times, expected 1" , plugin .TypedName (), tp .ScoreCallCount )
166+ t .Errorf ("Plugin '%s' Score() called %d times, expected 1" , plugin .TypedName (), tp .ScoreCallCount )
159167 }
160168 if test .numPodsToScore != tp .NumOfScoredPods {
161- t .Errorf ("Plugin %s Score() called with %d pods, expected %d" , plugin .TypedName (), tp .NumOfScoredPods , test .numPodsToScore )
169+ t .Errorf ("Plugin '%s' Score() called with %d pods, expected %d" , plugin .TypedName (), tp .NumOfScoredPods , test .numPodsToScore )
162170 }
163171 }
164172 tp , _ := test .profile .picker .(* testPlugin )
165173 if tp .NumOfPickerCandidates != test .numPodsToScore {
166- t .Errorf ("Picker plugin %s Pick() called with %d candidates, expected %d" , tp .TypedName (), tp .NumOfPickerCandidates , tp .NumOfScoredPods )
174+ t .Errorf ("Picker plugin '%s' Pick() called with %d candidates, expected %d" , tp .TypedName (), tp .NumOfPickerCandidates , tp .NumOfScoredPods )
167175 }
168176 if tp .PickCallCount != 1 {
169- t .Errorf ("Picker plugin %s Pick() called %d times, expected 1" , tp .TypedName (), tp .PickCallCount )
177+ t .Errorf ("Picker plugin '%s' Pick() called %d times, expected 1" , tp .TypedName (), tp .PickCallCount )
170178 }
171179 if tp .WinnerPodScore != test .targetPodScore {
172180 t .Errorf ("winner pod score %v, expected %v" , tp .WinnerPodScore , test .targetPodScore )
173181 }
174182 for _ , plugin := range test .profile .postCyclePlugins {
175183 tp , _ := plugin .(* testPlugin )
176- if tp .PostScheduleCallCount != 1 {
177- t .Errorf ("Plugin %s PostSchedule () called %d times, expected 1" , plugin .TypedName (), tp .PostScheduleCallCount )
184+ if tp .PostCycleCallCount != 1 {
185+ t .Errorf ("Plugin '%s' PostCycle () called %d times, expected 1" , plugin .TypedName (), tp .PostCycleCallCount )
178186 }
179187 }
180188 })
@@ -189,32 +197,22 @@ var _ PostCycle = &testPlugin{}
189197
190198// testPlugin is an implementation useful in unit tests.
191199type testPlugin struct {
192- tn plugins.TypedName
200+ typedName plugins.TypedName
193201 TypeRes string
194202 ScoreCallCount int
195203 NumOfScoredPods int
196204 ScoreRes float64
197205 FilterCallCount int
198206 FilterRes []k8stypes.NamespacedName
199- PostScheduleCallCount int
207+ PostCycleCallCount int
200208 PickCallCount int
201209 NumOfPickerCandidates int
202210 PickRes k8stypes.NamespacedName
203211 WinnerPodScore float64
204212}
205213
206- func newTestPlugin (typeRes string , score float64 , pruned []k8stypes.NamespacedName ,
207- target k8stypes.NamespacedName ) * testPlugin {
208- return & testPlugin {
209- tn : plugins.TypedName {Type : typeRes , Name : "test-plugin" },
210- ScoreRes : score ,
211- FilterRes : pruned ,
212- PickRes : target ,
213- }
214- }
215-
216214func (tp * testPlugin ) TypedName () plugins.TypedName {
217- return tp .tn
215+ return tp .typedName
218216}
219217
220218func (tp * testPlugin ) Filter (_ context.Context , _ * types.CycleState , _ * types.LLMRequest , pods []types.Pod ) []types.Pod {
@@ -249,14 +247,14 @@ func (tp *testPlugin) Pick(_ context.Context, _ *types.CycleState, scoredPods []
249247}
250248
251249func (tp * testPlugin ) PostCycle (_ context.Context , _ * types.CycleState , res * types.ProfileRunResult ) {
252- tp .PostScheduleCallCount ++
250+ tp .PostCycleCallCount ++
253251}
254252
255253func (tp * testPlugin ) reset () {
256254 tp .FilterCallCount = 0
257255 tp .ScoreCallCount = 0
258256 tp .NumOfScoredPods = 0
259- tp .PostScheduleCallCount = 0
257+ tp .PostCycleCallCount = 0
260258 tp .PickCallCount = 0
261259 tp .NumOfPickerCandidates = 0
262260}
0 commit comments