Skip to content

Commit

Permalink
Merge pull request testng-team#3093 from krmahadevan/fix_test/RetryAn…
Browse files Browse the repository at this point in the history
…alyzerTest_ensureRetryDoesntRunEndlesslyForDataDrivenTests

Test case failure
  • Loading branch information
juherr authored Mar 17, 2024
2 parents 15874ea + 3505e4b commit 554cfa6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
15 changes: 10 additions & 5 deletions testng-core/src/main/java/org/testng/internal/BaseTestMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.testng.IClass;
Expand Down Expand Up @@ -832,7 +833,7 @@ private IRetryAnalyzer getRetryAnalyzerConsideringMethodParameters(ITestResult t
return this.m_retryAnalyzer;
}

final String keyAsString = getSimpleName() + "#" + hashParameters(tr);
final String keyAsString = getSimpleName() + "#" + parameterId(tr);
return m_testMethodToRetryAnalyzer.computeIfAbsent(
keyAsString,
key -> {
Expand All @@ -842,9 +843,13 @@ private IRetryAnalyzer getRetryAnalyzerConsideringMethodParameters(ITestResult t
});
}

private int hashParameters(ITestResult itr) {
Object[] parameters = itr.getParameters();
return Objects.hash(parameters);
private final Map<IObject.IdentifiableArrayObject, IObject.IdentifiableArrayObject> parameters =
new ConcurrentHashMap<>();

private String parameterId(ITestResult itr) {
IObject.IdentifiableArrayObject parameter =
new IObject.IdentifiableArrayObject(itr.getParameters());
return parameters.computeIfAbsent(parameter, Function.identity()).getInstanceId();
}

private static boolean isNotParameterisedTest(ITestResult tr) {
Expand Down
33 changes: 33 additions & 0 deletions testng-core/src/main/java/org/testng/internal/IObject.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.testng.internal;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
Expand Down Expand Up @@ -113,4 +114,36 @@ public int hashCode() {
return Objects.hash(instanceId);
}
}

/**
* A wrapper class that wraps around an array and associates a unique Id that can be used as a key
* for the array.
*/
class IdentifiableArrayObject {

private final String instanceId = UUID.randomUUID().toString();

private final Object[] parameters;

public IdentifiableArrayObject(Object[] parameters) {
this.parameters = parameters;
}

public String getInstanceId() {
return instanceId;
}

@Override
public boolean equals(Object object) {
if (this == object) return true;
if (object == null || getClass() != object.getClass()) return false;
IdentifiableArrayObject that = (IdentifiableArrayObject) object;
return Arrays.equals(parameters, that.parameters);
}

@Override
public int hashCode() {
return Arrays.hashCode(parameters);
}
}
}

0 comments on commit 554cfa6

Please sign in to comment.