Skip to content

Commit 951b5af

Browse files
committed
unit-test fix
Signed-off-by: Nir Rozenbaum <[email protected]>
1 parent d8e1d79 commit 951b5af

File tree

2 files changed

+34
-37
lines changed

2 files changed

+34
-37
lines changed

pkg/epp/scheduling/framework/scheduler_profile_test.go

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,24 @@ import (
3030
)
3131

3232
func 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.
191199
type 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-
216214
func (tp *testPlugin) TypedName() plugins.TypedName {
217-
return tp.tn
215+
return tp.typedName
218216
}
219217

220218
func (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

251249
func (tp *testPlugin) PostCycle(_ context.Context, _ *types.CycleState, res *types.ProfileRunResult) {
252-
tp.PostScheduleCallCount++
250+
tp.PostCycleCallCount++
253251
}
254252

255253
func (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
}

pkg/epp/scheduling/scheduler_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ func TestSchedule(t *testing.T) {
4040
{
4141
name: "no candidate pods",
4242
req: &types.LLMRequest{
43-
TargetModel: "any-model",
4443
RequestId: uuid.NewString(),
44+
TargetModel: "any-model",
4545
},
4646
input: []types.Pod{},
4747
wantRes: nil,
@@ -50,8 +50,8 @@ func TestSchedule(t *testing.T) {
5050
{
5151
name: "finds optimal pod",
5252
req: &types.LLMRequest{
53-
TargetModel: "critical",
5453
RequestId: uuid.NewString(),
54+
TargetModel: "critical",
5555
},
5656
// pod2 will be picked because it has relatively low queue size, with the requested
5757
// model being active, and has low KV cache.
@@ -98,7 +98,7 @@ func TestSchedule(t *testing.T) {
9898
TargetPods: []types.Pod{
9999
&types.ScoredPod{
100100
Pod: &types.PodMetrics{
101-
Pod: &backend.Pod{NamespacedName: k8stypes.NamespacedName{Name: "pod2"}, Labels: make(map[string]string)},
101+
Pod: &backend.Pod{NamespacedName: k8stypes.NamespacedName{Name: "pod2"}},
102102
MetricsState: &backendmetrics.MetricsState{
103103
WaitingQueueSize: 3,
104104
KVCacheUsagePercent: 0.1,
@@ -107,7 +107,6 @@ func TestSchedule(t *testing.T) {
107107
"foo": 1,
108108
"critical": 1,
109109
},
110-
WaitingModels: map[string]int{},
111110
},
112111
},
113112
},

0 commit comments

Comments
 (0)