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.
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 alist
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.