Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

anujagrawal699
Copy link
Contributor

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?:

NONE

@karmada-bot karmada-bot added kind/documentation Categorizes issue or PR as related to documentation. kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. labels Sep 4, 2024
@karmada-bot karmada-bot added kind/feature Categorizes issue or PR as related to a new feature. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 4, 2024
@codecov-commenter
Copy link

codecov-commenter commented Sep 4, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 31.92%. Comparing base (7a2b493) to head (e648c1b).
Report is 70 commits behind head on master.

❗ 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     
Flag Coverage Δ
unittests 31.92% <ø> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@anujagrawal699
Copy link
Contributor Author

@zhzhuang-zju

@XiShanYongYe-Chang
Copy link
Member

/assign

Comment on lines 45 to 67
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,
Copy link
Contributor

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?

Copy link
Contributor Author

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

  1. If there's no existing target for the given key, it stores the new target and returns false
  2. 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.

Copy link
Contributor

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

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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 ?

Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

@anujagrawal699 anujagrawal699 Sep 5, 2024

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?

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@anujagrawal699 anujagrawal699 force-pushed the addedTests-pkg/controllers/cronfederatedhpa branch from 0e35f96 to 4bcdfed Compare September 5, 2024 09:02
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from xishanyongye-chang. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@anujagrawal699
Copy link
Contributor Author

@zhzhuang-zju

@anujagrawal699
Copy link
Contributor Author

@zhzhuang-zju Please take a look.

Copy link
Contributor

@zhzhuang-zju zhzhuang-zju left a 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

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]>
@anujagrawal699 anujagrawal699 force-pushed the addedTests-pkg/controllers/cronfederatedhpa branch from 4bcdfed to e648c1b Compare September 9, 2024 09:14
@anujagrawal699
Copy link
Contributor Author

@XiShanYongYe-Chang CI failed.

@zhzhuang-zju
Copy link
Contributor

/retest

@anujagrawal699
Copy link
Contributor Author

@XiShanYongYe-Chang PTAL, Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/documentation Categorizes issue or PR as related to documentation. kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. kind/feature Categorizes issue or PR as related to a new feature. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants