-
Notifications
You must be signed in to change notification settings - Fork 918
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 unit tests for the scheduler's node tree functionality #5772
Added unit tests for the scheduler's node tree functionality #5772
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #5772 +/- ##
==========================================
+ Coverage 42.31% 47.95% +5.64%
==========================================
Files 655 663 +8
Lines 55756 54761 -995
==========================================
+ Hits 23591 26261 +2670
+ Misses 30651 26793 -3858
- Partials 1514 1707 +193
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
/retest |
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.
thanks~ others LGTM
// Helper function to create a test node | ||
func makeNode(name, region, zone string) *corev1.Node { | ||
return &corev1.Node{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: name, | ||
Labels: map[string]string{ | ||
corev1.LabelTopologyRegion: region, | ||
corev1.LabelTopologyZone: zone, | ||
}, | ||
}, | ||
} | ||
} |
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.
'makeNode' redeclared in this package
karmada/pkg/util/lifted/scheduler/cache/snapshot_test.go
Lines 386 to 394 in 93a68eb
func makeNode(name string, res corev1.ResourceList) *corev1.Node { | |
return &corev1.Node{ | |
ObjectMeta: metav1.ObjectMeta{Name: name}, | |
Status: corev1.NodeStatus{ | |
Capacity: res, | |
Allocatable: res, | |
}, | |
} | |
} |
da08542
to
7c10a66
Compare
Hi @zhzhuang-zju , please take a look! |
for _, node := range tt.nodes { | ||
count, exists := nodeCount[node.Name] | ||
assert.True(t, exists, "node %s should be in the list", node.Name) | ||
assert.Equal(t, 1, count, "node %s should appear exactly once", node.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.
The nodeTree
has no restriction that nodeName
cannot be duplicated, so determining whether count
is 1 may be a bit inappropriate.
How about directly determine if the result of nt.list()
is the expected slice? Like
func TestList(t *testing.T) {
tests := []struct {
name string
nodes []*corev1.Node
expectedList []string
}{
{
name: "multiple zones",
nodes: []*corev1.Node{
makeNodeWithTopology("node1", "us-east", "us-east-1a"),
makeNodeWithTopology("node2", "us-east", "us-east-1b"),
makeNodeWithTopology("node3", "us-east", "us-east-1a"),
makeNodeWithTopology("node4", "us-east", "us-east-1c"),
},
expectedList: []string{"node1", "node2", "node3", "node4"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
nt := newNodeTree(tt.nodes)
list, err := nt.list()
assert.NoError(t, err)
sort.Strings(tt.expectedList)
sort.Strings(list)
assert.Equal(t, tt.expectedList, list)
})
}
}
Signed-off-by: Anuj Agrawal <[email protected]> Added unit tests for the scheduler's node tree functionality Signed-off-by: Anuj Agrawal <[email protected]> Added unit tests for the scheduler's node tree functionality Signed-off-by: Anuj Agrawal <[email protected]>
7c10a66
to
55707d8
Compare
/retest |
/lgtm |
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.
Thanks a lot~
/approve
[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 |
Description:
This PR adds comprehensive unit tests for the scheduler's node tree functionality. These tests improve code coverage and ensure reliable behavior of a critical component that manages node organization by zones for efficient scheduling decisions.
Additions:
Test Coverage:
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?: