-
Notifications
You must be signed in to change notification settings - Fork 71
fix: Account for indeterminate Map ordering in unit tests #274
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
Conversation
Fixed All Flaky Tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR! I agree it would be good to fix up these tests. I have a couple bits of feedback on the PR, and once those are addressed I'd be happy to merge this in.
Also, the CI is failing due to formatting checks. You can run mvn com.coveo:fmt-maven-plugin:format
to auto format your changes so that it meets our formatting requirements.
...st/java/com/amazonaws/services/dynamodbv2/datamodeling/encryption/DynamoDBEncryptorTest.java
Show resolved
Hide resolved
...va/com/amazonaws/services/dynamodbv2/datamodeling/internal/AttributeValueMarshallerTest.java
Outdated
Show resolved
Hide resolved
Hi there, thanks for your response! I've just addressed all requests. |
Hi there, I just restored the original fix while addressing the style! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thank you for your contribution @kaiyaok2 !
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.