Fix JSON string comparision for tests #8183
Merged
yadvr merged 1 commit intoapache:mainfrom Nov 3, 2023
Merged
Conversation
Codecov Report
@@ Coverage Diff @@
## main #8183 +/- ##
============================================
+ Coverage 22.00% 29.16% +7.15%
- Complexity 21855 30984 +9129
============================================
Files 5047 5181 +134
Lines 343240 365208 +21968
Branches 49449 53420 +3971
============================================
+ Hits 75527 106509 +30982
+ Misses 256710 244106 -12604
- Partials 11003 14593 +3590
Flags with carried forward coverage won't be shown. Click here to find out more. see 1383 files with indirect coverage changes 📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today! |
yadvr
approved these changes
Nov 3, 2023
|
Awesome work, congrats on your first merged pull request! |
dhslove
pushed a commit
to ablecloud-team/ablestack-cloud
that referenced
this pull request
Nov 8, 2023
Dajeong-Park
added a commit
to Dajeong-Park/ablestack-cloud
that referenced
this pull request
Nov 16, 2023
This reverts commit d224a1d.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
The PR fixes the following test which could produce non-deterministic/flaky pass/fail result
com.cloud.server.StatsCollectorTest.java#persistVirtualMachineStatsTestPersistsSuccessfullySetup:
Java version: 11.0.20.1
Maven version: 3.8.8
Test failure reproduction:
The test
com.cloud.server.StatsCollectorTest.java#persistVirtualMachineStatsTestPersistsSuccessfullycompares two JSON Strings and asserts if they are equal. However, the order of key value pairs is not guaranteed in a JSON string. Hence the test can fail. This issue was verified using the NonDex plugin.Steps:
Root cause and Fix
Test Failure in Nondex Mode
The following error occurs when comparing two json strings in this line. The expected string is a hardcoded json string. The actual string is obtained by converting the class attributes to JSON(using the Gson library) here. The comparision fails in some cases since the key orderings between the JSON data could be different.
Fix
The Fix converts both the JSON strings to TreeMaps(which maintain key order) and compares these for equality. This makes the test more stable without losing out on effectiveness
Types of changes
Feature/Enhancement Scale or Bug Severity
This code modifies only test files and should not affect anything in production
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
mvn -pl server edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=com.cloud.server.StatsCollectorTest.java#persistVirtualMachineStatsTestPersistsSuccessfully)mvn -pl server test)How did you try to break this feature and the system with this change?
The change only creates a new test utility and calls it within a single test. Hence it should not affect any other code