-
Notifications
You must be signed in to change notification settings - Fork 40.9k
remove assert/require lib from scheduler pkg #131145
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
base: master
Are you sure you want to change the base?
remove assert/require lib from scheduler pkg #131145
Conversation
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. 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. |
This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The 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. |
Welcome @mohitsethia! |
Hi @mohitsethia. 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 Once the patch is verified, the new status will be reflected by the 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. |
Can you follow the original author's comment? or You don't need to use a new pr, but can continue to complete the work directly on that pr. |
or you can use |
/hold |
Hi @googs1025 , I had forked the repo with only the master branch. So, it was not possible for me to use that branch. |
can you pull his branch down without recreating? |
Since this is already created, does it make sense to simply close that PR? And to pull his branch, I again have to clone his forked repo. I am sorry but I think this would only |
@mohitsethia
base on: Or you need to indicate the collaborators in your PR. like this: #131145 (comment) |
726b639
to
42be468
Compare
/test pull-kubernetes-e2e-gce |
@@ -1163,7 +1172,9 @@ func (tc *testContext) verify(t *testing.T, expected result, initialObjects []me | |||
func (tc *testContext) listAll(t *testing.T) (objects []metav1.Object) { | |||
t.Helper() | |||
claims, err := tc.client.ResourceV1beta1().ResourceClaims("").List(tc.ctx, metav1.ListOptions{}) | |||
require.NoError(t, err, "list claims") | |||
if err != nil { | |||
t.Errorf("unexpected error in list claims: %s", err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to call .Error()
if passing is as an argument to the t.Errorf
:
t.Errorf("unexpected error in list claims: %s", err.Error()) | |
t.Errorf("unexpected error in list claims: %s", err) |
if err != nil { | ||
t.Errorf("Unexpected error: %s", err.Error()) | ||
} | ||
if diff := cmp.Diff(tc.expectedHint, actualHint); diff != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using cmp.Diff
on an int value is probably too much and just an equality check could be enough.
} | ||
|
||
func verifyEmpty(t *testing.T, queue *FIFO[int]) { | ||
t.Helper() | ||
require.Equal(t, 0, queue.Len()) | ||
if !cmp.Equal(0, queue.Len()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For simple equality check it's not needed to use cmp.Equal
:
if !cmp.Equal(0, queue.Len()) { | |
if queue.Len() != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why I didn't receive any notifications for these comments. The comment totally makes sense, fixed all the comments now.
Hi , does any one know what seems to be the error in the e2e-gce test? Could it be a flaky test? |
Looks like a flaky test /retest |
/remove-sig instrumentation |
fea491c
to
b4bb6dc
Compare
@@ -99,19 +111,31 @@ func TestShrink(t *testing.T) { | |||
for i := 0; i < normalSize*2; i++ { | |||
queue.Push(i) | |||
} | |||
require.Equal(t, normalSize*2, queue.Len()) | |||
require.LessOrEqual(t, 2*normalSize, len(queue.elements)) | |||
if !cmp.Equal(normalSize*2, queue.Len()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if !cmp.Equal(normalSize*2, queue.Len()) { | |
if queue.Len() != normalSize*2 { |
if !cmp.Equal(normalSize*2, queue.Len()) { | ||
t.Errorf("Expected queue len as %d, actual len: %d", normalSize*2, queue.Len()) | ||
} | ||
if 2*normalSize > len(queue.elements) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flip the args:
if 2*normalSize > len(queue.elements) { | |
if len(queue.elements) < 2*normalSize { |
if queue.Len() != 0 { | ||
t.Errorf("Expected queue len as 0, actual len: %d", queue.Len()) | ||
} | ||
if !cmp.Equal(normalSize, len(queue.elements)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if !cmp.Equal(normalSize, len(queue.elements)) { | |
if len(queue.elements) != normalSize { |
if queue.Len() != 0 { | ||
t.Errorf("Expected queue len as 0, actual len: %d", queue.Len()) | ||
} | ||
if normalSize != len(queue.elements) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if normalSize != len(queue.elements) { | |
if len(queue.elements) != normalSize { |
if !cmp.Equal(expectedOk, ok) { | ||
t.Errorf("Expected queue.Pop() status: %t, actual status: %t", expectedOk, ok) | ||
} | ||
if !cmp.Equal(expectedValue, actual) { | ||
t.Errorf("Expected queue.Pop() value: %d, actual status: %d", expectedValue, actual) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if !cmp.Equal(expectedOk, ok) { | |
t.Errorf("Expected queue.Pop() status: %t, actual status: %t", expectedOk, ok) | |
} | |
if !cmp.Equal(expectedValue, actual) { | |
t.Errorf("Expected queue.Pop() value: %d, actual status: %d", expectedValue, actual) | |
} | |
if ok != expectedOk { | |
t.Errorf("Expected queue.Pop() status: %t, actual status: %t", expectedOk, ok) | |
} | |
if actual != expectedValue { | |
t.Errorf("Expected queue.Pop() value: %d, actual status: %d", expectedValue, actual) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall I resolve all the conversation? Or wait for the commentor to do it?
if expected.status == nil && status != nil { | ||
t.Errorf("Expected nil status but got: %+v", status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe keep the previous logic:
if expected.status == nil && status != nil { | |
t.Errorf("Expected nil status but got: %+v", status) | |
if expected.status == nil { | |
if status != nil { | |
t.Errorf("Expected nil status but got: %+v", status) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got a comment to simplify it 😅
b4bb6dc
to
6ad0083
Compare
/remove-area dependency |
6ad0083
to
09376ee
Compare
/test pull-kubernetes-unit |
Hi, can we merge the PR now, or is there anything that is blocking it for now? |
Hi @macsko, can you please help me letting know what is the next action to be taken for this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/remove-area kubeadm
/remove-sig cluster-lifecycle
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rebase and check if after rebasing no new assert/require usages appear.
@@ -1163,7 +1174,9 @@ func (tc *testContext) verify(t *testing.T, expected result, initialObjects []me | |||
func (tc *testContext) listAll(t *testing.T) (objects []metav1.Object) { | |||
t.Helper() | |||
claims, err := tc.client.ResourceV1beta1().ResourceClaims("").List(tc.ctx, metav1.ListOptions{}) | |||
require.NoError(t, err, "list claims") | |||
if err != nil { | |||
t.Errorf("unexpected error in list claims: %s", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to t.Fatalf
everywhere where require
was used
if err != nil { | ||
t.Errorf("Unexpected error in isSchedulableAfterPodDeleted: %s", err.Error()) | ||
} | ||
if diff := cmp.Diff(tc.expectedHint, actualHint); diff != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an integer. You could just do comparison (tc.expectedHint != actualHint). It would be good to print them in error message as strings (use %s).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And change it similarly for other plugins
require.NoError(t, err) | ||
require.Equal(t, tc.expectedHint, actualHint) | ||
if err != nil { | ||
t.Errorf("Unexpected error in isSchedulableAfterNodeChange: %s", err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can skip .Error()
here. Please change it in other places as well:
t.Errorf("Unexpected error in isSchedulableAfterNodeChange: %s", err.Error()) | |
t.Errorf("Unexpected error in isSchedulableAfterNodeChange: %s", err) |
t.Errorf("Expected queue.Pop() status: %t, actual status: %t", expectedOk, ok) | ||
} | ||
if actual != expectedValue { | ||
t.Errorf("Expected queue.Pop() value: %d, actual status: %d", expectedValue, actual) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t.Errorf("Expected queue.Pop() value: %d, actual status: %d", expectedValue, actual) | |
t.Errorf("Expected queue.Pop() value: %d, actual value: %d", expectedValue, actual) |
} | ||
|
||
func verifyEmpty(t *testing.T, queue *FIFO[int]) { | ||
t.Helper() | ||
require.Equal(t, 0, queue.Len()) | ||
if queue.Len() != 0 { | ||
t.Errorf("Expected empty queue, actual Len: %d", queue.Len()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t.Errorf("Expected empty queue, actual Len: %d", queue.Len()) | |
t.Errorf("Expected empty queue, actual len: %d", queue.Len()) |
What type of PR is this?
/sig scheduling
/kind cleanup
What this PR does / why we need it: According to the sig guidelines, we should use cmp.Equal or cmp.Diff instead of assert & require libraries
Which issue(s) this PR fixes: #130407
Fixes #130407
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: