Fixed All Flaky Tests #1
Merged
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.
Description
2 flaky tests are found using Nondex when running commands
mvn edu.illinois:nondex-maven-plugin:1.1.2:nondex Dtest=DynamoDBEncryptorTest#ensureEncryptedAttributesUnmodified
and
mvn edu.illinois:nondex-maven-plugin:1.1.2:nondex -Dtest=AttributeValueMarshallerTest#testSimpleMapWithNull
The reason for test flakiness is that Java map API does not preserve the order of the key-value pairs. Comparing maps by casting to string can fail when, for example, the Java version upgrades in the future, or when the code is run in different environment.
Flaky Tests and Fixes
Test:
ensureEncryptedAttributesUnmodified
inDynamoDBEncryptor.java
.Reason & Fix: The test tries to compare two maps after casting them to strings. However, item orders in maps are not preserved. I converted the referenced maps to TreeMaps before casting them to string.
Test:
testSimpleMapWithNull
inAttributeValueMarshallerTest.java
Reason & Fix: Part of the expected string is a representation of a map. Similarly, order is not preserved in maps, hence I considered the 2 possible permutation patterns of the string representation of the map.