facebook / facebook-java-business-sdk

Java SDK for Meta Marketing APIs
https://developers.facebook.com/docs/business-sdk
Other
402 stars 332 forks source link

Fix flaky tests in `SignalTest.EventRequestTest` and `ServerSideTest.CustomDataParametersTest` #360

Open sliu-UIUC opened 3 years ago

sliu-UIUC commented 3 years ago

The flakiness comes from the fact that a hashmap data structure is being serialized into a Json object, but the elements in the original hashmap is not deterministic. Thus, we you compare two serialized Json string with each other, although they might contain the same elements, the order can be different during different test runs.

For checking whether the serialized string does contain all key value pairs, instead it can be done through checking each {key, value} pair directly and assert that each individual exists in the serialized string. Since the keys are unique in the hash map, it should be guaranteed that this way it is correctly checking the two compared objects have the same key value pairs.

One thing to note is that Gson.toJson can also have indeterministic ordering when the object being json serialized is a list type. Thus currently, Assert.assertTrue(serializedPayload.contains(serializedContents)) and other assertions involving serialized string type objects might be flaky as well. Further examination is needed to address this potential problem.