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 first part of unit tests for pkg/scheduler #5680

Conversation

anujagrawal699
Copy link
Contributor

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

Note:
The CI tests will fail because the mocks needed for tests are included in second part of unit tests for scheduler module.

Modifications:
pkg/scheduler/scheduler_test.go

Key Improvements:
Added tests for doSchedule, doScheduleBinding, and doScheduleClusterBinding functions.
Added tests for scheduleResourceBindingWithClusterAffinity and scheduleResourceBindingWithClusterAffinities.
Added tests for patchScheduleResultForResourceBinding.

Test Coverage:
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 12, 2024
@karmada-bot karmada-bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Oct 12, 2024
@anujagrawal699
Copy link
Contributor Author

@XiShanYongYe-Chang Please take a look.

@XiShanYongYe-Chang
Copy link
Member

Hi @anujagrawal699 these methods need to be defined:

Error: pkg/scheduler/scheduler_test.go:106:23: undefined: fakeBindingLister
Error: pkg/scheduler/scheduler_test.go:[10](https://github.com/karmada-io/karmada/actions/runs/11304671646/job/31443324973?pr=5680#step:6:11)7:30: undefined: fakeClusterBindingLister
Error: pkg/scheduler/scheduler_test.go:110:22: undefined: fakeBindingLister
Error: pkg/scheduler/scheduler_test.go:[11](https://github.com/karmada-io/karmada/actions/runs/11304671646/job/31443324973?pr=5680#step:6:12)5:29: undefined: fakeClusterBindingLister
Error: pkg/scheduler/scheduler_test.go:[12](https://github.com/karmada-io/karmada/actions/runs/11304671646/job/31443324973?pr=5680#step:6:13)0:17: undefined: mockAlgorithm
Error: pkg/scheduler/scheduler_test.go:253:22: undefined: mockAlgorithm
Error: pkg/scheduler/scheduler_test.go:261:21: undefined: fakeBindingLister
Error: pkg/scheduler/scheduler_test.go:379:22: undefined: mockAlgorithm
Error: pkg/scheduler/scheduler_test.go:387:28: undefined: fakeClusterBindingLister
Error: pkg/scheduler/scheduler_test.go:481:22: undefined: mockAlgorithm
Error: pkg/scheduler/scheduler_test.go:481:22: too many errors (typecheck)

@anujagrawal699
Copy link
Contributor Author

Hi @anujagrawal699 these methods need to be defined:

Error: pkg/scheduler/scheduler_test.go:106:23: undefined: fakeBindingLister
Error: pkg/scheduler/scheduler_test.go:[10](https://github.com/karmada-io/karmada/actions/runs/11304671646/job/31443324973?pr=5680#step:6:11)7:30: undefined: fakeClusterBindingLister
Error: pkg/scheduler/scheduler_test.go:110:22: undefined: fakeBindingLister
Error: pkg/scheduler/scheduler_test.go:[11](https://github.com/karmada-io/karmada/actions/runs/11304671646/job/31443324973?pr=5680#step:6:12)5:29: undefined: fakeClusterBindingLister
Error: pkg/scheduler/scheduler_test.go:[12](https://github.com/karmada-io/karmada/actions/runs/11304671646/job/31443324973?pr=5680#step:6:13)0:17: undefined: mockAlgorithm
Error: pkg/scheduler/scheduler_test.go:253:22: undefined: mockAlgorithm
Error: pkg/scheduler/scheduler_test.go:261:21: undefined: fakeBindingLister
Error: pkg/scheduler/scheduler_test.go:379:22: undefined: mockAlgorithm
Error: pkg/scheduler/scheduler_test.go:387:28: undefined: fakeClusterBindingLister
Error: pkg/scheduler/scheduler_test.go:481:22: undefined: mockAlgorithm
Error: pkg/scheduler/scheduler_test.go:481:22: too many errors (typecheck)

Thanks @XiShanYongYe-Chang , how can i split mocks in a split of a single file. Should i commit mocks in both parts?

@XiShanYongYe-Chang
Copy link
Member

how can i split mocks in a split of a single file. Should i commit mocks in both parts?

In my opinion, the mock parts can be submitted together and do not need to be split separately.

@anujagrawal699
Copy link
Contributor Author

how can i split mocks in a split of a single file. Should i commit mocks in both parts?

In my opinion, the mock parts can be submitted together and do not need to be split separately.

But if i commit it in one part, the mocks will be undefined in other. Similarly for imports, and unused mocks in a commit will give lint errors.

@XiShanYongYe-Chang
Copy link
Member

But if i commit it in one part, the mocks will be undefined in other. Similarly for imports, and unused mocks in a commit will give lint errors.

Add only the mock function required by each pr. When one pr is integrated, rebase the code and delete unnecessary code.

Signed-off-by: Anuj Agrawal <anujagrawal380@gmail.com>

Added first part of unit tests for pkg/scheduler

Signed-off-by: Anuj Agrawal <anujagrawal380@gmail.com>
@anujagrawal699 anujagrawal699 force-pushed the part1-addedTests-pkg/scheduler/scheduler.go branch from 458b7d2 to 0d6d2d7 Compare October 14, 2024 07:31
@codecov-commenter
Copy link

⚠️ 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 38.33%. Comparing base (6b18b6e) to head (0d6d2d7).
Report is 66 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    #5680      +/-   ##
==========================================
+ Coverage   35.19%   38.33%   +3.13%     
==========================================
  Files         645      649       +4     
  Lines       44869    45133     +264     
==========================================
+ Hits        15792    17302    +1510     
+ Misses      27846    26511    -1335     
- Partials     1231     1320      +89     
Flag Coverage Δ
unittests 38.33% <ø> (+3.13%) ⬆️

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

@XiShanYongYe-Chang Please take a look!

@XiShanYongYe-Chang
Copy link
Member

Thanks~
/assign

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
/lgtm
/approve

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Oct 15, 2024
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: XiShanYongYe-Chang

The full list of commands accepted by this bot can be found here.

The pull request process is described 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

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 15, 2024
@karmada-bot karmada-bot merged commit bf771c7 into karmada-io:master Oct 15, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. 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.

4 participants