This repository was archived by the owner on Jun 6, 2025. It is now read-only.
Fixing three flaky tests in AuthorisationsTest and ViewTest #3327
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.
Two flaky tests were fixed in this pull request-
Flakiness in the tests -
To check for flakiness in the tests, a tool called nondex was used.
Steps to reproduce flakiness using nondex -
Test 1:
The third command shows us the flakiness in the test. There are test failures due to differences in the order of elements

Test 2:
The third command shows us the flakiness in the test. There are test failures due to differences in order of elements

Test 3:
Source of Flakiness in tests and fixes:
The Authorisation object created in the test case appends three strings to the auths member of the class which is a HashSet. The toString() method of the class then iterates over this HashSet and builds a String after concatenating the members of the set. Since a Java HashSet does not store order, the test case fails if the elements of the HashSet are iterated over in any order other than the order in which they were appended during object instantiation. To fix this, the test was updated to check if all strings in the auths member of the object are a part of the String returned by toString() instead of focusing on the order.
In this test case, the source of flakiness is the following lines -
final byte[] viewJson = view.toCompactJson();
final byte[] cloneJson = clone.toCompactJson();
assertThat(cloneJson).containsExactly(viewJson);
The method toCompactJson() internally uses JSONSerialiser.serialise() to convert the object into a byte stream. This does not preserve the order of attributes. Therefore, the containsExactly() method fails when the order of attributes differs in the two objects. To fix this, an ObjectMapper object was created and two JsonNode objects were created after calling the readTree() method on the two byte arrays. The equality check was then applied on these two JsonNode objects.
Similar to test 2, the source of flakiness is from the toCompactJson() method which does not preserve the order of attributes.
Please let me know if you have any questions or need any additional justification/changes from my side.