Partha-SUST16 opened a new pull request, #341:
URL: https://github.com/apache/commons-collections/pull/341

   ### What is the purpose of this PR
   
   - This PR fixes the flaky test  
`org.apache.commons.collections4.bag.CollectionBagTest.testCollectionToArray2`
   - The mentioned test may fail or pass without changes made to the source 
code when it is run in different JVMs due to `HashMap`'s non-deterministic 
iteration order.
   
   ### Why the test fails
   - As the `CollectionBagTest` uses `HashBag` as its `collection` which uses 
`HashMap` internally and as per `Java 8` documentation, the ordering of 
`HashMap` is not constant, so assigning the same hashmap as an array to 
different objects can change the ordering. So when comparing these two arrays 
with `assertEquals` the test may fail as their ordering can be different.
   
   ### Reproduce the test failure
   - Run the test with 'NonDex' maven plugin. The command to recreate the flaky 
test failure is 
     ` mvn -pl . edu.illinois:nondex-maven-plugin:1.1.2:nondex -debug 
-Dtest=org.apache.commons.collections4.bag.CollectionBagTest#testCollectionToArray2`
   
   - Fixing the flaky test now may prevent flaky test failures in future Java 
versions.
   
   ### Expected result
   - The tests should run successfully when run with 'NonDex' maven with the 
same command for recreating the flaky test.
   
   ### Actual Result
   - We get the failure:
       `[ERROR] 
org.apache.commons.collections4.bag.CollectionBagTest.testCollectionToArray2  
Time elapsed: 0.025 s  <<< FAILURE! junit.framework.AssertionFailedError: 
toArrays should be equal expected:<[10, 6.0, 11, 4, Seven, Eight, 5.0, 15, 2, 
12, 16, Thirteen, null, , Three, Nine, One, One, 14]> but was:<[, null, Seven, 
2, 5.0, 12, 10, 11, 14, 16, One, One, Nine, Eight, Thirteen, 15, 4, 6.0, Three]>
   `
   ### Fix
   - Override the `getIterationBehaviour()' method from 
`AbstractCollectionTest` and return `UNORDERED` in `CollectionBagTest`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@commons.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to