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

Fix nondeterministic test failure in DefaultFactoryTest #295

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Qi-Cui
Copy link

@Qi-Cui Qi-Cui commented Oct 8, 2024

Description

Test org.apache.gora.mongodb.filters.DefaultFactoryTest#testCreateFilter_list_2 occasionally fails when the order of fields in the JSONObject objects is different. The root cause is that current test compares the two JSONObject objects by converting them to strings, which is order-sensitive, and could fail when field order differs.

Steps to reproduce

I used Nondex to introduce randomness by run mvn -pl gora-mongodb edu.illinois:nondex-maven-plugin:2.1.7:nondex -Dtest=org.apache.gora.mongodb.filters.DefaultFactoryTest#testCreateFilter_list_2 .

Expected Behaviour

This test should pass consistently, regardless of the order of fields in the JSONObject, as long as the content remains the same.

Actual Behaviour

The test occasionally fails, raise an exception with error message:

DefaultFactoryTest.testCreateFilter_list_2:119 expected:<{"[h.C·T":"text/html","url":"http://www.example.com]"}> but was:<{"[url":"http://www.example.com","h.C·T":"text/html]"}>

Proposed Solution

The solution is to parse both expected and actual JSONObject into JsonNode, rather than comparing them as strings. Then use Jackson's ObjectMapper to compare the two JsonNode objects, which ignores the order of the keys.

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.

1 participant