@@ -118,7 +118,7 @@ func TestConcurrencyAutoScaler(t *testing.T) {
118118 {autoScalerEventStart , false , 100 , "00:00:00" },
119119 {autoScalerEventEnable , true , 100 , "00:00:00" },
120120 {autoScalerEventPollerSkipUpdateCooldown , true , 100 , "00:00:01" },
121- {autoScalerEventPollerUpdate , true , 116 , "00:00:02" },
121+ {autoScalerEventPollerScaleUp , true , 116 , "00:00:02" },
122122 {autoScalerEventStop , true , 116 , "00:00:02" },
123123 },
124124 },
@@ -132,12 +132,60 @@ func TestConcurrencyAutoScaler(t *testing.T) {
132132 {autoScalerEventStart , false , 100 , "00:00:00" },
133133 {autoScalerEventEnable , true , 100 , "00:00:00" },
134134 {autoScalerEventPollerSkipUpdateCooldown , true , 100 , "00:00:01" },
135- {autoScalerEventPollerUpdate , true , 200 , "00:00:02" },
135+ {autoScalerEventPollerScaleUp , true , 200 , "00:00:02" },
136136 {autoScalerEventStop , true , 200 , "00:00:02" },
137137 },
138138 },
139139 {
140- "idl pollers waiting for tasks" ,
140+ "busy pollers, scale up to maximum, and then scale down slowly" ,
141+ []* shared.AutoConfigHint {
142+ {common .PtrOf (true ), common .PtrOf (int64 (0 ))}, // <- tick, in cool down
143+ {common .PtrOf (true ), common .PtrOf (int64 (0 ))}, // <- tick, scale up
144+ {common .PtrOf (true ), common .PtrOf (int64 (10000 ))}, // <- tick, skip due to cooldown
145+ {common .PtrOf (true ), common .PtrOf (int64 (10000 ))}, // <- tick, scale down
146+ {common .PtrOf (true ), common .PtrOf (int64 (10000 ))}, // <- tick, skip due to cooldown
147+ {common .PtrOf (true ), common .PtrOf (int64 (10000 ))}, // <- tick, scale down further
148+ },
149+ []eventLog {
150+ {autoScalerEventStart , false , 100 , "00:00:00" },
151+ {autoScalerEventEnable , true , 100 , "00:00:00" },
152+ {autoScalerEventPollerSkipUpdateCooldown , true , 100 , "00:00:01" },
153+ {autoScalerEventPollerScaleUp , true , 200 , "00:00:02" },
154+ {autoScalerEventPollerSkipUpdateCooldown , true , 200 , "00:00:03" },
155+ {autoScalerEventPollerScaleDown , true , 121 , "00:00:04" },
156+ {autoScalerEventPollerSkipUpdateCooldown , true , 121 , "00:00:05" },
157+ {autoScalerEventPollerScaleDown , true , 73 , "00:00:06" },
158+ {autoScalerEventStop , true , 73 , "00:00:06" },
159+ },
160+ },
161+ {
162+ "pollers, scale up and down multiple times" ,
163+ []* shared.AutoConfigHint {
164+ {common .PtrOf (true ), common .PtrOf (int64 (0 ))}, // <- tick, in cool down
165+ {common .PtrOf (true ), common .PtrOf (int64 (0 ))}, // <- tick, scale up
166+ {common .PtrOf (true ), common .PtrOf (int64 (10000 ))}, // <- tick, skip due to cooldown
167+ {common .PtrOf (true ), common .PtrOf (int64 (10000 ))}, // <- tick, scale down
168+ {common .PtrOf (true ), common .PtrOf (int64 (0 ))}, // <- tick, skip due to cooldown
169+ {common .PtrOf (true ), common .PtrOf (int64 (0 ))}, // <- tick, scale up again
170+ {common .PtrOf (true ), common .PtrOf (int64 (10000 ))}, // <- tick, skip due to cooldown
171+ {common .PtrOf (true ), common .PtrOf (int64 (10000 ))}, // <- tick, scale down again
172+ },
173+ []eventLog {
174+ {autoScalerEventStart , false , 100 , "00:00:00" },
175+ {autoScalerEventEnable , true , 100 , "00:00:00" },
176+ {autoScalerEventPollerSkipUpdateCooldown , true , 100 , "00:00:01" },
177+ {autoScalerEventPollerScaleUp , true , 200 , "00:00:02" },
178+ {autoScalerEventPollerSkipUpdateCooldown , true , 200 , "00:00:03" },
179+ {autoScalerEventPollerScaleDown , true , 121 , "00:00:04" },
180+ {autoScalerEventPollerSkipUpdateCooldown , true , 121 , "00:00:05" },
181+ {autoScalerEventPollerScaleUp , true , 200 , "00:00:06" },
182+ {autoScalerEventPollerSkipUpdateCooldown , true , 200 , "00:00:07" },
183+ {autoScalerEventPollerScaleDown , true , 121 , "00:00:08" },
184+ {autoScalerEventStop , true , 121 , "00:00:08" },
185+ },
186+ },
187+ {
188+ "idle pollers waiting for tasks" ,
141189 []* shared.AutoConfigHint {
142190 {common .PtrOf (true ), common .PtrOf (int64 (1000 ))}, // <- tick, in cool down
143191 {common .PtrOf (true ), common .PtrOf (int64 (1000 ))}, // <- tick, scale up
@@ -146,12 +194,12 @@ func TestConcurrencyAutoScaler(t *testing.T) {
146194 {autoScalerEventStart , false , 100 , "00:00:00" },
147195 {autoScalerEventEnable , true , 100 , "00:00:00" },
148196 {autoScalerEventPollerSkipUpdateCooldown , true , 100 , "00:00:01" },
149- {autoScalerEventPollerUpdate , true , 80 , "00:00:02" },
197+ {autoScalerEventPollerScaleDown , true , 80 , "00:00:02" },
150198 {autoScalerEventStop , true , 80 , "00:00:02" },
151199 },
152200 },
153201 {
154- "idl pollers, scale down to minimum" ,
202+ "idle pollers, scale down to minimum" ,
155203 []* shared.AutoConfigHint {
156204 {common .PtrOf (true ), common .PtrOf (int64 (60000 ))}, // <- tick, in cool down
157205 {common .PtrOf (true ), common .PtrOf (int64 (60000 ))}, // <- tick, scale up
@@ -160,12 +208,12 @@ func TestConcurrencyAutoScaler(t *testing.T) {
160208 {autoScalerEventStart , false , 100 , "00:00:00" },
161209 {autoScalerEventEnable , true , 100 , "00:00:00" },
162210 {autoScalerEventPollerSkipUpdateCooldown , true , 100 , "00:00:01" },
163- {autoScalerEventPollerUpdate , true , 50 , "00:00:02" },
211+ {autoScalerEventPollerScaleDown , true , 50 , "00:00:02" },
164212 {autoScalerEventStop , true , 50 , "00:00:02" },
165213 },
166214 },
167215 {
168- "idl pollers but disabled scaling" ,
216+ "idle pollers but disabled scaling" ,
169217 []* shared.AutoConfigHint {
170218 {common .PtrOf (false ), common .PtrOf (int64 (100 ))}, // <- tick, in cool down
171219 {common .PtrOf (false ), common .PtrOf (int64 (100 ))}, // <- tick, scale up
@@ -178,7 +226,7 @@ func TestConcurrencyAutoScaler(t *testing.T) {
178226 },
179227 },
180228 {
181- "idl pollers but disabled scaling at a later time" ,
229+ "idle pollers but disabled scaling at a later time" ,
182230 []* shared.AutoConfigHint {
183231 {common .PtrOf (true ), common .PtrOf (int64 (1000 ))}, // <- tick, in cool down
184232 {common .PtrOf (true ), common .PtrOf (int64 (1000 ))}, // <- tick, scale up
@@ -188,14 +236,14 @@ func TestConcurrencyAutoScaler(t *testing.T) {
188236 {autoScalerEventStart , false , 100 , "00:00:00" },
189237 {autoScalerEventEnable , true , 100 , "00:00:00" },
190238 {autoScalerEventPollerSkipUpdateCooldown , true , 100 , "00:00:01" },
191- {autoScalerEventPollerUpdate , true , 80 , "00:00:02" },
239+ {autoScalerEventPollerScaleDown , true , 80 , "00:00:02" },
192240 {autoScalerEventDisable , false , 100 , "00:00:02" },
193241 {autoScalerEventPollerSkipUpdateNotEnabled , false , 100 , "00:00:03" },
194242 {autoScalerEventStop , false , 100 , "00:00:03" },
195243 },
196244 },
197245 {
198- "idl pollers and enabled at a later time" ,
246+ "idle pollers and enabled at a later time" ,
199247 []* shared.AutoConfigHint {
200248 {common .PtrOf (false ), common .PtrOf (int64 (1000 ))}, // <- tick, in cool down
201249 {common .PtrOf (false ), common .PtrOf (int64 (1000 ))}, // <- tick, not enabled
@@ -206,7 +254,7 @@ func TestConcurrencyAutoScaler(t *testing.T) {
206254 {autoScalerEventPollerSkipUpdateNotEnabled , false , 100 , "00:00:01" },
207255 {autoScalerEventPollerSkipUpdateNotEnabled , false , 100 , "00:00:02" },
208256 {autoScalerEventEnable , true , 100 , "00:00:02" },
209- {autoScalerEventPollerUpdate , true , 80 , "00:00:03" },
257+ {autoScalerEventPollerScaleDown , true , 80 , "00:00:03" },
210258 {autoScalerEventStop , true , 80 , "00:00:03" },
211259 },
212260 },
@@ -226,7 +274,9 @@ func TestConcurrencyAutoScaler(t *testing.T) {
226274 clock .Sleep (testTickTime / 2 ) // poll delay by 0.5 unit of time to avoid test flakiness
227275 for _ , hint := range tt .pollAutoConfigHint {
228276 t .Log ("hint process time: " , clock .Now ().Format (testTimeFormat ))
229- scaler .ProcessPollerHint (hint )
277+ for i := 0 ; i < numberOfPollsInRollingAverage ; i ++ { // simulate polling multiple times to avoid flakiness
278+ scaler .ProcessPollerHint (hint )
279+ }
230280 clock .Sleep (testTickTime )
231281 }
232282 }()
@@ -249,7 +299,7 @@ func TestConcurrencyAutoScaler(t *testing.T) {
249299
250300 var actualEvents []eventLog
251301 for _ , event := range obs .FilterMessage (autoScalerEventLogMsg ).All () {
252- if event .ContextMap ()["event" ] != autoScalerEventMetrics {
302+ if event .ContextMap ()["event" ] != string ( autoScalerEventEmitMetrics ) {
253303 t .Log ("event: " , event .ContextMap ())
254304 actualEvents = append (actualEvents , eventLog {
255305 eventType : autoScalerEvent (event .ContextMap ()["event" ].(string )),
0 commit comments