-
Notifications
You must be signed in to change notification settings - Fork 471
Fix non deterministic for LoadPlanTest.testJson() #5961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
LoadPlanTest#testJson NonDex-safe by comparing JSON structures instead of raw stringsLoadPlanTest.testJson()
LoadPlanTest.testJson()|
@annhchen89 - Are #5961 and #5962 the only issues you found using NonDex in the Accumulo codebase? I looked at the NonDex Maven plugin details to see if it would fail the build if the plugin found any violations. I didn't find mention of failing the build, do you know if it will? |
dlmarion
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If LoadPlan implemented equals(), then we could use that to deserialize the json and compare the original and deserialized objects. It doesn't currently do that, so this is sufficient for now.
kevinrr888
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these changes and the changes in any other PR related to violations from NonDex be put into a single PR?
I closed #5948 due to inactivity and it being in an unmergable state (see #5948 (comment)), but could include those changes in the new/updated singular PR.
|
@kevinrr888 - I was reviewing your #5948 (comment) and while I agree with your comment that the JSON is valid, I think the issue is that we are comparing JSON as Strings in the test code and the gson code for serialization order is non-deterministic unless you tell it what the order should be. I think the better solution is to not compare Strings in the test, but deserialize the json back to an object and do object comparison. I'm thinking we should add NonDex to the build to identify these occurrences so we can fix them to do object comparison. Thoughts? |
|
@dlmarion The issue is that the build fails with NonDex with something like: at line 4. In this test, we are not comparing Strings but JsonNode objects which can be compared directly. |
Line 4 fails because Edit: NonDex is pointing out that Gson serializes in non-deterministic order by default. So if we are comparing json strings in our test where one String is serialized using gson, then it could fail at a future point. I think the suggestion of using Jackson to perform the test as we are using a different json serialization framework in the test vs what we are using at runtime. I think the solution is to not compare json strings in the tests. Use Gson to deserialize the string back to an object and use |
But order does not matter when comparing LinkedHashMap... I certainly agree that we shouldn't be comparing JSON strings, but I am just pointing out that NonDex might not be the way to go about enforcing this in our build due to the above issue |
Dismissing my approval. This fix gets the NonDex build plugin to pass, but I don't think using Jackson to test Gson serialized output is the right solution.
|
More context: Does NOT actually fail the build, but the exact example (from #5948) does fail the build... I was trying to give a simple failure example but ended up removing the failure. |
|
The NonDex plugin doesn't work on a full build, so we can't add it to the build. I'm going to put up a different PR to resolve the issue in LoadPlanTest |
|
Closing in favor of #6008 |
Related to #5961 Co-authored-by: Keith Turner <kturner@apache.org>
What does this PR do?
This PR is fixing a nondeterministic test failure in
LoadPlanTest.testJson()when running with Nondex.Problem
Previously, the test used:
This approach directly compared JSON strings. However, JSON object field order is nondeterministic, and NonDex randomizes iteration orders.
As a result, the test failed when field order in the generated JSON differed from the expected literal string, even though both represented the same structure.
Reproduce Test
Run:
The Fix
Instead of comparing JSON strings directly, the test now parses both expected and actual JSON into
JsonNodeobjects and asserts structural equality. This ensures the comparison is order-independent and validates actual JSON semantics, not textual layout.