Describe the bug
The test file
common/
com.alibaba.nacos.common.utils.JacksonUtilsTest.
has flakiness in the test testToJsonBytes
Expected behavior
The assertion should be passed whatever the order of the JSON string is.
We use the NonDex. as a test tool and we expected it passed.
Actually behavior
Fails while using Nondex to run the test with the following error -
[ERROR] Failures:
[ERROR] JacksonUtilsTest.testToJsonBytes:460 expected:<{"code":0,"data":{"[string":"你好,中国!","integer":999]}}> but was:<{"code":0,"data":{"[integer":999,"string":"你好,中国!"]}}>
[INFO]
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
How to Reproduce
The flakiness was found with NonDex.
After installing NonDex and run the following code.
cd nacos
mvn install -pl common -am -DskipTests
mvn -pl common edu.illinois:nondex-maven-plugin:1.1.2:nondex -Dtest=com.alibaba.nacos.common.utils.JacksonUtilsTest#testToJsonBytes
Desktop (please complete the following information):
- OS: Windows
- Version: 10
- Maven Version: 3.8.1
- Nacos Module - common
- SDK: Original
3条答案
按热度按时间mcvgt66p1#
Can you provide a fix solution way?
gwo2fgha2#
Yes, the proposed solution is as follows: ( #9505 is my pull request for the same.)
There are two points where non-determinism is introduced. Proposed fixes are attached herewith.
Fix: Use a LinkedHashMap instead of a HashMap to guarantee the preservation of the order of insertion.
Fix: Annotate the class ResultSet with @JsonPropertyOrder(alphabetic = true) to ensure the order of properties while converting the object into JSON.
Can you please review the same and approve?
lymnna713#
The second way is un-reasonable, the problem is test case problem, so the solution should not change the original codes.