Skip to content

Commit

Permalink
Fix #811: Timeout is not working with parallel=tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juherr committed Nov 22, 2015
1 parent 402f6b1 commit 2c23fd8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.testng.internal.thread.ThreadExecutionException;
import org.testng.internal.thread.ThreadTimeoutException;
import org.testng.internal.thread.ThreadUtil;
import org.testng.xml.XmlSuite;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -225,7 +226,7 @@ protected static void invokeWithTimeout(ITestNGMethod tm, Object instance,
protected static void invokeWithTimeout(ITestNGMethod tm, Object instance,
Object[] parameterValues, ITestResult testResult, IHookable hookable)
throws InterruptedException, ThreadExecutionException {
if (ThreadUtil.isTestNGThread()) {
if (ThreadUtil.isTestNGThread() && testResult.getTestContext().getCurrentXmlTest().getParallel() != XmlSuite.ParallelMode.TESTS) {
// We are already running in our own executor, don't create another one (or we will
// lose the time out of the enclosing executor).
invokeWithTimeoutWithNoExecutor(tm, instance, parameterValues, testResult, hookable);
Expand Down
6 changes: 2 additions & 4 deletions src/test/java/test/thread/FactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ public void verifyFactoryParallelMethods() {
runTest(XmlSuite.ParallelMode.METHODS, 2);
}

@Test(groups = "broken",
description = "Known bug: when parallel='tests', tests returned" +
" by a @Factory are run in the same thread")
@Test
public void verifyFactoryParallelTests() {
runTest(XmlSuite.ParallelMode.TESTS, 2);
runTest(XmlSuite.ParallelMode.TESTS, 1);
}

private void runTest(XmlSuite.ParallelMode parallelMode, int expectedThreadIdCount) {
Expand Down

0 comments on commit 2c23fd8

Please sign in to comment.