You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "XinT (Jira)" <ji...@apache.org> on 2020/10/08 18:16:00 UTC

[jira] [Updated] (COLLECTIONS-768) Flat3MapTest.tesetEntrySet() is flaky

     [ https://issues.apache.org/jira/browse/COLLECTIONS-768?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

XinT updated COLLECTIONS-768:
-----------------------------
    Description: 
The testEntrySet() function (org.apache.commons.collections4.map.Flat3MapTest#testEntrySet) is flaky because it uses a flaky helper function putAndRemove(). The helper function wrongly assumes that map iterators execute in insertion order, while in fact it can be any order. 

The current test asserts the last element iterated (and subsequently removed) is the last element inserted. Therefore, the test passes when it so happens that the last iterated element is the last inserted element, but fails otherwise. 

 

  was:
The `testEntrySet()` function is flaky because it uses a flaky helper function `putAndRemove()`. The helper function wrongly assumes that map iterators execute in insertion order, while in fact it can be any order. 

The current test asserts the last element iterated (and subsequently removed) is the last element inserted. Therefore, the test passes when it so happens that the last iterated element is the last inserted element, but fails otherwise. 

The current `putAndRemove()`:

```
private void putAndRemove(final Map<K, V> map) {
map.put((K) "A", (V) "one");
map.put((K) "B", (V) "two");
map.put((K) "C", (V) "three");
final Iterator<Map.Entry<K, V>> it =map.entrySet().iterator();

final Map.Entry<K, V> mapEntry1 =it.next();
final Map.Entry<K, V> mapEntry2 =it.next();
final Map.Entry<K, V> mapEntry3 =it.next();
it.remove();
assertEquals(2, map.size());
assertEquals("one", map.get("A"));
assertEquals("two", map.get("B"));
assertEquals(null, map.get("C"));
}
```
 


> Flat3MapTest.tesetEntrySet() is flaky
> -------------------------------------
>
>                 Key: COLLECTIONS-768
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-768
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Map
>    Affects Versions: 4.4
>            Reporter: XinT
>            Priority: Minor
>              Labels: easyfix, pull-request-available
>
> The testEntrySet() function (org.apache.commons.collections4.map.Flat3MapTest#testEntrySet) is flaky because it uses a flaky helper function putAndRemove(). The helper function wrongly assumes that map iterators execute in insertion order, while in fact it can be any order. 
> The current test asserts the last element iterated (and subsequently removed) is the last element inserted. Therefore, the test passes when it so happens that the last iterated element is the last inserted element, but fails otherwise. 
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)