Skip to content

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