-
Notifications
You must be signed in to change notification settings - Fork 471
[Misc] Added unit test for APA post autoscaler #1659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
googs1025
merged 4 commits into
vllm-project:main
from
nurali-techie:nur/patch-pa-ctrl-test1
Oct 17, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
00bfc02
refactor: move mock context to new file
nurali-techie e1610fd
test: added test for APA scaling algo
nurali-techie 6da8a5b
refactor: remove unnecessary type cast for better code readability
nurali-techie 5ad92c5
chore: added licence text to new file
nurali-techie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
/* | ||
Copyright 2025 The Aibrix Team. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package algorithm | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAPAAlgorithm_ComputeTargetReplicas(t *testing.T) { | ||
algorithm := &APAAlgorithm{} | ||
|
||
tests := []struct { | ||
name string | ||
currentPodCount float64 | ||
context *mockScalingContext | ||
expected int32 | ||
}{ | ||
// scale up tests | ||
{ | ||
name: "basic_scale_up", | ||
currentPodCount: 2.0, | ||
context: &mockScalingContext{ | ||
TargetValue: 30.0, | ||
CurrentUsePerPod: 45.0, | ||
UpFluctuationTolerance: 0.1, | ||
MaxScaleUpRate: 2, | ||
DownFluctuationTolerance: 0.1, | ||
MaxScaleDownRate: 2, | ||
}, | ||
expected: 3, | ||
}, | ||
{ | ||
name: "scale_up_upto_ceiling", | ||
currentPodCount: 2.0, | ||
context: &mockScalingContext{ | ||
TargetValue: 30.0, | ||
CurrentUsePerPod: 35.0, | ||
UpFluctuationTolerance: 0.1, | ||
MaxScaleUpRate: 2, | ||
DownFluctuationTolerance: 0.1, | ||
MaxScaleDownRate: 2, | ||
}, | ||
expected: 3, | ||
}, | ||
{ | ||
name: "scale_up_upto_max_scale_up", | ||
currentPodCount: 2.0, | ||
context: &mockScalingContext{ | ||
TargetValue: 30.0, | ||
CurrentUsePerPod: 90.0, | ||
UpFluctuationTolerance: 0.1, | ||
MaxScaleUpRate: 2, | ||
DownFluctuationTolerance: 0.1, | ||
MaxScaleDownRate: 2, | ||
}, | ||
expected: 4, | ||
}, | ||
{ | ||
name: "scale_up_upto_max_scale_up_ceiling", | ||
currentPodCount: 2.0, | ||
context: &mockScalingContext{ | ||
TargetValue: 30.0, | ||
CurrentUsePerPod: 90.0, | ||
UpFluctuationTolerance: 0.1, | ||
MaxScaleUpRate: 2.5, | ||
DownFluctuationTolerance: 0.1, | ||
MaxScaleDownRate: 2, | ||
}, | ||
expected: 5, | ||
}, | ||
// scale down tests | ||
{ | ||
name: "basic_scale_down", | ||
currentPodCount: 6.0, | ||
context: &mockScalingContext{ | ||
TargetValue: 30.0, | ||
CurrentUsePerPod: 20.0, | ||
UpFluctuationTolerance: 0.1, | ||
MaxScaleUpRate: 2, | ||
DownFluctuationTolerance: 0.1, | ||
MaxScaleDownRate: 2, | ||
}, | ||
expected: 4, | ||
}, | ||
{ | ||
name: "scale_down_upto_ceiling", | ||
currentPodCount: 6.0, | ||
context: &mockScalingContext{ | ||
TargetValue: 30.0, | ||
CurrentUsePerPod: 18.0, | ||
UpFluctuationTolerance: 0.1, | ||
MaxScaleUpRate: 2, | ||
DownFluctuationTolerance: 0.1, | ||
MaxScaleDownRate: 2, | ||
}, | ||
expected: 4, | ||
}, | ||
{ | ||
name: "scale_down_upto_max_scale_down", | ||
currentPodCount: 6.0, | ||
context: &mockScalingContext{ | ||
TargetValue: 30.0, | ||
CurrentUsePerPod: 10.0, | ||
UpFluctuationTolerance: 0.1, | ||
MaxScaleUpRate: 2, | ||
DownFluctuationTolerance: 0.1, | ||
MaxScaleDownRate: 2, | ||
}, | ||
expected: 3, | ||
}, | ||
{ | ||
name: "scale_down_upto_max_scale_down_floor", | ||
currentPodCount: 6.0, | ||
context: &mockScalingContext{ | ||
TargetValue: 30.0, | ||
CurrentUsePerPod: 5.0, | ||
UpFluctuationTolerance: 0.1, | ||
MaxScaleUpRate: 2, | ||
DownFluctuationTolerance: 0.1, | ||
MaxScaleDownRate: 2.5, | ||
}, | ||
expected: 2, | ||
}, | ||
// no scaling tests | ||
{ | ||
name: "no_scaling_as_within_up_tolerance", | ||
currentPodCount: 2.0, | ||
context: &mockScalingContext{ | ||
TargetValue: 30.0, | ||
CurrentUsePerPod: 33.0, | ||
UpFluctuationTolerance: 0.1, | ||
MaxScaleUpRate: 2, | ||
DownFluctuationTolerance: 0.1, | ||
MaxScaleDownRate: 2, | ||
}, | ||
expected: 2, | ||
}, | ||
{ | ||
name: "no_scaling_as_within_down_tolerance", | ||
currentPodCount: 2.0, | ||
context: &mockScalingContext{ | ||
TargetValue: 30.0, | ||
CurrentUsePerPod: 27.0, | ||
UpFluctuationTolerance: 0.1, | ||
MaxScaleUpRate: 2, | ||
DownFluctuationTolerance: 0.1, | ||
MaxScaleDownRate: 2, | ||
}, | ||
expected: 2, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result := algorithm.computeTargetReplicas(tt.currentPodCount, tt.context) | ||
assert.Equal(t, tt.expected, result) | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to make sure one thing: we convert from float -> int to ensure the stability of the unit test, right?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not quite sure on what you are referring about stability of unit test. Unit tests will work without this change (commit_link).
This change is made for better code readability. If you see,
math.Ceil()
andmath.Floor()
always returnint
(check documentation) so it's safe to type cast to int.Once we type cast both variable
maxScaleUp
andexpectedPods
toint
; we can work with them without any further type cast which simplify the code and improve readability.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically,
math,Ceil()
math.Floor()
still return float but it's integer. The refactoring is about earlier type conversion, not about the return types here. so this is still ok