review: test: Fixed 4 non-deterministic flaky tests #6084
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.
What changes were proposed in this pull request?
Sorting the order of imports list variable and enums list variable in 4 flaky tests in order to make them deterministic. The assertions are written with an assumption that the list will always be in a particular predefined order, but that may not be the case. The PR contains fix for the below test cases to make them deterministic:
Why are the changes needed?
Multiple flaky tests were detected while trying to run the tests using the nondex tool. NonDex is a tool for detecting and debugging wrong assumptions on under-determined Java APIs.
Sample ERROR logs:
Reason for Failure
As mentioned above, the assertions assume that the list will always be in a particular predefined order, but that may not be the case. For eg, in test case : staticImports_ofNestedTypes_shouldBeRecorded, we have the following test case
The above code assumes that the first element of the list will be
InnerClass
which may not be true. This is because the imports is being set byJDTImportBuilder.java
class where the imports variable is implemented as HashSet. As per the javadocs, the order of elements is not maintained in HashSet.Hence, we sort the fields before asserting based on certain fields to make the order deterministic.
Steps to reproduce flakiness using nondex -
Please let me know if you have any questions or would like to discuss this further for any clarificaitions.