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

Add some tests for pkg/scheduler #5274

Merged
merged 1 commit into from
Aug 22, 2024
Merged

Conversation

varshith257
Copy link
Contributor

What type of PR is this?

/kind test
/kind flake

What this PR does / why we need it:

Which issue(s) this PR fixes:
Part of #5235

Special notes for your reviewer:
No

Does this PR introduce a user-facing change?:

None

@karmada-bot karmada-bot added the kind/flake Categorizes issue or PR as related to a flaky test. label Jul 29, 2024
@karmada-bot
Copy link
Collaborator

@varshith257: The label(s) kind/test cannot be applied, because the repository doesn't have them.

In response to this:

What type of PR is this?

/kind test
/kind flake

What this PR does / why we need it:

Which issue(s) this PR fixes:
Part of #5235

Special notes for your reviewer:
No

Does this PR introduce a user-facing change?:

None

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@karmada-bot
Copy link
Collaborator

Welcome @varshith257! It looks like this is your first PR to karmada-io/karmada 🎉

@karmada-bot karmada-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 29, 2024
@varshith257 varshith257 changed the title Add some tests for 'pkg/scheduler'` Add some tests for pkg/scheduler Jul 29, 2024
@varshith257
Copy link
Contributor Author

varshith257 commented Jul 29, 2024

@XiShanYongYe-Chang, I have added some tests to familiarize myself with the codebase and the coding style. Will incrementally add tests to make coverage of pkg/scheduler ~ 85 - 90%

@codecov-commenter
Copy link

codecov-commenter commented Jul 29, 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 29.94%. Comparing base (23cbfdc) to head (49adbf8).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5274      +/-   ##
==========================================
+ Coverage   29.83%   29.94%   +0.11%     
==========================================
  Files         632      632              
  Lines       43936    43936              
==========================================
+ Hits        13107    13156      +49     
+ Misses      29871    29823      -48     
+ Partials      958      957       -1     
Flag Coverage Δ
unittests 29.94% <ø> (+0.11%) ⬆️

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

Thanks @varshith257
/assign

@varshith257
Copy link
Contributor Author

varshith257 commented Aug 6, 2024

@XiShanYongYe-Chang Can you review this PR and get merged? It will also helps to me link it in cover letter and submit application :)

I will push follow up prs gradually increase test coverage of pkg/scheduler as mentioned

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~ @varshith257
Sorry, I almost forgot this pr.

pkg/scheduler/scheduler_test.go Outdated Show resolved Hide resolved
@varshith257
Copy link
Contributor Author

@XiShanYongYe-Chang PTAL

disableSchedulerEstimatorInPullMode bool
expectedError bool
expectEstablishConnection bool
}{
Copy link
Member

Choose a reason for hiding this comment

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

It seems that all cases have an error when getting the cluster object.

Copy link
Member

Choose a reason for hiding this comment

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

Hi @anujagrawal699 would you like to give some advice on this case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hello @XiShanYongYe-Chang I think the issue is that test is creating a cluster using karmadaClient, but the reconcileEstimatorConnection method is using a clusterLister to retrieve it. This can be a reason of an error when getting the cluster object. More cases like the cluster in push mode might help us determine it. There can be also other reasons of this errors. @varshith257

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 have tried though and debuged it. Maybe I can add this test in separate PR with fresh perspective of solving it. I will remove adding this test in this PR.

Copy link
Member

Choose a reason for hiding this comment

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

I think the issue is that test is creating a cluster using karmadaClient, but the reconcileEstimatorConnection method is using a clusterLister to retrieve it.

@anujagrawal699 I see you wrote a test with similar logic and it passed, so wanted to see what you thought.

I have tried though and debuged it. Maybe I can add this test in separate PR with fresh perspective of solving it. I will remove adding this test in this PR.

Hi @varshith257 I agree with you.

Copy link
Contributor

@anujagrawal699 anujagrawal699 Aug 15, 2024

Choose a reason for hiding this comment

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

@XiShanYongYe-Chang In desheduler_test.go, the tests starts and waits for the informer cache to sync and also it allows the test operations to complete with timeout. Also, i don't think the test is successfully retrieving the cluster. _, err = karmadaClient.ClusterV1alpha1().Clusters().Create(context.TODO(), cluster, metav1.CreateOptions{}) is creating a cluster. I think retrieving it using the same clusterLister method could work, it goes like

 retrievedCluster, err := scheduler.clusterLister.Get(clusterName)
if err != nil {
    t.Fatalf("Failed to retrieve cluster: %v", err)
}

@varshith257
Copy link
Contributor Author

@XiShanYongYe-Chang Any guidance on it will be greatly appreciated. I have tested with cluster creation mock and expected to call the EstablishConnection method but we can't mock it. Instead I just verified through the it invocation

@varshith257
Copy link
Contributor Author

@XiShanYongYe-Chang Any review or guidance on this

@XiShanYongYe-Chang
Copy link
Member

image

Lines in red are not covered by the test. You can find other tests to see if you can successfully get the resource from the lister.

@XiShanYongYe-Chang
Copy link
Member

Hi @varshith257 how is it going now?

By the way, would you like to review the ut tests submitted by others? It's not mandatory, you can do it as you wish, and it's an important contribution to the community. Thank you very much. (I highly encourage you to review each other. My perspective may be subjective, but you can discuss it fully and provide more valuable review comments.)

@varshith257
Copy link
Contributor Author

Sure!

@varshith257
Copy link
Contributor Author

/retest

@karmada-bot
Copy link
Collaborator

@varshith257: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@varshith257
Copy link
Contributor Author

@XiShanYongYe-Chang Can do /ok-to-test? I can't isolate why failing in e2e whiles changes done for UT?

@XiShanYongYe-Chang
Copy link
Member

Hi @varshith257, can you help pull the latest code from master and rebase it?

@varshith257
Copy link
Contributor Author

Sure!

@varshith257
Copy link
Contributor Author

@XiShanYongYe-Chang Done!

@XiShanYongYe-Chang
Copy link
Member

Hi @varshith257, can you help squash the commits into one?

@karmada-bot karmada-bot added the do-not-merge/contains-merge-commits Indicates a PR which contains merge commits. label Aug 21, 2024
@karmada-bot karmada-bot removed the do-not-merge/contains-merge-commits Indicates a PR which contains merge commits. label Aug 21, 2024
@varshith257
Copy link
Contributor Author

@XiShanYongYe-Chang Done!

@anujagrawal699
Copy link
Contributor

Hi @varshith257 . Thanks for the PR. Try running golangci-lint run --fix in the file directory to debug linting errors.

Signed-off-by: Vamshi Maskuri <[email protected]>

add review comments

Signed-off-by: Vamshi Maskuri <[email protected]>

fix lint
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 Aug 22, 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 Aug 22, 2024
@karmada-bot karmada-bot merged commit 7563904 into karmada-io:master Aug 22, 2024
12 checks passed
@RainbowMango RainbowMango added this to the v1.11 milestone Aug 31, 2024
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/flake Categorizes issue or PR as related to a flaky test. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants