Skip to content

Commit 832cff4

Browse files
committed
Avoid using hashCode
When this test is run with the below JVM flags It fails because the hashCode is set to be constant -Duser.timezone="America/New_York" -Duser.country=FR -Duser.language=fr -XX:+UnlockExperimentalVMOptions -XX:hashCode=2 -Duser.country=FR -Duser.language=fr -XX:+UnlockDiagnosticVMOptions -XX:+StressGCM -XX:+StressLCM -XX:+StressIGVN -XX:+StressCCP
1 parent eb80671 commit 832cff4

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

testng-core/src/test/java/test/retryAnalyzer/RetryAnalyzerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class RetryAnalyzerTest extends SimpleBaseTest {
4646
@Test(description = "GITHUB-2798")
4747
public void ensureNoDuplicateRetryAnalyzerInstancesAreCreated() {
4848
create(TestClassSample.class).run();
49-
Map<Integer, Long> collected =
49+
Map<String, Long> collected =
5050
HashCodeAwareRetryAnalyzer.hashCodes.stream()
5151
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
5252
assertThat(collected.keySet())

testng-core/src/test/java/test/retryAnalyzer/issue2798/HashCodeAwareRetryAnalyzer.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,26 @@
22

33
import java.util.ArrayList;
44
import java.util.List;
5+
import java.util.UUID;
56
import org.testng.IRetryAnalyzer;
67
import org.testng.ITestResult;
78
import org.testng.internal.AutoCloseableLock;
89

910
public class HashCodeAwareRetryAnalyzer implements IRetryAnalyzer {
1011

11-
public static final List<Integer> hashCodes = new ArrayList<>();
12+
public static final List<String> hashCodes = new ArrayList<>();
1213

1314
private static final AutoCloseableLock lock = new AutoCloseableLock();
1415

16+
private final UUID id = UUID.randomUUID();
17+
1518
int cnt = 0;
1619
static final int threshold = 2;
1720

1821
@Override
1922
public boolean retry(ITestResult result) {
2023
try (AutoCloseableLock ignore = lock.lock()) {
21-
hashCodes.add(this.hashCode());
24+
hashCodes.add(id.toString());
2225
return cnt++ < threshold;
2326
}
2427
}

0 commit comments

Comments
 (0)