Fix flaky test RefactorTest#47
Open
jcoben wants to merge 1 commit into
Open
Conversation
This test was passing when run on its own but flaky when run with other tests. Discovered with the nondex tool: https://github.com/TestingResearchIllinois/NonDex Ran test on its own with command: mvn test -Dtest=com.insightfullogic.java8.examples.chapter3.RefactorTest#allStringJoins Ran tests in groups with command: mvn edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=com.insightfullogic.java8.examples.chapter3.RefactorTest#allStringJoins Fixed test by adding some code to sort the HashSet before comparing it to a hard-coded string.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 is the purpose of this PR
com.insightfullogic.java8.examples.chapter3.RefactorTest#allStringJoinsHashSet's non-deterministic iteration order.Why the tests fail
HashSetcontaining the string data. The test compares this result to a hard-coded string value. The problem is that the order of iteration is not guaranteed forHashSets. So, the test may fail as the given order can be different from the expected order.Reproduce the test failure
Run the tests with
NonDexmaven plugin. The commands to recreate the flaky test failures are:mvn edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=com.insightfullogic.java8.examples.chapter3.RefactorTest#allStringJoinsTo run the test without NonDex:
mvn test -Dtest=com.insightfullogic.java8.examples.chapter3.RefactorTest#allStringJoinsExpected results
NonDex.Actual Result
Description of Fix
HashSetinto a list and then usedCollections.sort()to sort it before comparing to the hard-coded string value.