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.
Updated a flaky test case in Md5UtilTest to avoid making internal function calls thus making it not flaky.
Flaky test case: cn.hippo4j.common.toolkit.Md5UtilTest.assetGetTpContentMd5
hippo4j/infra/common/src/test/java/cn/hippo4j/common/toolkit/Md5UtilTest.java
Line 52 in 472d345
Problem
Test
assetGetTpContentMd5
inMd5UtilTest
is detected as flaky with the NonDex tool. The test failed with the following error:Root cause
In this test, an object of class ThreadPoolParameterInfo is created and Md5Util.getTpContentMd5() is called with this object. Then the result is compared with a hardcoded string "md5Result"(ef5ea7cb47377fb9fb85a7125e76715d) here
hippo4j/infra/common/src/test/java/cn/hippo4j/common/toolkit/Md5UtilTest.java
Line 58 in 472d345
During the execution, at one point here
hippo4j/infra/common/src/main/java/cn/hippo4j/common/toolkit/ContentUtil.java
Line 51 in 472d345
the object is converted to a JSON string using JSONUtil.toJSONString() which internally uses Jackson library ObjectMapper to convert the object to string. But, since the order of properties is not preserved, we get the JSON string with different order of properties each time and this is making this test flaky. Due to different JSON string values, final md5 string value is also different thus making this test flaky.
Fix
Ideally, a unit test should test the functionality of the method and not the functionalities of the methods called from inside this method. Therefore, we need to mock all the internal calls and test only the functionality of the method. I mocked ContentUtil class (static class) and tested only the Md5Util functionality. This way, the problem mentioned in the above root cause section is avoided and this test doesn't become flaky anymore.
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.