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 pkg/scheduler/scheduler.go #5645

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

Conversation

anujagrawal699
Copy link
Contributor

Description:
This PR significantly enhances the unit tests for the scheduler package. The improvements aim to increase code reliability, maintainability, and test coverage for various scheduler functions.

Modifications:

  1. pkg/scheduler/scheduler_test.go

Key Improvements:

  1. Added tests for doSchedule, doScheduleBinding, and doScheduleClusterBinding functions.
  2. Added tests for scheduleResourceBindingWithClusterAffinity and scheduleResourceBindingWithClusterAffinities.
  3. Added tests for scheduleClusterResourceBindingWithClusterAffinity and scheduleClusterResourceBindingWithClusterAffinities.
  4. Added tests for patchScheduleResultForResourceBinding.
  5. Added tests for the worker functionality and scheduleNext method.
  6. Added tests for recordScheduleResultEventForResourceBinding.
  7. Added tests for the placementChanged function.
  8. Added new test cases for the TestCreateScheduler

Test Coverage:

  1. pkg/scheduler/scheduler_test.go: 29.71% to 66.90%

What type of PR is this?
/kind feature

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 the kind/feature Categorizes issue or PR as related to a new feature. label Oct 6, 2024
@karmada-bot karmada-bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Oct 6, 2024
@codecov-commenter
Copy link

codecov-commenter commented Oct 6, 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 37.03%. Comparing base (6b18b6e) to head (9a0abbf).
Report is 64 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    #5645      +/-   ##
==========================================
+ Coverage   35.19%   37.03%   +1.83%     
==========================================
  Files         645      648       +3     
  Lines       44869    45079     +210     
==========================================
+ Hits        15792    16693     +901     
+ Misses      27846    27118     -728     
- Partials     1231     1268      +37     
Flag Coverage Δ
unittests 37.03% <ø> (+1.83%) ⬆️

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.

@XiShanYongYe-Chang
Copy link
Member

/assign

if tt.expectSchedule {
assert.Len(t, patchActions, len(tt.expectedPatches), "Expected %d patch actions, got %d", len(tt.expectedPatches), len(patchActions))
for i, expectedPatch := range tt.expectedPatches {
if i < len(patchActions) {
Copy link
Member

Choose a reason for hiding this comment

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

Why add this judgment?

In addition, the judgment logic of the TestDoScheduleClusterBinding and TestDoScheduleBinding functions is different. Can the TestDoScheduleClusterBinding and TestDoScheduleBinding functions directly determine the binding field obtained at the same time?

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'll remove those judgements and refractor both tests to be consistent.

if (err != nil) != tt.expectError {
t.Errorf("scheduleResourceBindingWithClusterAffinities() error = %v, expectError %v", err, tt.expectError)
}
})
Copy link
Member

Choose a reason for hiding this comment

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

The result is not judged later. The test method can be the same as that of the TestScheduleResourceBindingWithClusterAffinity.

Copy link
Member

@XiShanYongYe-Chang XiShanYongYe-Chang left a comment

Choose a reason for hiding this comment

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

Thanks~, It's a big mr.

The name of the new test method is different from that of the existing test function.

Signed-off-by: Anuj Agrawal <[email protected]>

Added tests for pkg/scheduler/scheduler.go

Signed-off-by: Anuj Agrawal <[email protected]>
@anujagrawal699
Copy link
Contributor Author

Thanks~, It's a big mr.

The name of the new test method is different from that of the existing test function.

Yes it is big and the scheduler package is hard to test.

@anujagrawal699 anujagrawal699 force-pushed the addedTests-pkg/scheduler/scheduler.go branch from 681e490 to 9a0abbf Compare October 11, 2024 12:15
@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

@XiShanYongYe-Chang
Copy link
Member

Yes it is big and the scheduler package is hard to test.

You can consider splitting pr.

@anujagrawal699
Copy link
Contributor Author

Yes it is big and the scheduler package is hard to test.

You can consider splitting pr.

I had a question. As i have used mocks, if i spilt the file than the CI tests might fail. That's the reason i tried to make a single PR for a single file. How can i tackle it?

@XiShanYongYe-Chang
Copy link
Member

As i have used mocks, if i spilt the file than the CI tests might fail.

We need to look at what error caused the ci failure. Generally, CI failures are recorded in clear logs to tell us how to modify them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants