Skip to content

Remove usage of assertion libraries in pkg/scheduler tests #130710

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

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

Conversation

pjsharath28
Copy link
Contributor

What type of PR is this?

/kind cleanup
/sig scheduling

What this PR does / why we need it:

Removed the usage of assertion libraries as per the style guide

Which issue(s) this PR fixes:

Fixes #130407

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Mar 11, 2025
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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.

@k8s-ci-robot k8s-ci-robot added needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 11, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @pjsharath28. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pjsharath28
Once this PR has been reviewed and has the lgtm label, please assign alculquicondor, x13n for approval. For more information see the 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

@k8s-ci-robot k8s-ci-robot added sig/node Categorizes an issue or PR as relevant to SIG Node. sig/storage Categorizes an issue or PR as relevant to SIG Storage. wg/device-management Categorizes an issue or PR as relevant to WG Device Management. labels Mar 11, 2025
@haosdent
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 12, 2025
@haosdent
Copy link
Member

Actually, I feel using assert.InDelta looks more simple compared to the original code. But just my opinion

@k8s-ci-robot
Copy link
Contributor

@pjsharath28: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubernetes-unit 939d617 link true /test pull-kubernetes-unit

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@bart0sh bart0sh moved this from Triage to not-only-sig-node in SIG Node: code and documentation PRs Mar 19, 2025
Copy link
Member

@macsko macsko left a comment

Choose a reason for hiding this comment

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

Please rebase for the recent changes and replace require library calls as well

@@ -936,7 +936,9 @@ func TestPlugin(t *testing.T) {

result, status := testCtx.p.PreFilter(testCtx.ctx, testCtx.state, tc.pod)
t.Run("prefilter", func(t *testing.T) {
assert.Equal(t, tc.want.preFilterResult, result)
if diff := cmp.Diff(tc.want.preFilterResult, result); diff != "" {
t.Errorf("Mismatch in Prefilter (- expected, + actual):\n%s", diff)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
t.Errorf("Mismatch in Prefilter (- expected, + actual):\n%s", diff)
t.Errorf("Unexpected PreFilter result (-want,+got):\n%s", diff)

Copy link
Member

Choose a reason for hiding this comment

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

And change in other as well

Comment on lines +1056 to +1063
expectedErr := expected.status.AsError()
if expectedErr != nil {
if diff := cmp.Diff(expectedErr.Error(), actualErr.Error()); diff != "" {
t.Errorf("Mismatch in error strings (- expected, + actual):\n%s", diff)
}
} else {
t.Errorf("Expected no error, but got: %v", actualErr)
}
Copy link
Member

Choose a reason for hiding this comment

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

Use cmp.Equal to compare strings:

Suggested change
expectedErr := expected.status.AsError()
if expectedErr != nil {
if diff := cmp.Diff(expectedErr.Error(), actualErr.Error()); diff != "" {
t.Errorf("Mismatch in error strings (- expected, + actual):\n%s", diff)
}
} else {
t.Errorf("Expected no error, but got: %v", actualErr)
}
expectedErr := expected.status.AsError()
if !cmp.Equal(expectedErr.Error(), actualErr.Error()) {
t.Errorf("Expected status error: %s, got: %s", expectedErr, actualErr)
}

@@ -809,7 +812,9 @@ func TestVolumeBinding(t *testing.T) {
t.Logf("Verify: call Filter and check status")
for i, nodeInfo := range nodeInfos {
gotStatus := p.Filter(ctx, state, item.pod, nodeInfo)
assert.Equal(t, item.wantFilterStatus[i], gotStatus)
if diff := cmp.Diff(item.wantFilterStatus[i], gotStatus); diff != "" {
t.Errorf("Mismatch in wantFilterStatus[%d] (-want,+got):\n%s", i, diff)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
t.Errorf("Mismatch in wantFilterStatus[%d] (-want,+got):\n%s", i, diff)
t.Errorf("Unexpected Filter status for node %s (-want,+got):\n%s", nodeInfo.Node().Name, diff)

Comment on lines +216 to +222
actual := function(assertion.p)
delta := 0.1
expectedAsFloat := float64(assertion.expected)
actualAsFloat := float64(actual)
if (expectedAsFloat-actualAsFloat) > delta || (actualAsFloat-expectedAsFloat) > delta {
t.Errorf("Mismatch in values with delta threshold (%.2f): expected %.2f, actual %.2f", delta, expectedAsFloat, actualAsFloat)
}
Copy link
Member

Choose a reason for hiding this comment

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

Checking delta in this test doesn't make sense at all. We have two ints, so if they are equal the test will pass, but it they are not, it will always fail. It could be just an equality check here:

Suggested change
actual := function(assertion.p)
delta := 0.1
expectedAsFloat := float64(assertion.expected)
actualAsFloat := float64(actual)
if (expectedAsFloat-actualAsFloat) > delta || (actualAsFloat-expectedAsFloat) > delta {
t.Errorf("Mismatch in values with delta threshold (%.2f): expected %.2f, actual %.2f", delta, expectedAsFloat, actualAsFloat)
}
if actual := function(assertion.p); actual != assertion.expected {
t.Errorf(...)
}

Comment on lines +45 to +48
if !cmp.Equal(c, nil) {
t.Errorf("Expected nil, but got: %+v", c)
}

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 like the nil check is redundant, you could use underscore above:

var _ frameworkContract = f

Code won't compile if the contract is not satisfied

Copy link
Member

Choose a reason for hiding this comment

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

Probably these two lines could be moved outside of the function, as package variables

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 25, 2025
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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.

@dims dims added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jul 12, 2025
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle rotten
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Aug 11, 2025
@macsko
Copy link
Member

macsko commented Aug 11, 2025

/remove-lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. sig/storage Categorizes an issue or PR as relevant to SIG Storage. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. wg/device-management Categorizes an issue or PR as relevant to WG Device Management.
Projects
Archived in project
Status: other-sig (sig-node-approved)
Development

Successfully merging this pull request may close these issues.

Remove usage of assertion libraries in pkg/scheduler tests
6 participants