Skip to content

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

Merged
merged 16 commits into from
Feb 10, 2022

Conversation

kaiyaok2
Copy link
Contributor

@kaiyaok2 kaiyaok2 commented Feb 7, 2022

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 in DynamoDBEncryptor.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 in AttributeValueMarshallerTest.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.

@kaiyaok2 kaiyaok2 requested a review from a team as a code owner February 7, 2022 12:05
Copy link
Contributor

@lavaleri lavaleri left a 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.

@kaiyaok2
Copy link
Contributor Author

kaiyaok2 commented Feb 9, 2022

Hi there, thanks for your response! I've just addressed all requests.

@lavaleri lavaleri changed the title Fix some flaky tests fix: Account for indeterminate Map ordering in unit tests Feb 9, 2022
@kaiyaok2
Copy link
Contributor Author

Hi there, I just restored the original fix while addressing the style!

Copy link
Contributor

@josecorella josecorella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@lavaleri lavaleri left a 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 !

@lavaleri lavaleri merged commit c786e67 into aws:master Feb 10, 2022
seebees pushed a commit that referenced this pull request Dec 12, 2023
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.

3 participants