-
Notifications
You must be signed in to change notification settings - Fork 871
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
Added tests for cronfederatedhpa controller #5481
base: master
Are you sure you want to change the base?
Added tests for cronfederatedhpa controller #5481
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #5481 +/- ##
==========================================
+ Coverage 31.71% 31.92% +0.20%
==========================================
Files 643 643
Lines 44429 44445 +16
==========================================
+ Hits 14089 14187 +98
+ Misses 29310 29220 -90
- Partials 1030 1038 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
/assign |
name: "New scale target", | ||
cronFHPAKey: "default/test-cronhpa", | ||
initialTarget: autoscalingv2.CrossVersionObjectReference{ | ||
Kind: "Deployment", | ||
Name: "test-deployment", | ||
APIVersion: "apps/v1", | ||
}, | ||
updatedTarget: autoscalingv2.CrossVersionObjectReference{ | ||
Kind: "Deployment", | ||
Name: "test-deployment", | ||
APIVersion: "apps/v1", | ||
}, | ||
expectedUpdate: false, | ||
}, | ||
{ | ||
name: "Same scale target", | ||
cronFHPAKey: "default/test-cronhpa", | ||
initialTarget: autoscalingv2.CrossVersionObjectReference{ | ||
Kind: "Deployment", | ||
Name: "test-deployment", | ||
APIVersion: "apps/v1", | ||
}, | ||
updatedTarget: autoscalingv2.CrossVersionObjectReference{ | ||
Kind: "Deployment", | ||
Name: "test-deployment", | ||
APIVersion: "apps/v1", | ||
}, | ||
expectedUpdate: false, |
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.
What's the difference between test case New scale target
and Same scale target
?
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.
Yeah they are redundant. I thought to test both return statements with it
- If there's no existing target for the given key, it stores the new target and returns false
- If there is an existing target, it compares it with the new target and returns whether they are different.
I think we should update the New Scale Target test to start with no initial target in the handler's map.
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.
maybe we can use different cronFHPAKey to achieve the effect of a new scale target
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.
Okay, good idea. I think different keys also won't cause conflicts.
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
handler.CronFHPAScaleTargetRefUpdates(tt.cronFHPAKey, tt.initialTarget) |
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.
Is there a possibility of conflict when using the same handler for different test cases?
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.
Yeah, what you said makes sense. I'll update the tests to ensure that each test case uses a fresh handler instance.
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.
but the handler map has cronFHPAKey as the keys
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.
what do u suggest @zhzhuang-zju ?
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.
but the handler map has cronFHPAKey as the keys
sorry, I didn't get it. Could you explain what issue this might cause?
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 meant using different cronFHPAKey values for each test case, even with the same handler instance, should not lead to conflicts. What do u say?
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.
This does indeed avoid conflicts, but using different cronFHPAKeys also increases maintenance costs in the long run.
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.
Okay, i'll use a separate cronFHPAKey for new scale target and we'll create a new handler for each test case. Is it okay?
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.
yeah~make sense to me
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.
Thanks!
0e35f96
to
4bcdfed
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@zhzhuang-zju Please take a look. |
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.
others LGTM
cc @XiShanYongYe-Chang for another look
pkg/controllers/cronfederatedhpa/cronfederatedhpa_handler_test.go
Outdated
Show resolved
Hide resolved
Signed-off-by: Anuj Agrawal <[email protected]> Added tests for pkg/controllers/cronfederatedhpa Signed-off-by: Anuj Agrawal <[email protected]> Added tests for controllers/cronfederatedhpa Signed-off-by: Anuj Agrawal <[email protected]>
4bcdfed
to
e648c1b
Compare
@XiShanYongYe-Chang CI failed. |
/retest |
@XiShanYongYe-Chang PTAL, Thanks. |
Description:
This PR introduces tests for cronfederatedhpa controller. This PR tests the cronfederatedhpa_handler and some functions of cronfederatedhpa_job module. The cronfederatedhpa_controller module is harder and complex to test and we could approach it after completion of tests which are necessary, maintainable and easy.
Test Coverage:
The test coverage of the directory pkg/controllers/cronfederatedhpa has been increased from 0.00% to 27.8%.
What type of PR is this?
/kind documentation
/kind failing-test
/kind feature
What this PR does / why we need it:
This PR adds comprehensive tests for testing functionality of cronfederatedhpa controller.
Which issue(s) this PR fixes:
Fixes a part of #5470
Does this PR introduce a user-facing change?: