cayenne icon indicating copy to clipboard operation
cayenne copied to clipboard

Fix concurrent map flakiness

Open shunfan-shao opened this issue 4 years ago • 0 comments

Description

Test org.apache.cayenne.util.WeakValueMapTest.testConcurrentModification will fail under NonDex which detects flakiness under non-deterministic environment.

To reproduce:

mvn edu.illinois:nondex-maven-plugin:1.1.2:nondex \
    -pl cayenne-server \
    -Dtest=org.apache.cayenne.util.WeakValueMapTest#testConcurrentModification

Issue

The test code follows the logic below:

Map<String, Integer> map = new WeakValueMap<>(3);
for(Map.Entry<String, Integer> entry : map.entrySet()) {
    if("key_2".equals(entry.getKey())) 
        map.remove("key_2");
}

While WeakValueMap uses HashMap internally, it is not guaranteed for map.entrySet to iterate over the entries under some orders.

The code is expected to thrown ConcurrentModificationException during execution. Under some edge cases, eg: key_2 is traversed and removed last, the test will fail to throw and cause an issue.

shunfan-shao avatar Nov 18 '21 20:11 shunfan-shao