Skip to content

Conversation

@pengyuejiang
Copy link

The Problem

The test com.ibm.cloud.is.vpc.v1.model.InstanceTemplatePrototypeInstanceByVolumeTest.testInstanceTemplatePrototypeInstanceByVolume is flaky as was discovered through the plug-in NonDex. The test com.ibm.cloud.is.vpc.v1.model.InstanceTemplatePrototypeInstanceByVolumeTest.testInstanceTemplatePrototypeInstanceBnyVolume can fail because it compares two JSON strings whose key order can differ. Here are the full steps to reproduce the issue:

git clone https://github.com/IBM/vpc-java-sdk && cd vpc-java-sdk
export JAVA_HOME=$(/usr/libexec/java_home -v1.8)
mvn clean install -pl modules/vpc -am -DskipTests
mvn edu.illinois:nondex-maven-plugin:1.1.2:nondex -pl modules/vpc -Dtest=InstanceTemplatePrototypeInstanceByVolumeTest#testInstanceTemplatePrototypeInstanceByVolume

The build will fail.

The current implementation compares two serializations with each other. However, it would be safer to directly compare the objects themselves to avoid any issues where serialization strings are different but representing the same object. NonDex shuffles the ordering of fields, so the test will fail without having any real issues.

The Fix

It's a very simple fix, instead of comparing serializations, JsonParser from GSON is used to compare their deserialized forms to make sure that the test will not fail because a field in the serialization string is in a different ordering from another that is constructed from the same object.

There are a few other tests in the project that have similar issues, which can also be discovered through running NonDex for the whole project. Please do give some feedbacks on whether you think this way of fixing it is feasible. Thanks!

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