Skip to content

Commit a69e198

Browse files
authored
Fix: flaky tests of set comparison (#3104)
The flaky tests below were found with [NonDex](https://github.com/TestingResearchIllinois/NonDex), which explores non-determinism in tests. These tests can fail due to different iteration orders under different JVMs, hash seeds, etc. - `AbstractValueTest.shouldConvertToJavaSetUsingSupplier` - `AbstractValueTest.shouldConvertToJavaSet` - `AbstractTraversableTest.shouldConvertNonNilToHashSet` The `assertThat(Iterable<T>)` returns an `IterableAssert`, even when we pass a Set. The comparator `isEqualTo(...)` for `IterableAssert` is order-sensitive and can iterate through the sets in different orders. Use `containsExactlyInAnyOrderElementsOf` from assertJ, which is order-insensitive. The fix only modifies test code, but not production code. ### Failure Reproduction - Java version: ``` openjdk 17.0.16 2025-07-15 OpenJDK Runtime Environment (build 17.0.16+8-Ubuntu-0ubuntu124.04.1) OpenJDK 64-Bit Server VM (build 17.0.16+8-Ubuntu-0ubuntu124.04.1, mixed mode, sharing) ``` - OS version: `Ubuntu 24.04.3 LTS` Build the module and run tests with [NonDex](https://github.com/TestingResearchIllinois/NonDex), for example: ``` mvn edu.illinois:nondex-maven-plugin:2.1.7:nondex -pl vavr \ -Dtest=IteratorTest#shouldConvertToJavaSetUsingSupplier \ -Djacoco.skip -Drat.skip -Dpmd.skip -Denforcer.skip ```
1 parent ae2ab78 commit a69e198

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

vavr/src/test/java/io/vavr/AbstractValueTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -804,9 +804,9 @@ public void shouldConvertToJavaSet() {
804804
final Value<Integer> value = of(1, 2, 3);
805805
final java.util.Set<Integer> set = value.toJavaSet();
806806
if (value.isSingleValued()) {
807-
assertThat(set).isEqualTo(JavaCollections.javaSet(1));
807+
assertThat(set).containsExactlyInAnyOrderElementsOf(JavaCollections.javaSet(1));
808808
} else {
809-
assertThat(set).isEqualTo(JavaCollections.javaSet(1, 2, 3));
809+
assertThat(set).containsExactlyInAnyOrderElementsOf(JavaCollections.javaSet(1, 2, 3));
810810
}
811811
}
812812

@@ -815,9 +815,9 @@ public void shouldConvertToJavaSetUsingSupplier() {
815815
final Value<Integer> value = of(1, 2, 3);
816816
final java.util.Set<Integer> set = value.toJavaSet(java.util.HashSet::new);
817817
if (value.isSingleValued()) {
818-
assertThat(set).isEqualTo(JavaCollections.javaSet(1));
818+
assertThat(set).containsExactlyInAnyOrderElementsOf(JavaCollections.javaSet(1));
819819
} else {
820-
assertThat(set).isEqualTo(JavaCollections.javaSet(1, 2, 3));
820+
assertThat(set).containsExactlyInAnyOrderElementsOf(JavaCollections.javaSet(1, 2, 3));
821821
}
822822
}
823823

vavr/src/test/java/io/vavr/collection/AbstractTraversableTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2601,7 +2601,7 @@ public void shouldConvertNonNilToHashSet() {
26012601
expected.add(2);
26022602
expected.add(1);
26032603
expected.add(3);
2604-
assertThat(of(1, 2, 2, 3).toJavaSet()).isEqualTo(expected);
2604+
assertThat(of(1, 2, 2, 3).toJavaSet()).containsExactlyInAnyOrderElementsOf(expected);
26052605
}
26062606

26072607
// toTree

0 commit comments

Comments
 (0)