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

Restore Ordering for DependsOnGroups by using separate Priority on Configuration Methods alternative 2 #2668

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Current
Fixed: GITHUB-2643: assertEquals(Set,Set) now ignores ordering as it did before. (Elis Edlund)
Fixed: GITHUB-2653: Assert methods requires casting since TestNg 7.0 for mixed boxed and unboxed primitives in assertEquals.
New: GITHUB-2663 Add support for Priority in Configuration Methods. (Martin Aldrin)
Fixed: GITHUB-2653: Assert methods requires casting since TestNg 7.0 for mixed boxed and unboxed primitives in assertEquals. (Martin Aldrin)
Fixed: GITHUB-2229: Restore @BeforeGroups and @AfterGroups Annotations functionality (Krishnan Mahadevan)
Fixed: GITHUB-2563: Skip test if its data provider provides no data (Krishnan Mahadevan)
Fixed: GITHUB-2535: TestResult.getEndMillis() returns 0 for skipped configuration - after upgrading testng to 7.0 + (Krishnan Mahadevan)
Expand Down
4 changes: 4 additions & 0 deletions testng-core-api/src/main/java/org/testng/ITestNGMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ default boolean hasAfterGroupsConfiguration() {

void setInterceptedPriority(int priority);

int getClassHierarchyPriority();

void setClassHierarchyPriority(int priority);

/** @return the XmlTest this method belongs to. */
XmlTest getXmlTest();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,11 @@
* @return the valude (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,11 @@ public interface ITestOrConfiguration extends IParameterizable {
String getDescription();

void setDescription(String description);

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int getPriority();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public final class Systematiser {

private static final Comparator<ITestNGMethod> COMPARE_INSTANCES =
Comparator.comparingInt(ITestNGMethod::getPriority)
.thenComparing(ITestNGMethod::getClassHierarchyPriority)
.thenComparing(method -> method.getRealClass().getName())
.thenComparing(ITestNGMethod::getMethodName)
.thenComparing(Object::toString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public abstract class BaseTestMethod implements ITestNGMethod, IInvocationStatus
private boolean m_ignoreMissingDependencies;
private int m_priority;
private int m_interceptedPriority;
private int m_classHierarchyPriority;

private XmlTest m_xmlTest;
private final Object m_instance;
Expand Down Expand Up @@ -710,6 +711,16 @@ public void setInterceptedPriority(int priority) {
m_interceptedPriority = priority;
}

@Override
public int getClassHierarchyPriority() {
return m_classHierarchyPriority;
}

@Override
public void setClassHierarchyPriority(int priority) {
m_classHierarchyPriority = priority;
}

@Override
public XmlTest getXmlTest() {
return m_xmlTest;
Expand Down
14 changes: 12 additions & 2 deletions testng-core/src/main/java/org/testng/internal/ClonedMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public int getPriority() {

@Override
public void setPriority(int priority) {
// ignored
m_method.setPriority(priority);
}

@Override
Expand All @@ -337,7 +337,17 @@ public int getInterceptedPriority() {

@Override
public void setInterceptedPriority(int priority) {
// ignored
m_method.setInterceptedPriority(priority);
}

@Override
public int getClassHierarchyPriority() {
return m_method.getClassHierarchyPriority();
}

@Override
public void setClassHierarchyPriority(int priority) {
m_method.setClassHierarchyPriority(priority);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ private void init() {
m_inheritGroupsFromTestClass = annotation.getInheritGroups();
setEnabled(annotation.getEnabled());
setDescription(annotation.getDescription());
setPriority(annotation.getPriority());
}

if (annotation != null && annotation.isFakeConfiguration()) {
Expand Down Expand Up @@ -503,6 +504,7 @@ public ConfigurationMethod clone() {
clone.setDescription(getDescription());
clone.setEnabled(getEnabled());
clone.setParameterInvocationCount(getParameterInvocationCount());
clone.setPriority(getPriority());
clone.m_inheritGroupsFromTestClass = inheritGroupsFromTestClass();

return clone;
Expand Down
20 changes: 7 additions & 13 deletions testng-core/src/main/java/org/testng/internal/MethodHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.testng.internal.collections.Pair;
import org.testng.internal.invokers.IInvocationStatus;
import org.testng.util.TimeUtils;
import org.testng.xml.XmlTest;

/** Collection of helper methods to help sort and arrange methods. */
public class MethodHelper {
Expand Down Expand Up @@ -259,11 +258,7 @@ private static Graph<ITestNGMethod> topologicalSort(

Map<Object, List<ITestNGMethod>> testInstances = sortMethodsByInstance(methods);

XmlTest xmlTest = null;
for (ITestNGMethod m : methods) {
if (xmlTest == null) {
xmlTest = m.getXmlTest();
}
result.addNode(m);

List<ITestNGMethod> predecessors = Lists.newArrayList();
Expand All @@ -289,14 +284,13 @@ private static Graph<ITestNGMethod> topologicalSort(
}
predecessors.addAll(Arrays.asList(methodsNamed));
}
if (XmlTest.isGroupBasedExecution(xmlTest)) {
String[] groupsDependedUpon = m.getGroupsDependedUpon();
if (groupsDependedUpon.length > 0) {
for (String group : groupsDependedUpon) {
ITestNGMethod[] methodsThatBelongToGroup =
MethodGroupsHelper.findMethodsThatBelongToGroup(m, methods, group);
predecessors.addAll(Arrays.asList(methodsThatBelongToGroup));
}
// Should not be part of this commit. just added until GITHUB-2664 is solved.
String[] groupsDependedUpon = m.getGroupsDependedUpon();
if (groupsDependedUpon.length > 0) {
for (String group : groupsDependedUpon) {
ITestNGMethod[] methodsThatBelongToGroup =
MethodGroupsHelper.findMethodsThatBelongToGroup(m, methods, group);
predecessors.addAll(Arrays.asList(methodsThatBelongToGroup));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.testng.ITestNGMethod;
import org.testng.collections.Lists;
import org.testng.collections.Maps;
import org.testng.xml.XmlTest;

public class MethodInheritance {

Expand Down Expand Up @@ -135,14 +134,11 @@ public static void fixMethodInheritance(ITestNGMethod[] methods, boolean before)
ITestNGMethod m1 = l.get(i);
for (int j = i + 1; j < l.size(); j++) {
ITestNGMethod m2 = l.get(j);
boolean groupMode = XmlTest.isGroupBasedExecution(m2.getXmlTest());
if (groupMode) {
// Do not resort to adding implicit depends-on if there are groups
continue;
}
if (!equalsEffectiveClass(m1, m2) && !dependencyExists(m1, m2, methods)) {
Utils.log("MethodInheritance", 4, m2 + " DEPENDS ON " + m1);
m2.addMethodDependedUpon(MethodHelper.calculateMethodCanonicalName(m1));
if (m1.getClassHierarchyPriority() >= m2.getClassHierarchyPriority()) {
m2.setClassHierarchyPriority(m2.getClassHierarchyPriority() + 1);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public static int compareStatic(ITestNGMethod o1, ITestNGMethod o2) {
return prePriDiff;
}

int prePriDiff2 =
Integer.compare(o1.getClassHierarchyPriority(), o2.getClassHierarchyPriority());
if (prePriDiff2 != 0) {
return prePriDiff2;
}

int priDiff = Integer.compare(o1.getPriority(), o2.getPriority());
if (priDiff != 0) {
return priDiff;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,16 @@ public void setInterceptedPriority(int priority) {
testNGMethod.setInterceptedPriority(priority);
}

@Override
public int getClassHierarchyPriority() {
return testNGMethod.getClassHierarchyPriority();
}

@Override
public void setClassHierarchyPriority(int priority) {
testNGMethod.setClassHierarchyPriority(priority);
}

@Override
public XmlTest getXmlTest() {
return testNGMethod.getXmlTest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ private static void finishInitialize(
result.setGroups(bs.getGroups());
result.setInheritGroups(bs.getInheritGroups());
result.setTimeOut(bs.getTimeOut());
result.setPriority(bs.getPriority());
}

public static List<Class<? extends IAnnotation>> getAllAnnotations() {
Expand Down
Loading