-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix #1480: Priority/parallel=methods issue. #1910
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
Changes from all commits
bdbb563
0feae1f
64ae15e
e2f8805
fba7b44
5c56486
1e1d704
7b5e25d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package org.testng.internal; | ||
|
|
||
| import java.util.Comparator; | ||
|
|
||
| import org.testng.ITestNGMethod; | ||
|
|
||
| public class TestMethodComparator implements Comparator<ITestNGMethod> { | ||
|
|
||
| @Override | ||
| public int compare(ITestNGMethod o1, ITestNGMethod o2) { | ||
| return compareStatic(o1, o2); | ||
| } | ||
|
|
||
| public static int compareStatic(ITestNGMethod o1, ITestNGMethod o2) { | ||
| int prePriDiff = o1.getInterceptedPriority() - o2.getInterceptedPriority(); | ||
| if (prePriDiff != 0) { | ||
| return prePriDiff; | ||
| } | ||
|
|
||
| int priDiff = o1.getPriority() - o2.getPriority(); | ||
| if (priDiff != 0) { | ||
| return priDiff; | ||
| } | ||
|
|
||
| return o1.getMethodName().compareTo(o2.getMethodName()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,9 @@ | |
| import org.testng.log4testng.Logger; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.concurrent.BlockingQueue; | ||
|
|
@@ -26,6 +29,7 @@ public class GraphThreadPoolExecutor<T> extends ThreadPoolExecutor { | |
| private final IThreadWorkerFactory<T> m_factory; | ||
| private final Map<T, IWorker<T>> mapping = Maps.newConcurrentMap(); | ||
| private final Map<T, T> upstream = Maps.newConcurrentMap(); | ||
| private final Comparator<T> m_comparator; | ||
|
|
||
| public GraphThreadPoolExecutor( | ||
| String name, | ||
|
|
@@ -35,7 +39,8 @@ public GraphThreadPoolExecutor( | |
| int maximumPoolSize, | ||
| long keepAliveTime, | ||
| TimeUnit unit, | ||
| BlockingQueue<Runnable> workQueue) { | ||
| BlockingQueue<Runnable> workQueue, | ||
| Comparator<T> comparator) { | ||
| super( | ||
| corePoolSize, | ||
| maximumPoolSize, | ||
|
|
@@ -45,6 +50,7 @@ public GraphThreadPoolExecutor( | |
| new TestNGThreadFactory(name)); | ||
| m_graph = graph; | ||
| m_factory = factory; | ||
| m_comparator = comparator; | ||
|
|
||
| if (m_graph.getFreeNodes().isEmpty()) { | ||
| throw new TestNGException("The graph of methods contains a cycle:" + graph); | ||
|
|
@@ -54,6 +60,9 @@ public GraphThreadPoolExecutor( | |
| public void run() { | ||
| synchronized (m_graph) { | ||
| List<T> freeNodes = m_graph.getFreeNodes(); | ||
| if (m_comparator != null) { | ||
| Collections.sort(freeNodes, m_comparator); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The sort logic could be done in |
||
| } | ||
| runNodes(freeNodes); | ||
| } | ||
| } | ||
|
|
@@ -84,6 +93,9 @@ public void afterExecute(Runnable r, Throwable t) { | |
| shutdown(); | ||
| } else { | ||
| List<T> freeNodes = m_graph.getFreeNodes(); | ||
| if (m_comparator != null) { | ||
| Collections.sort(freeNodes, m_comparator); | ||
| } | ||
| handleThreadAffinity(freeNodes); | ||
| runNodes(freeNodes); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ public void a_second0() { | |
|
|
||
| @Test( | ||
| groups = {"3"}, | ||
| dependsOnGroups = {"2.0"}) | ||
| dependsOnGroups = {"2.0", "2.1"}) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this was a case where the dependency was being assumed by the test, but wasn't explicit. |
||
| public void third0() { | ||
| verifyGroup(3, m_group2); | ||
| m_group3[0] = true; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -159,7 +159,7 @@ public static Object[][] dp1380() { | |
| {GitHub1380Sample.class, new String[] {"testMethodA", "testMethodB", "testMethodC"}, true}, | ||
| {GitHub1380Sample2.class, new String[] {"testMethodC", "testMethodB", "testMethodA"}, true}, | ||
| {GitHub1380Sample3.class, new String[] {"testMethodA", "testMethodB", "testMethodC"}, true}, | ||
| {GitHub1380Sample4.class, new String[] {"testMethodB", "testMethodA", "testMethodC"}, true} | ||
| {GitHub1380Sample4.class, new String[] {"testMethodB", "testMethodC", "testMethodA"}, true} | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change to this test is because |
||
| }; | ||
| } | ||
|
|
||
|
|
@@ -175,7 +175,15 @@ public void simpleCyclingDependencyShouldWork( | |
| tng.addListener(listener); | ||
|
|
||
| tng.run(); | ||
|
|
||
| assertThat(listener.getSucceedMethodNames()).containsExactly(runMethods); | ||
|
|
||
| if (!isParallel) { | ||
| // When not running parallel, invoke order and succeed order are the same. | ||
| assertThat(listener.getInvokedMethodNames()).containsExactly(runMethods); | ||
| assertThat(listener.getSucceedMethodNames()).containsExactly(runMethods); | ||
| } else { | ||
| // When running parallel, invoke order is consistent, but succeed order isn't. | ||
| assertThat(listener.getInvokedMethodNames()).containsExactly(runMethods); | ||
| assertThat(listener.getSucceedMethodNames()).containsExactlyInAnyOrder(runMethods); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implements the default behavior (and remove it from tests)