Fixed Flaky test found in UserDataTest
#359
Open
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.
Specifically, the tests comes from this line
in test
test/java/com/facebook/ads/sdk/serverside/UserDataTest.java
, which is a flaky test thateither pass or fail occasionally on its own. The reason is that
externalIds
is declared earlier aswhich ensures
externalIds.subList(0, 2))
to always yield{"external-1", "external-2"}
and in thisorder. However, both
userData.externalIds
oruserData.setExternalIds
which setthe external ids field of user data utilize the
dedup
function defined insrc/main/java/com/facebook/ads/sdk/serverside/UserData.java
. Becausededup
utilizes a hash setdata structure, external id values are not necessarily having a fixed order each time the
function is called, so both
userData.externalIds
oruserData.setExternalIds
can eitherreturn
{"external-1", "external-2"}
or"{external-2", "external-1}"
during different runs.In the unit test, I stored the result of
userData.getExternalIds
in a list and sort the resultbefore hand, and the assertion should also yield true with the fix.