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
scheduler/internal: Improving cache and heap test coverage #114273
scheduler/internal: Improving cache and heap test coverage #114273
Conversation
Please note that we're already in Test Freeze for the Fast forwards are scheduled to happen every 6 hours, whereas the most recent run was: Sat Dec 3 09:45:01 UTC 2022. |
@TommyStarK: 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/test-infra repository. |
Hi @TommyStarK. 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/test-infra repository. |
I know guys you are super busy and this PR is far from being a priority. As a very new aspiring contributor I am still trying to become familiar with the code and to start helping on small pieces. Hope you don't mind. Any feedback will be greatly appreciated 😅. Best regards, |
Thanks @TommyStarK |
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.
Nice improvement on the test coverage!
roughly, this PR looks to me!
}) | ||
} | ||
|
||
// should trigger an error log as there is no node info for this given name |
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.
could this be verified? or else what's the point to leave these in the testcases?
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 think so. You are right there is no point to keep that.
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.
Resolved in 1c12a991112
@@ -1854,6 +1860,106 @@ func TestSchedulerCache_updateNodeInfoSnapshotList(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestSchedulerCache_ErrorCases(t *testing.T) { |
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.
Alternatively, you can test this in the related function instead of pull the false cases out and test it here, e.g "forget unknown pod" can go to "TestForgetPod". It might be better to org these testcases, but I am fine with this as well.
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 was my first intent but once my code added I felt like messing up with the existing scenarii so I change my mind and gathered all false cases into this function. I'd rather keep it this way but if you don't feel comfortable with that please tell me and I'll go back with the 1st approach :)
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.
+1, this is hard to maintain in the future. I didn't see any precedents in kubernetes. Let's try to make the tests pure.
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.
Sure thing. I will come back to move those tests to their related function.
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.
@chendave, @kerthcet, I tried to keep tests as pure as possible and avoid messing too much with their clarity. This is what I ended with 807b29ad6e9120cbca49ae864b74a4f8ae003f36.
Below the new unit tests code coverage for the pkg/scheduler/internal/cache
.
All pipelines have passed, remaining at your disposal if you have any remark :)
Best regards,
@@ -97,12 +141,17 @@ func TestHeap_Add(t *testing.T) { | |||
// TestHeap_Delete tests Heap.Delete and ensures that heap invariant is | |||
// preserved after deleting items. | |||
func TestHeap_Delete(t *testing.T) { | |||
h := New(testHeapObjectKeyFunc, compareInts) | |||
h := NewWithRecorder(testHeapObjectKeyFunc, compareInts, new(testMetricRecorder)) // cover conditions on metric recorder |
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.
Do you want to add some statements to cover the metric inc/dec?
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.
Resolved in 1c12a991112
this looks good to me now, pls remember to squash or org your commits properly. /lgtm /assign @Huang-Wei (per the suggestion from bot) |
@kerthcet I applied changes to address your latest comments. Hope it matches to your expectations :) Remaining at your disposal. Best, |
pkg/scheduler/internal/heap/heap.go
Outdated
@@ -158,6 +164,14 @@ func (h *Heap) Update(obj interface{}) error { | |||
return h.Add(obj) | |||
} | |||
|
|||
// Cleanup removes all items. | |||
func (h *Heap) Cleanup() { |
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.
Why are you adding this function?
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.
Sorry I misunderstood the comment of the last review. Removed.
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 called by UnschedulablePods
. Just remove this function if it's not needed.
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.
Got it. I removed it. sorry
59bc26f
to
5db1983
Compare
/retest-required |
if info == nil { | ||
t.Error("node infos should not be nil") | ||
} | ||
if test.expectedNodesInfos[i] != info.String() { |
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.
/approve cancel
don't compare strings.
Compare the objects and use cmp.Diff
to be able to tell the differences.
/cancel-approve |
Once comments are addressed, I'll wait for another pass from @kerthcet |
General question, why are we pushing back on testify? it seems more natural than cmp in some places? |
5db1983
to
a1a4b2b
Compare
@alculquicondor I updated my PR to address your comments. Had issues using |
Mostly for consistency and because |
I am not sure if we want to be that strict, I liked how simple the code was with testify. |
As discussed offline with Aldo, assertions are not generally preferred, which I agree with. My concern with cmp is that it sometimes bloats the test code (comparing to the exact same error); but if we can use cmp with options to avoid that, then that is great. |
/retest-required |
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.
/approve
Thanks
I will leave the lgtm to @kerthcet
nodes: []*v1.Node{ | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{Name: "node-0"}, | ||
Status: v1.NodeStatus{}, |
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.
this line is unnecessary, same below
{ | ||
Pod: podWithPort, | ||
}, |
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.
nit:
{ | |
Pod: podWithPort, | |
}, | |
{ Pod: podWithPort }, |
} | ||
} | ||
|
||
if !sets.String.Equal(test.expectedUsedPVCSet, snapshot.usedPVCSet) { |
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.
nit: cmp.Diff
can make it easier to spot the differences.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahg-g, alculquicondor, TommyStarK 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 |
} | ||
} | ||
|
||
if !sets.String.Equal(test.expectedUsedPVCSet, snapshot.usedPVCSet) { |
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 use cmp here as well
|
||
for i, node := range test.nodes { | ||
info, err := snapshot.Get(node.Name) | ||
if err != nil { |
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.
Every err != nil
is now replaced with three lines, similar with info == nil
below. Do we have a package to do those checks in a single line?
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 this is the case please tell me and I will update the 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.
Also not sure about this package. LGTM it's easy to read.
Signed-off-by: TommyStarK <thomasmilox@gmail.com>
a1a4b2b
to
94a29ef
Compare
Thank you very much @alculquicondor @ahg-g for your time and review. I updated the code according your suggestions. |
/lgtm |
Signed-off-by: TommyStarK thomasmilox@gmail.com
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
If applied this commit will increase the unit tests code coverage of
pkg/scheduler/internal/cache
andpkg/scheduler/internal/heap
.Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: