commons-collections icon indicating copy to clipboard operation
commons-collections copied to clipboard

COLLECTIONS-804- Fix flaky test testCollectionToArray2

Open anirudh711 opened this issue 2 years ago • 1 comments

Problem:

The test testCollectionToArray2 is flaky because the array in use does not maintain the order of the elements. This was caught by the nondex tool created by the researchers of UIUC. Related issue : https://issues.apache.org/jira/browse/COLLECTIONS-804 Related PR with a similar fix: https://github.com/apache/commons-collections/pull/341

Description:

The flakiness occurs in two places

https://github.com/apache/commons-collections/blob/35e408717379eed0085cdb29e879209dbadc1ead/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java#L1132-L1136

https://github.com/apache/commons-collections/blob/35e408717379eed0085cdb29e879209dbadc1ead/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java#L1156-L1162

The function getIterationBehaviour() returns 0 by default mentioning the array is ordered and the constant UNORDERED is used for the functions that might be unordered in which a different assertion assertUnorderedArrayEquals will be used . Since the code is part of the abstract class, this code has to remain untouched but the getIterationBehaviour() of the classes implementing this abstract class can be changed.

getIterationBehaviour() of the class TestMapEntrySet returns 0 which means it assumes the array being ordered for TestMapEntrySet which is not true. The order of elements can be changed and will be nondeterministic.

Fix:

In the overriding function, the return value has to be changed from 0 to 1 which mentions it can be unordered and this will only affect the TestMapEntrySet and not other classes.

https://github.com/anirudh711/commons-collections/blob/90a80f010822fca17323bfc043f14ebc71c92a78/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java#L1644-L1648

anirudh711 avatar Nov 22 '23 21:11 anirudh711

Hello @anirudh711 You'll need to show something failing, like a new test, to justify this change. TY

garydgregory avatar Mar 31 '24 15:03 garydgregory

Closing: No further reply from OP.

garydgregory avatar Sep 03 '24 18:09 garydgregory