zhouyinn opened a new pull request, #15137: URL: https://github.com/apache/druid/pull/15137
### What is the purpose of this PR - This PR fixes the error resulting from the flaky test ``org.apache.druid.java.util.emitter.core.EmitterTest`` - The mentioned test may fail or pass without changes made to the source code when it is run in different JVMs due to `Json`'s non-deterministic iteration order. ### Why the test fails The test `testBasicAuthenticationAndNewlineSeparating` fails due to the order of byte buffer data returned by the `org.asynchttpclient.Request` object is non-deterministic. This issue arises because asynchronous methods can process data in a different order from the order of reception ### Reproduce the test failure - Run the test with [NonDex maven plugin](https://github.com/TestingResearchIllinois/NonDex). The command to recreate the flaky test failures is: `mvn -pl org.apache.druid:druid-processing edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest="org.apache.druid.java.util.emitter.core.EmitterTest#testBasicAuthenticationAndNewlineSeparating"` - Fixing the flaky test now may prevent unreliable test results in future code changes. ### Expected results The test should run successfully when run with NonDex. Test failing before changes: > [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 4.573 s <<< FAILURE! -- in org.apache.druid.java.util.emitter.core.EmitterTest [ERROR] org.apache.druid.java.util.emitter.core.EmitterTest.testBasicAuthenticationAndNewlineSeparating -- Time elapsed: 4.561 s <<< FAILURE! java.lang.AssertionError at org.junit.Assert.fail(Assert.java:87) EXPECTED: {"metrics":{"value":1},"feed":"test"} {"metrics":{"value":2},"feed":"test"} BUT FOUND: {"feed":"test","metrics":{"value":1}} {"metrics":{"value":2},"feed":"test"} ### Fix - Instead of directly comparing strings that represent JSON objects, compare the equality of complete JSON trees by evaluating the equality of their corresponding root nodes. - Utilize [Jackson](https://github.com/FasterXML/jackson) to read the input JSON as a JsonNode and compare them. Even when the order of attributes in the input JSON variables differs, the `equals()` method will disregard the order and consider them as equal. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
