@@ -30,14 +30,14 @@ import (
3030
3131func TestCalculateDesiredReplicas (t * testing.T ) {
3232 tests := []struct {
33- name string
34- policy * kubeaiv1alpha1.AIInferenceAutoscalerPolicy
35- currentReplicas int32
36- currentMetrics * kubeaiv1alpha1.CurrentMetrics
37- expected int32
38- expectedAlgorithm string
39- expectedRequestedAlgoNotFound bool
40- expectedRequestedName string
33+ name string
34+ policy * kubeaiv1alpha1.AIInferenceAutoscalerPolicy
35+ currentReplicas int32
36+ currentMetrics * kubeaiv1alpha1.CurrentMetrics
37+ expected int32
38+ expectedAlgorithm string
39+ expectedRequestedAlgoNotFound bool
40+ expectedRequestedName string
4141 }{
4242 {
4343 name : "scale up based on latency" ,
@@ -53,12 +53,12 @@ func TestCalculateDesiredReplicas(t *testing.T) {
5353 },
5454 },
5555 },
56- currentReplicas : 2 ,
57- currentMetrics : & kubeaiv1alpha1.CurrentMetrics {LatencyP99Ms : 200 },
58- expected : 4 ,
59- expectedAlgorithm : "MaxRatio" ,
60- expectedRequestedAlgoNotFound : false ,
61- expectedRequestedName : "" ,
56+ currentReplicas : 2 ,
57+ currentMetrics : & kubeaiv1alpha1.CurrentMetrics {LatencyP99Ms : 200 },
58+ expected : 4 ,
59+ expectedAlgorithm : "MaxRatio" ,
60+ expectedRequestedAlgoNotFound : false ,
61+ expectedRequestedName : "" ,
6262 },
6363 {
6464 name : "scale up based on GPU utilization" ,
@@ -74,12 +74,12 @@ func TestCalculateDesiredReplicas(t *testing.T) {
7474 },
7575 },
7676 },
77- currentReplicas : 2 ,
78- currentMetrics : & kubeaiv1alpha1.CurrentMetrics {GPUUtilizationPercent : 100 },
79- expected : 4 ,
80- expectedAlgorithm : "MaxRatio" ,
81- expectedRequestedAlgoNotFound : false ,
82- expectedRequestedName : "" ,
77+ currentReplicas : 2 ,
78+ currentMetrics : & kubeaiv1alpha1.CurrentMetrics {GPUUtilizationPercent : 100 },
79+ expected : 4 ,
80+ expectedAlgorithm : "MaxRatio" ,
81+ expectedRequestedAlgoNotFound : false ,
82+ expectedRequestedName : "" ,
8383 },
8484 {
8585 name : "respect max replicas" ,
@@ -95,12 +95,12 @@ func TestCalculateDesiredReplicas(t *testing.T) {
9595 },
9696 },
9797 },
98- currentReplicas : 3 ,
99- currentMetrics : & kubeaiv1alpha1.CurrentMetrics {LatencyP99Ms : 500 },
100- expected : 5 ,
101- expectedAlgorithm : "MaxRatio" ,
102- expectedRequestedAlgoNotFound : false ,
103- expectedRequestedName : "" ,
98+ currentReplicas : 3 ,
99+ currentMetrics : & kubeaiv1alpha1.CurrentMetrics {LatencyP99Ms : 500 },
100+ expected : 5 ,
101+ expectedAlgorithm : "MaxRatio" ,
102+ expectedRequestedAlgoNotFound : false ,
103+ expectedRequestedName : "" ,
104104 },
105105 {
106106 name : "respect min replicas" ,
@@ -116,12 +116,12 @@ func TestCalculateDesiredReplicas(t *testing.T) {
116116 },
117117 },
118118 },
119- currentReplicas : 1 ,
120- currentMetrics : & kubeaiv1alpha1.CurrentMetrics {LatencyP99Ms : 100 },
121- expected : 2 ,
122- expectedAlgorithm : "MaxRatio" ,
123- expectedRequestedAlgoNotFound : false ,
124- expectedRequestedName : "" ,
119+ currentReplicas : 1 ,
120+ currentMetrics : & kubeaiv1alpha1.CurrentMetrics {LatencyP99Ms : 100 },
121+ expected : 2 ,
122+ expectedAlgorithm : "MaxRatio" ,
123+ expectedRequestedAlgoNotFound : false ,
124+ expectedRequestedName : "" ,
125125 },
126126 {
127127 name : "no scaling when at target" ,
@@ -137,12 +137,12 @@ func TestCalculateDesiredReplicas(t *testing.T) {
137137 },
138138 },
139139 },
140- currentReplicas : 3 ,
141- currentMetrics : & kubeaiv1alpha1.CurrentMetrics {LatencyP99Ms : 100 },
142- expected : 3 ,
143- expectedAlgorithm : "MaxRatio" ,
144- expectedRequestedAlgoNotFound : false ,
145- expectedRequestedName : "" ,
140+ currentReplicas : 3 ,
141+ currentMetrics : & kubeaiv1alpha1.CurrentMetrics {LatencyP99Ms : 100 },
142+ expected : 3 ,
143+ expectedAlgorithm : "MaxRatio" ,
144+ expectedRequestedAlgoNotFound : false ,
145+ expectedRequestedName : "" ,
146146 },
147147 {
148148 name : "use highest ratio from multiple metrics" ,
@@ -162,12 +162,12 @@ func TestCalculateDesiredReplicas(t *testing.T) {
162162 },
163163 },
164164 },
165- currentReplicas : 2 ,
166- currentMetrics : & kubeaiv1alpha1.CurrentMetrics {LatencyP99Ms : 150 , GPUUtilizationPercent : 150 },
167- expected : 6 ,
168- expectedAlgorithm : "MaxRatio" ,
169- expectedRequestedAlgoNotFound : false ,
170- expectedRequestedName : "" ,
165+ currentReplicas : 2 ,
166+ currentMetrics : & kubeaiv1alpha1.CurrentMetrics {LatencyP99Ms : 150 , GPUUtilizationPercent : 150 },
167+ expected : 6 ,
168+ expectedAlgorithm : "MaxRatio" ,
169+ expectedRequestedAlgoNotFound : false ,
170+ expectedRequestedName : "" ,
171171 },
172172 {
173173 name : "use AverageRatio algorithm" ,
@@ -191,12 +191,12 @@ func TestCalculateDesiredReplicas(t *testing.T) {
191191 },
192192 },
193193 },
194- currentReplicas : 2 ,
195- currentMetrics : & kubeaiv1alpha1.CurrentMetrics {LatencyP99Ms : 200 , GPUUtilizationPercent : 100 },
196- expected : 4 , // avg of 2.0 and 2.0 = 2.0, 2 * 2.0 = 4
197- expectedAlgorithm : "AverageRatio" ,
198- expectedRequestedAlgoNotFound : false ,
199- expectedRequestedName : "AverageRatio" ,
194+ currentReplicas : 2 ,
195+ currentMetrics : & kubeaiv1alpha1.CurrentMetrics {LatencyP99Ms : 200 , GPUUtilizationPercent : 100 },
196+ expected : 4 , // avg of 2.0 and 2.0 = 2.0, 2 * 2.0 = 4
197+ expectedAlgorithm : "AverageRatio" ,
198+ expectedRequestedAlgoNotFound : false ,
199+ expectedRequestedName : "AverageRatio" ,
200200 },
201201 {
202202 name : "fallback to MaxRatio for unknown algorithm" ,
@@ -215,12 +215,12 @@ func TestCalculateDesiredReplicas(t *testing.T) {
215215 },
216216 },
217217 },
218- currentReplicas : 2 ,
219- currentMetrics : & kubeaiv1alpha1.CurrentMetrics {LatencyP99Ms : 200 },
220- expected : 4 ,
221- expectedAlgorithm : "MaxRatio" , // Falls back
222- expectedRequestedAlgoNotFound : true ,
223- expectedRequestedName : "NonExistentAlgorithm" ,
218+ currentReplicas : 2 ,
219+ currentMetrics : & kubeaiv1alpha1.CurrentMetrics {LatencyP99Ms : 200 },
220+ expected : 4 ,
221+ expectedAlgorithm : "MaxRatio" , // Falls back
222+ expectedRequestedAlgoNotFound : true ,
223+ expectedRequestedName : "NonExistentAlgorithm" ,
224224 },
225225 }
226226
0 commit comments