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

Added unit tests for the scheduler's node tree functionality #5772

Conversation

anujagrawal699
Copy link
Contributor

@anujagrawal699 anujagrawal699 commented Nov 2, 2024

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:

  1. pkg/util/lifted/scheduler/cache/node_tree_test.go

Test Coverage:

  1. pkg/util/lifted/scheduler/cache/node_tree_test.go : 0% to 98.2%

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?:

NONE

@karmada-bot karmada-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Nov 2, 2024
@karmada-bot karmada-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 2, 2024
@codecov-commenter
Copy link

codecov-commenter commented Nov 2, 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 47.95%. Comparing base (057cf86) to head (55707d8).
Report is 188 commits behind head on master.

❗ 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     
Flag Coverage Δ
unittests 47.95% <ø> (+5.64%) ⬆️

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.

@zhzhuang-zju
Copy link
Contributor

[CronFederatedHPA] CronFederatedHPA testing Scale FederatedHPA [It] Test scale FederatedHPA testing
https://github.com/karmada-io/karmada/actions/runs/11640040601/job/32417012568?pr=5772

/retest

Copy link
Contributor

@zhzhuang-zju zhzhuang-zju left a comment

Choose a reason for hiding this comment

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

thanks~ others LGTM

Comment on lines 393 to 423
// 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,
},
},
}
}
Copy link
Contributor

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

func makeNode(name string, res corev1.ResourceList) *corev1.Node {
return &corev1.Node{
ObjectMeta: metav1.ObjectMeta{Name: name},
Status: corev1.NodeStatus{
Capacity: res,
Allocatable: res,
},
}
}

pkg/util/lifted/scheduler/cache/node_tree_test.go Outdated Show resolved Hide resolved
@anujagrawal699 anujagrawal699 force-pushed the addedTests-pkg/util/lifted/scheduler/cache/node_tree_test.go branch from da08542 to 7c10a66 Compare December 5, 2024 17:19
@anujagrawal699
Copy link
Contributor Author

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)
Copy link
Contributor

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]>
@anujagrawal699 anujagrawal699 force-pushed the addedTests-pkg/util/lifted/scheduler/cache/node_tree_test.go branch from 7c10a66 to 55707d8 Compare December 6, 2024 10:23
@zhzhuang-zju
Copy link
Contributor

https://github.com/karmada-io/karmada/actions/runs/12197101877/job/34026335469?pr=5772#step:6:1770
Karmadactl top testing Karmadactl top pod which does not exist [It] Karmadactl top pod which does not exist

/retest

@zhzhuang-zju
Copy link
Contributor

/lgtm
thanks~
ask @XiShanYongYe-Chang for another look

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 7, 2024
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 a lot~
/approve

@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 Dec 7, 2024
@karmada-bot karmada-bot merged commit acce8fd into karmada-io:master Dec 7, 2024
18 checks passed
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/feature Categorizes issue or PR as related to a new feature. 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.

5 participants