Fixed Flaky Test: CustomDataParametersTest #440
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.
Fixed the flaky test CustomDataParametersTest inside src/test/java/com/facebook/ads/ServerSideTest class.
Root Cause
The test CustomDataParametersTest has been reported as flaky when ran with the NonDex tool. The test failed because it is trying to check if it contains a string or not which is actually nothing but a String Values of List, Hash Map. The HashMap/List in Java is implemented in such a way that it does not store the order in which the keys and/or values are inserted. As a result, when the expected string (which is hard-coded) is compared with the actual one, it failed.
Fix
The simplest fix is to check if all the patterns of expected String in actual String serialisedPayload. Since there were only two possible order changes, it was easy to hardcode the expected patterns and fix the flakiness.
How this has been tested?
Java: openjdk version "11.0.20.1"
Maven: Apache Maven 3.6.3
Module build: Successful
Command used: mvn install -am -DskipTests
Regular test: Successful
Command used: mvn test -Dtest=com.facebook.ads.ServerSideTest#CustomDataParametersTest
NonDex test: Failed
Command used:
mvn edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=com.facebook.ads.ServerSideTest#CustomDataParametersTest
NonDex test passed after the fix.
Let me know if you have any further questions