Skip to content
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

Fixed test failure(test4) by comparing maps instead of json. #447

Open
wants to merge 1 commit into
base: v2.1.3
Choose a base branch
from

Conversation

RugvedB
Copy link

@RugvedB RugvedB commented Nov 28, 2023

Created this PR to fix 1 flaky test - test4


  1. How were these test identified as flaky?
    This test was identified as flaky by using an open-source research tool named NonDex which is responsible for finding and diagnosing non-deterministic runtime exceptions in Java programs.

  2. What was the error?
    When the test convert childBean to json string String json = JsonKit.toString(childBean);, the order of keys (i.e. repeatField, childField, superField) is not guaranteed. Thus, when we compare this String variable 'json' directly to hardcoded string "{\"repeatField\":\"sss\",\"childField\":\"child\",\"superField\":\"super\"}", it may fail sometimes because the order could be different than the expected order i.e repeatField, childField, superField.

Error:

[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.024 s <<< FAILURE! -- in com.hellokaton.blade.kit.JsonKitTest
[ERROR] com.hellokaton.blade.kit.JsonKitTest.test4 -- Time elapsed: 0.022 s <<< FAILURE!
org.junit.ComparisonFailure: expected:<{"[repeatField":"sss","childField":"child]","superField":"supe...> but was:<{"[childField":"child","repeatField":"sss]","superField":"supe...>
  1. What is the fix?
    Instead of comparing json strings, we can convert json to Map and then compare the maps. This PR proposes to compare Maps instead of json strings in test4.

You can run the following commands to run test4 using NonDex tool:

mvn -pl blade-kit edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=com.hellokaton.blade.kit.JsonKitTest#test4

Test Environment:

java version 11.0.19
Apache Maven 3.9.5

Kindly let me know if this fix is acceptable.
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants