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 this pull request does
This pull request fixes the flaky test
SnippetsTests.pick_should_pick_key_pairs_corresponding_to_keys
. The test passes sometimes and fails other times because theSnippets.pick
method does not preserve the order of elements in a list, while the test assumes a specific order.Why the test is flaky
The
containsExactly
method assumes that the mapgroups
will have a specific order, but theSnippets.pick
method can return a map with elements in any order.How the test was fixed
The test can be fixed by replacing
containsExactly
withcontainsOnly
, which does not assume a specific order.Reproduce the test failure
Run the tests with the
NonDex
maven tool and use the following command:mvn -e -pl . edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=snippets.SnippetsTests#pick_should_pick_key_pairs_corresponding_to_keys
Fixing the flaky test now may prevent flaky test failures in future Java versions.
Result from testing
We get the following failure:
[ERROR]
pick_should_pick_key_pairs_corresponding_to_keys(snippets.SnippetsTests)
Time elapsed: 0.039 s <<< FAILURE!java.lang.AssertionError
: Actual and expected have the same elements but not in the same order, at index 0 actual element was:<MapEntry[key="c", value=3]>
whereas expected element was:<a=1>