Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test case failure #3093

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}
}
}