Skip to content

Commit f7d25ad

Browse files
authored
test: update load aware scorer unit tests (#291)
Signed-off-by: jairuigou <[email protected]>
1 parent 850f80e commit f7d25ad

File tree

1 file changed

+31
-75
lines changed

1 file changed

+31
-75
lines changed

pkg/plugins/scorer/load_aware_scorer_test.go

Lines changed: 31 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -10,104 +10,60 @@ import (
1010
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend"
1111
backendmetrics "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend/metrics" // Import config for thresholds
1212
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework"
13-
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/picker"
1413
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/types"
1514

1615
"github.com/llm-d/llm-d-inference-scheduler/pkg/plugins/scorer"
1716
)
1817

1918
func TestLoadBasedScorer(t *testing.T) {
19+
podA := &types.PodMetrics{
20+
Pod: &backend.Pod{NamespacedName: k8stypes.NamespacedName{Name: "pod-a"}},
21+
MetricsState: &backendmetrics.MetricsState{
22+
WaitingQueueSize: 2,
23+
},
24+
}
25+
podB := &types.PodMetrics{
26+
Pod: &backend.Pod{NamespacedName: k8stypes.NamespacedName{Name: "pod-b"}},
27+
MetricsState: &backendmetrics.MetricsState{
28+
WaitingQueueSize: 0,
29+
},
30+
}
31+
podC := &types.PodMetrics{
32+
Pod: &backend.Pod{NamespacedName: k8stypes.NamespacedName{Name: "pod-c"}},
33+
MetricsState: &backendmetrics.MetricsState{
34+
WaitingQueueSize: 15,
35+
},
36+
}
37+
2038
tests := []struct {
21-
name string
22-
scorer framework.Scorer
23-
req *types.LLMRequest
24-
input []types.Pod
25-
wantRes *types.ProfileRunResult
26-
err bool
39+
name string
40+
scorer framework.Scorer
41+
req *types.LLMRequest
42+
input []types.Pod
43+
wantScores map[types.Pod]float64
2744
}{
2845
{
2946
name: "load based scorer",
3047
scorer: scorer.NewLoadAwareScorer(context.Background(), 10),
31-
3248
req: &types.LLMRequest{
3349
TargetModel: "critical",
3450
},
35-
// pod2 will be picked because it has the shortest queue
3651
input: []types.Pod{
37-
&types.PodMetrics{
38-
Pod: &backend.Pod{NamespacedName: k8stypes.NamespacedName{Name: "pod1"}},
39-
MetricsState: &backendmetrics.MetricsState{
40-
WaitingQueueSize: 2,
41-
KVCacheUsagePercent: 0.2,
42-
MaxActiveModels: 2,
43-
ActiveModels: map[string]int{
44-
"foo": 1,
45-
"bar": 1,
46-
},
47-
},
48-
},
49-
50-
&types.PodMetrics{
51-
Pod: &backend.Pod{NamespacedName: k8stypes.NamespacedName{Name: "pod2"}},
52-
MetricsState: &backendmetrics.MetricsState{
53-
WaitingQueueSize: 0,
54-
KVCacheUsagePercent: 0.2,
55-
MaxActiveModels: 2,
56-
ActiveModels: map[string]int{
57-
"foo": 1,
58-
"bar": 1,
59-
},
60-
},
61-
},
62-
&types.PodMetrics{
63-
Pod: &backend.Pod{NamespacedName: k8stypes.NamespacedName{Name: "pod3"}},
64-
MetricsState: &backendmetrics.MetricsState{
65-
WaitingQueueSize: 5,
66-
KVCacheUsagePercent: 0.2,
67-
MaxActiveModels: 2,
68-
ActiveModels: map[string]int{
69-
"foo": 1,
70-
"bar": 1,
71-
},
72-
},
73-
},
52+
podA, podB, podC,
7453
},
75-
wantRes: &types.ProfileRunResult{
76-
TargetPods: []types.Pod{&types.ScoredPod{
77-
Pod: &types.PodMetrics{
78-
Pod: &backend.Pod{
79-
NamespacedName: k8stypes.NamespacedName{Name: "pod2"},
80-
},
81-
MetricsState: &backendmetrics.MetricsState{
82-
WaitingQueueSize: 0,
83-
KVCacheUsagePercent: 0.2,
84-
MaxActiveModels: 2,
85-
ActiveModels: map[string]int{
86-
"foo": 1,
87-
"bar": 1,
88-
},
89-
},
90-
},
91-
Score: 0.5,
92-
},
93-
},
54+
wantScores: map[types.Pod]float64{
55+
podA: 0.4,
56+
podB: 0.5,
57+
podC: 0,
9458
},
9559
},
9660
}
9761

9862
for _, test := range tests {
9963
t.Run(test.name, func(t *testing.T) {
100-
schedulerProfile := framework.NewSchedulerProfile().
101-
WithScorers(framework.NewWeightedScorer(test.scorer, 1)).
102-
WithPicker(picker.NewMaxScorePicker(picker.DefaultMaxNumOfEndpoints))
103-
104-
got, err := schedulerProfile.Run(context.Background(), test.req, nil, test.input)
105-
106-
if test.err != (err != nil) {
107-
t.Errorf("Unexpected error, got %v, want %v", err, test.err)
108-
}
64+
got := test.scorer.Score(context.Background(), nil, nil, test.input)
10965

110-
if diff := cmp.Diff(test.wantRes, got); diff != "" {
66+
if diff := cmp.Diff(test.wantScores, got); diff != "" {
11167
t.Errorf("Unexpected output (-want +got): %v", diff)
11268
}
11369
})

0 commit comments

Comments
 (0)