mumbler6 opened a new pull request, #4633:
URL: https://github.com/apache/servicecomb-java-chassis/pull/4633

   Hello, I apologize for not creating and linking a JIRA issue for this PR 
yet, though I did request for a JIRA account on the self-serve page if needed. 
This PR is fairly trivial though and does not change much code. 
   
   ### Purpose of this PR
   This PR fixes the flaky tests:
   * 
[`org.apache.servicecomb.core.exception.ExceptionsTest.should_convert_unknown_client_exception_to_invocation_exception`](https://github.com/apache/servicecomb-java-chassis/blob/fc7c01668fbb992e015458a86bc4366a00dc5878/core/src/test/java/org/apache/servicecomb/core/exception/ExceptionsTest.java#L46)
   * 
[`org.apache.servicecomb.core.exception.ExceptionsTest.should_convert_unknown_server_exception_to_invocation_exception`](https://github.com/apache/servicecomb-java-chassis/blob/fc7c01668fbb992e015458a86bc4366a00dc5878/core/src/test/java/org/apache/servicecomb/core/exception/ExceptionsTest.java#L59)
   
   The mentioned tests may non-deterministically pass or fail without changes 
made to the source code when it is run in different JVMs due to the inherent 
unordered nature of JSON properties in the JSON strings during comparison. The 
tests expect: 
   
   * `"{\"code\":\"SCB.00000000\",\"message\":\"Unexpected exception when 
processing none. msg\"}"`
   * `"{\"code\":\"SCB.50000000\",\"message\":\"Unexpected exception when 
processing none. msg\"}"`
   
   But `Json.encode(invocationException.getErrorData())` will sometimes return: 
   
   * "{\"message\":\"Unexpected exception when processing none. 
msg\",\"code\":\"SCB.00000000\"}"
   * "{\"message\":\"Unexpected exception when processing none. 
msg\",\"code\":\"SCB.50000000\"}"
   
   ### Steps to Reproduce
   
   This change was confirmed by running the 
[NonDex](https://github.com/TestingResearchIllinois/NonDex) tool, which 
explores and reports errors in different behaviors of under-determined Java 
APIs.
   ```
   # Compile the module in project directory
   mvn clean install -pl core -am -DskipTests
   
   # Run the unit tests using NonDex
   mvn edu.illinois:nondex-maven-plugin:2.1.7:nondex -pl core 
-Dtest=org.apache.servicecomb.core.exception.ExceptionsTest#should_convert_unknown_client_exception_to_invocation_exception
 \
   mvn edu.illinois:nondex-maven-plugin:2.1.7:nondex -pl core 
-Dtest=org.apache.servicecomb.core.exception.ExceptionsTest#should_convert_unknown_server_exception_to_invocation_exception
   ```
   * Following the above steps for the mentioned tests will produce the 
following results for those runs, respectively:
   ```
   [INFO] Results:
   [INFO] 
   [ERROR] Failures: 
   [ERROR]   
ExceptionsTest.should_convert_unknown_server_exception_to_invocation_exception:68
 
   expected: "{"code":"SCB.50000000","message":"Unexpected exception when 
processing none. msg"}"
    but was: "{"message":"Unexpected exception when processing none. 
msg","code":"SCB.50000000"}"
   [INFO] 
   [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
   ```
   ```
   [INFO] Results:
   [INFO] 
   [ERROR] Failures: 
   [ERROR]   
ExceptionsTest.should_convert_unknown_client_exception_to_invocation_exception:55
 
   expected: "{"code":"SCB.00000000","message":"Unexpected exception when 
processing none. msg"}"
    but was: "{"message":"Unexpected exception when processing none. 
msg","code":"SCB.00000000"}"
   [INFO] 
   [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
   ```
   
   ### Fix
   * I propose to use an ObjectMapper to convert the JSON strings into JsonNode 
trees which can be compared for equality regardless of the order. 
   * After the fix, I was able to get both test cases to pass on NonDex: 
   
   
![image](https://github.com/user-attachments/assets/ebda66c0-7fa4-4bbe-bae5-267e34d26978)
   
   
   Please let me know if there are any changes you would like me to make. 
   
   
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to