-
Notifications
You must be signed in to change notification settings - Fork 994
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
Fix flaky test in CollectUtilTest #1371
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tomsun28
added
enhancement
New feature or request
good first pull request
Good for newcomers
bugfix
labels
Dec 2, 2023
tomsun28
approved these changes
Dec 2, 2023
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.
👍👍 LGTM!
👍👍 @all-contributors please add @bbelide2 for code |
I've put up a pull request to add @bbelide2! 🎉 |
tomsun28
pushed a commit
that referenced
this pull request
Jan 16, 2024
Co-authored-by: balasukesh <bbelide2@fa23-cs527-002.cs.illinois.edu>
tomsun28
pushed a commit
that referenced
this pull request
Mar 9, 2024
Co-authored-by: balasukesh <bbelide2@fa23-cs527-002.cs.illinois.edu>
tomsun28
pushed a commit
that referenced
this pull request
Mar 9, 2024
Co-authored-by: balasukesh <bbelide2@fa23-cs527-002.cs.illinois.edu>
tomsun28
pushed a commit
that referenced
this pull request
Mar 10, 2024
Co-authored-by: balasukesh <bbelide2@fa23-cs527-002.cs.illinois.edu>
tomsun28
pushed a commit
that referenced
this pull request
Mar 10, 2024
Co-authored-by: balasukesh <bbelide2@fa23-cs527-002.cs.illinois.edu>
tomsun28
pushed a commit
that referenced
this pull request
Mar 11, 2024
Co-authored-by: balasukesh <bbelide2@fa23-cs527-002.cs.illinois.edu>
tomsun28
pushed a commit
that referenced
this pull request
Mar 11, 2024
Co-authored-by: balasukesh <bbelide2@fa23-cs527-002.cs.illinois.edu>
tomsun28
pushed a commit
that referenced
this pull request
Mar 11, 2024
Co-authored-by: balasukesh <bbelide2@fa23-cs527-002.cs.illinois.edu>
tomsun28
pushed a commit
that referenced
this pull request
Mar 11, 2024
Co-authored-by: balasukesh <bbelide2@fa23-cs527-002.cs.illinois.edu>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's changed?
Use JSON_MAPPER.readTree() to compare two JSON strings instead of direct assertion to fix a flaky test
Flaky test case:
org.dromara.hertzbeat.collector.util.CollectUtilTest.replaceCryPlaceholder
https://github.com/dromara/hertzbeat/blob/ce75254b8ec18422c48c40fe61354135d08b200d/collector/src/test/java/org/dromara/hertzbeat/collector/util/CollectUtilTest.java#L82
Problem
Test
replaceCryPlaceholder
inCollectUtilTest
is detected as flaky with the NonDex tool. The test failed with the following error:Root cause
In this test, two JSON strings are compared using Assert.assertEquals() in this part of the code:
https://github.com/dromara/hertzbeat/blob/ce75254b8ec18422c48c40fe61354135d08b200d/collector/src/test/java/org/dromara/hertzbeat/collector/util/CollectUtilTest.java#L92
and
https://github.com/dromara/hertzbeat/blob/ce75254b8ec18422c48c40fe61354135d08b200d/collector/src/test/java/org/dromara/hertzbeat/collector/util/CollectUtilTest.java#L105
Using Assert.assertEquals() will lead to flaky tests due to mismatch in the order of properties or if there are nested structures. In this particular test case, there is a mismatch in the order of properties and therefore the assertion failed making the test flaky when tested with NonDex.
Fix
JSON_MAPPER.readTree() for each JSON string while making the assertion to make the assertion order insensitive.
This change will not impact the code in anyways since the change is only done for the unit test.
How this has been tested?
Java: openjdk version "11.0.20.1"
Maven: Apache Maven 3.6.3
Command used -
Command used -
Command used -
NonDex test passed after the fix.
Checklist