[core] Fix flaky LatticeRelationTest #4752
Merged
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.
Describe the PR
Problem
The
LatticeRelationTest.testToString
is detected as flaky. The following lines of code iterate oververtices
which is of Type Set.pmd/pmd-core/src/main/java/net/sourceforge/pmd/util/GraphUtil.java
Line 46 in f030d7f
pmd/pmd-core/src/main/java/net/sourceforge/pmd/util/GraphUtil.java
Line 59 in f030d7f
Java does not iterate over elements of a set in a particular order. This causes the output
toString
function to be non-deterministic and results in theLatticeRelationTest.testToString
to be flaky.Solution
I have modified the code such that we iterate over a sorted list of
Vertex
objects. This results in thetoString
output being deterministic. I had to modify the expected string in the test assertion to account for the sorting.Another possible fix would be to modify the test itself and change the
assert
to expect multiple different string ordering values.Steps to reproduce the flaky test
Setup the NonDex tool and run
Error Message
Ready?
./mvnw clean verify
passes (checked automatically by github actions)