Fix flaky test UtilTest.testEnhanceResponseWithShippingAddressList#21
Open
Sujishark wants to merge 1 commit intoamzn:masterfrom
Open
Fix flaky test UtilTest.testEnhanceResponseWithShippingAddressList#21Sujishark wants to merge 1 commit intoamzn:masterfrom
Sujishark wants to merge 1 commit intoamzn:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 of changes:
This PR aims to fix a test:
This was found by using the NonDex tool.
REASON AND FIX
Encountered the following error while using NonDex:
The tests fails when the function
testEnhanceResponseWithShippingAddressList()compares both strings (expectedCheckoutSessionResponse.RawResponse and actualCheckoutSessionResponseAfterEnhancing.RawResponse) with key-value pairs in it.The JSON object is unordered since it uses Maps as their internal data structure. According to documentation,
"This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time."
Due to this a non-deterministic order of key-value pairs are maintained and hence the assertEquals fails.
amazon-pay-api-sdk-java/tst/com/amazon/pay/api/UtilTest.java
Line 257 in 3ff564e
One possible solution is to have those strings as JSONObjects and compare using JSONObject.similar(), which compares if the contents of two JSON objects are same, perhaps having a different order of attributes.
Reproduce:
This was found by using the NonDex tool.
The following command can be used to replicate the failures and validate the fix:
Environment:
No user-facing change.
No dependency upgrade.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.