-
Notifications
You must be signed in to change notification settings - Fork 144
Fix test flakiness due to getDeclaredFields() without adding dependencies #681
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 some tests
This pull request introduces 1 alert when merging a5f2faa into 8aa7dbd - view on LGTM.com new alerts:
|
Hi there, I've resolved the alert in the comments. |
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.
Hi @kaiyaok2, thanks for submitting your contribution! I've just noticed an issue with the new method com.adyen.util.Util#jsonObjectStringToTreeMap
.
The format produced by it can only be used in the tests.
Hi @kaiyaok2, the Feel free to change the test code of the library. |
Hi there, thanks for your message! I updated a commit to remove possible exceptions by using Gson instead, and hopefully this will not break the API. Other 44 of the 45 flaky tests can be done solely with modifications to test files only. However, for base64 comparison, I believe that the test flakiness cannot be resolved(without hardcoding) unless we force |
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.
Checkout this another idea to deal with the base64 encoded JSON strings. In test code we can tradeoff some performance in favor of determinism.
src/test/java/com/adyen/serializer/SaleToAcquirerDataSerializerTest.java
Outdated
Show resolved
Hide resolved
I just updated with a commit with all proposed changes done! Also, the other flaky tests in the repo are similar to ones in |
Nice! You can update those as well if you like. :) |
The latest commit updates all the other tests 👍 |
Hi @michaelpaul could you please check the newest version? |
Hi @AlexandrosMor @michaelpaul, What are the checks for coverage/coveralls? How can I ensure that these checks pass? |
Hi @kaiyaok2, the coveralls process runs unit tests with code coverage. I believe we need to make some adjustments for this check. If the tests are passing on your machine, then you don't have anything else to do. |
Got it, I had all tests passing on my machine. Thanks for clarifying! |
Description
45 flaky tests are found using Nondex when running commands, including all tests presented in the earlier PR #654. This PR now fixes all of them without introducing new plugins / dependencies.
The flaky tests can be found when running the following command:
mvn edu.illinois:nondex-maven-plugin:1.1.2:nondex -Dtest={test}
For example, replacing
{test}
byCheckoutTest
checks for all flaky tests inCheckoutTest.java
.All 45 flaky tests are related to JSON-format strings. 44 of them are representing JSONObject-likes and 1 of them is representing JSONArray-like. Direct comparisons between JSON-formatted strings may occasionally fail upon changes of environment (e.g. using future versions of Java), as element orders in JSONObjects/JSONArrays are not preserved. This issue is due to possible order permutation in the routine
getDeclaredFields()
.Proposed Fixes
Changes to specific test files fall into the following 3 categories:
assertJsonStringEquals()
instead. The function makes direct comparisons after parsing input strings with Gson'sJsonParser()
method, allowing permutation of element orders in JSONs.jsonRequest.contains(some_JSON_string)
, add all possible permutation patterns ofsome_JSON_string
SaleToAcquirerData
objects and then do a direct comparison.