You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2022/11/08 06:30:54 UTC
[GitHub] [commons-collections] yannizhou05 opened a new pull request, #360: Fix flaky test in CollectionUtilsTest.Java
yannizhou05 opened a new pull request, #360:
URL: https://github.com/apache/commons-collections/pull/360
The test below in `CollectionUtilsTest.java` was found flaky because of the ordering of result HashMap. The orders of elements in the HashMap are not the same as every time the test being called. In this case, LinkedHashMap was applied to ensure the orders do not cause the flakiness. This code change is trying to fix the [flaky tests](https://docs.gitlab.com/ee/development/testing_guide/flaky_tests.html) mentioned above, because they sometimes fail (as the picture showed) and sometimes pass. The failure could be reproduced by the commands above by using the tool of [NonDex](https://github.com/TestingResearchIllinois/NonDex). The code change is to make sure the tests will always pass in this case.
- `org.apache.commons.collections4.CollectionUtilsTest.get`
The test failures could be reproduced by
1. `mvn install -pl . -am -DskipTests`
2. run tests with NonDex
`mvn -pl . edu.illinois:nondex-maven-plugin:1.1.2:nondex -Dtest=org.apache.commons.collections4.CollectionUtilsTest#get`
<img width="896" alt="2" src="https://user-images.githubusercontent.com/61256379/200490788-027fa163-7ec5-43cd-9b0f-093bd359c0e9.png">
<img width="890" alt="3" src="https://user-images.githubusercontent.com/61256379/200490798-5413f162-637d-43e5-b9da-3ae766924046.png">
--
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-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-collections] yannizhou05 commented on a diff in pull request #360: Fix flaky test in CollectionUtilsTest.Java
Posted by GitBox <gi...@apache.org>.
yannizhou05 commented on code in PR #360:
URL: https://github.com/apache/commons-collections/pull/360#discussion_r1017432991
##########
src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java:
##########
@@ -687,7 +687,9 @@ public void get() {
assertEquals(2, CollectionUtils.get((Object) collectionA, 2));
assertEquals(2, CollectionUtils.get((Object) collectionA.iterator(), 2));
final Map<Integer, Integer> map = CollectionUtils.getCardinalityMap(collectionA);
- assertEquals(map.entrySet().iterator().next(), CollectionUtils.get((Object) map, 0));
+ Map<Integer, Integer> linkedMap = new LinkedHashMap<>();
Review Comment:
Thank you so much for the clarification. I have updated the code accordingly.
--
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-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-collections] aherbert commented on a diff in pull request #360: Fix flaky test in CollectionUtilsTest.Java
Posted by GitBox <gi...@apache.org>.
aherbert commented on code in PR #360:
URL: https://github.com/apache/commons-collections/pull/360#discussion_r1016232266
##########
src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java:
##########
@@ -687,7 +687,9 @@ public void get() {
assertEquals(2, CollectionUtils.get((Object) collectionA, 2));
assertEquals(2, CollectionUtils.get((Object) collectionA.iterator(), 2));
final Map<Integer, Integer> map = CollectionUtils.getCardinalityMap(collectionA);
- assertEquals(map.entrySet().iterator().next(), CollectionUtils.get((Object) map, 0));
+ Map<Integer, Integer> linkedMap = new LinkedHashMap<>();
Review Comment:
Add a comment to explain why this is done:
```Java
// Test assumes a defined iteration order so convert to a LinkedHashMap
```
Please use final:
```Java
final Map<Integer, Integer> linkedMap = ...
```
--
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-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-collections] aherbert commented on pull request #360: Fix flaky test in CollectionUtilsTest.Java
Posted by GitBox <gi...@apache.org>.
aherbert commented on PR #360:
URL: https://github.com/apache/commons-collections/pull/360#issuecomment-1306755028
I believe this is fixing a non-issue artificially introduced by the `nondex` plugin. The HashMap has an unspecified iteration order, but it is a deterministic data structure. If it is not modified then the iterator will return the same order.
This is different from other changes identified by `nondex` (see #341, #353) where the test assumptions about ordered iteration were false.
However I think the suggested change is harmless and it will prevent others identifying the same issue in the future using the `nondex` plugin.
--
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-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-collections] aherbert merged pull request #360: Fix flaky test in CollectionUtilsTest.Java
Posted by GitBox <gi...@apache.org>.
aherbert merged PR #360:
URL: https://github.com/apache/commons-collections/pull/360
--
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-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-collections] codecov-commenter commented on pull request #360: Fix flaky test in CollectionUtilsTest.Java
Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #360:
URL: https://github.com/apache/commons-collections/pull/360#issuecomment-1306733536
# [Codecov](https://codecov.io/gh/apache/commons-collections/pull/360?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#360](https://codecov.io/gh/apache/commons-collections/pull/360?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (b9759cf) into [master](https://codecov.io/gh/apache/commons-collections/commit/9bbfad5db3a0dc5a7f354e014249ecce5dfb3a60?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (9bbfad5) will **not change** coverage.
> The diff coverage is `n/a`.
```diff
@@ Coverage Diff @@
## master #360 +/- ##
=========================================
Coverage 81.17% 81.17%
Complexity 4603 4603
=========================================
Files 289 289
Lines 13452 13452
Branches 1979 1979
=========================================
Hits 10919 10919
Misses 1935 1935
Partials 598 598
```
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
--
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-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org