Fix flaky test testValidJSONObject() #4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Overview
The PR proposes a fix for the following tests -
com.p2sdev.jsonToOrmMapper.AppTest#testValidJSONObject
Build Project
Problem
This flakiness was identified by the nondex tool created by the researchers of UIUC. The above eight tests fail when run on the nondex tool.
This test is failing because the order is not maintained in the assertion although it is the same JSON object.
jsonToOrmMapper/src/test/java/com/p2sdev/jsonToOrmMapper/AppTest.java
Lines 61 to 69 in b84ba5c
This problem of flakiness starts with the
JSONToConverter
method that creates the object and builds the fields inside it (called columns here). This is being done when a newDjangoModel
is being initialized and the function of the classbuildClass
is where the flakiness lies.jsonToOrmMapper/src/main/java/com/p2sdev/jsonToOrmMapper/mapper/orm/DjangoModel.java
Lines 82 to 89 in b84ba5c
Here, the
buildClass
function initializestableColumnsDef
which is a map, a map does not maintain order which causes the reordering of values and the consequent fail in the assertion.Fix:
The proposed fix is to use a TreeMap to maintain the order of insertion. A Treemap is used instead of a LinkedHashMap because to maintain the order of insertion of the nested elements and not only the base-level JSON elements.
Note: There is a change in the base test code, shifting the values of
l_name
andp_id
to match with the assertion since a TreeMap will maintain order