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 tests for pkg/servicenameresolutiondetector #5408

Conversation

anujagrawal699
Copy link
Contributor

Description:
This PR introduces tests for servicenameresolutiondetector package covering all the modules in each directory of it.

Additions:*

  1. pkg/servicenameresolutiondetector/coredns/detector_test.go
  2. pkg/servicenameresolutiondetector/store/condition_cache_test.go
  3. pkg/servicenameresolutiondetector/store/node_store_test.go

Test Coverage:
The servicenameresolutiondetector package had a test coverage of 0.00%. The PR enhances its overall test coverage to more than 80%. The test coverage of pkg/servicenameresolutiondetector/coredns is enhanced to 74.3% and of pkg/servicenameresolutiondetector/store to 90.3%. This can be verified using go test ./... -coverprofile=coverage.out in the pkg/servicenameresolutiondetector directory.

What type of PR is this?
/kind failing-test
/kind feature

What this PR does / why we need it:
This PR adds comprehensive tests to the servicenameresolutiondetector package, improving the overall test coverage and ensuring the reliability and maintainability of the codebase.

Which issue(s) this PR fixes:
Fixes a part of #5235

Does this PR introduce a user-facing change?:

NONE

@karmada-bot karmada-bot added the kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. label Aug 20, 2024
@karmada-bot karmada-bot added kind/feature Categorizes issue or PR as related to a new feature. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Aug 20, 2024
@codecov-commenter
Copy link

codecov-commenter commented Aug 20, 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 30.59%. Comparing base (6318541) to head (147ede0).
Report is 180 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    #5408      +/-   ##
==========================================
+ Coverage   29.67%   30.59%   +0.91%     
==========================================
  Files         632      632              
  Lines       43936    43936              
==========================================
+ Hits        13037    13441     +404     
+ Misses      29954    29518     -436     
- Partials      945      977      +32     
Flag Coverage Δ
unittests 30.59% <ø> (+0.91%) ⬆️

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.

@anujagrawal699 anujagrawal699 force-pushed the addedTests-pkg/servicenameresolutiondetector branch 2 times, most recently from 8a2571a to 3111a59 Compare August 21, 2024 05:59
@zhzhuang-zju
Copy link
Contributor

/assign

@anujagrawal699
Copy link
Contributor Author

@XiShanYongYe-Chang Please take a look.

for _, status := range tt.expectedStatus {
if condition.Status == status {
validStatus = true
break
Copy link
Contributor

Choose a reason for hiding this comment

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

We can add a check: when condition.Status = metav1.ConditionFalse, check whether condition.Reason = serviceDomainNameResolutionFailed.

name string
alarm bool
expectedStatus metav1.ConditionStatus
expectedReason string
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
expectedReason string
expectedReason string
expectedMessage string

Comment on lines 126 to 127
case "ListAll":
result, opErr = store.ListAll()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
case "ListAll":
result, opErr = store.ListAll()

expectedError bool
}{
{
name: "Load existing node condition",
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a case where the node exists, but the conditionType of the node does not match the store.

},
},
expectedResult: []metav1.Condition{
{Type: string(corev1.NodeReady), Status: metav1.ConditionTrue},
Copy link
Contributor

Choose a reason for hiding this comment

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

listAll function does not guarantee that the returned result will maintain the same order as the input nodes, which can lead to intermittent test failures.

=== RUN   TestNodeStore_ListAll/List_with_not_ready_and_stale_nodes
    node_store_test.go:249: 
                Error Trace:    /root/home/workspace/code/karmada/pkg/servicenameresolutiondetector/store/node_store_test.go:249
                Error:          Not equal: 
                                expected: "True"
                                actual  : "Unknown"
                            
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -1,2 +1,2 @@
                                -(v1.ConditionStatus) (len=4) "True"
                                +(v1.ConditionStatus) (len=7) "Unknown"
                                 
                Test:           TestNodeStore_ListAll/List_with_not_ready_and_stale_nodes
    node_store_test.go:249: 
                Error Trace:    /root/home/workspace/code/karmada/pkg/servicenameresolutiondetector/store/node_store_test.go:249
                Error:          Not equal: 
                                expected: "Unknown"
                                actual  : "True"
                            
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -1,2 +1,2 @@
                                -(v1.ConditionStatus) (len=7) "Unknown"
                                +(v1.ConditionStatus) (len=4) "True"
                                 
                Test:           TestNodeStore_ListAll/List_with_not_ready_and_stale_nodes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can sort the results before comparing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like you are converting the result array into a map to avoid ordering issues, which makes sense to me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we move ahead with it?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, please go ahead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zhzhuang-zju can you trigger a retest?

@anujagrawal699 anujagrawal699 force-pushed the addedTests-pkg/servicenameresolutiondetector branch from 3111a59 to dd5ba22 Compare August 22, 2024 17:22
@karmada-bot karmada-bot added the do-not-merge/contains-merge-commits Indicates a PR which contains merge commits. label Aug 22, 2024
@anujagrawal699 anujagrawal699 force-pushed the addedTests-pkg/servicenameresolutiondetector branch from dd5ba22 to ef6fa6b Compare August 22, 2024 17:25
@karmada-bot karmada-bot removed the do-not-merge/contains-merge-commits Indicates a PR which contains merge commits. label Aug 22, 2024
@anujagrawal699 anujagrawal699 force-pushed the addedTests-pkg/servicenameresolutiondetector branch from ef6fa6b to 7ba7812 Compare August 22, 2024 17:30
@anujagrawal699
Copy link
Contributor Author

@zhzhuang-zju @XiShanYongYe-Chang PTAL

@XiShanYongYe-Chang
Copy link
Member

Hi @anujagrawal699, can you help squash the commits into one?

@anujagrawal699
Copy link
Contributor Author

anujagrawal699 commented Aug 23, 2024

Hi @anujagrawal699, can you help squash the commits into one?

Hey @XiShanYongYe-Chang can you check if the current TestNodeStore_ListAll function is correct as mentioned by @zhzhuang-zju in the review. I'll squash commit after making the necessary changes.

Signed-off-by: Anuj Agrawal <[email protected]>

Added tests for pkg/servicenameresolutiondetector

Signed-off-by: Anuj Agrawal <[email protected]>

Added tests for pkg/servicenameresolutiondetector

Signed-off-by: Anuj Agrawal <[email protected]>

Added tests for pkg/servicenameresolutiondetector

Signed-off-by: Anuj Agrawal <[email protected]>
@anujagrawal699 anujagrawal699 force-pushed the addedTests-pkg/servicenameresolutiondetector branch from 00dc3d6 to 147ede0 Compare August 23, 2024 04:54
@zhzhuang-zju
Copy link
Contributor

/retest

}
}

func TestSetNodeStatusCondition(t *testing.T) {

Choose a reason for hiding this comment

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

Hey @anujagrawal699 , do we have tested FindNodeStatusCondition function explicitly ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, we haven't. The size of PR was going big as you see (1000+ lines) and i though of another pr on pkg/servicenameresolutiondetector after i complete pending tests on another packages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yashpandey06 But still the FindNodeStatusCondition function is being indirectly tested within the TestNodeStore function.

Choose a reason for hiding this comment

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

If it's indirectly tested , that would suffice the need for now 😃

@XiShanYongYe-Chang
Copy link
Member

/assign

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~
/lgtm
/approve

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 24, 2024
@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 Aug 24, 2024
@karmada-bot karmada-bot merged commit aee21b8 into karmada-io:master Aug 24, 2024
12 checks passed
@RainbowMango RainbowMango added this to the v1.11 milestone Aug 31, 2024
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/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants