Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix concurrent map flakiness #472

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Fix concurrent map flakiness #472

wants to merge 5 commits into from

Conversation

shunfan-shao
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant