Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Current (7.11.0)
Current (7.12.0)
Fixed: GITHUB-2765: Test timeouts using existing Executor now propagate the stack trace to the ThreadTimeoutException

7.11.0
Fixed: GITHUB-3180: TestNG testng-failed.xml 'invocation-numbers' values are not calculated correctly with retry and dataproviders (Krishnan Mahadevan)
Fixed: GITHUB-3170: Specifying dataProvider and successPercentage causes test to always pass (Krishnan Mahadevan)
Fixed: GITHUB-3028: Execution stalls when using "use-global-thread-pool" (Krishnan Mahadevan)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,24 @@ public class ThreadTimeoutException extends Exception {
private static final long serialVersionUID = 7009400729783393548L;

public ThreadTimeoutException(String msg) {
super(msg);
this(msg, null);
}

public ThreadTimeoutException(String msg, Throwable cause) {
super(msg, cause);
}

public ThreadTimeoutException(Throwable cause) {
super(cause);
}

public ThreadTimeoutException(ITestNGMethod tm, long timeout) {
this("Method " + tm.getQualifiedName() + "() didn't finish within the time-out " + timeout);
this(tm, timeout, null);
}

public ThreadTimeoutException(ITestNGMethod tm, long timeout, Throwable cause) {
this(
"Method " + tm.getQualifiedName() + "() didn't finish within the time-out " + timeout,
cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ private static boolean invokeWithTimeoutWithNoExecutor(
Throwable e = ex.getCause();
boolean wasTimedOut = !(notTimedout && !interruptByMonitor.get());
if (wasTimedOut) {
e = new ThreadTimeoutException(tm, realTimeOut);
e = new ThreadTimeoutException(tm, realTimeOut, e);
} else {
if (e instanceof TestNGRuntimeException) {
e = e.getCause();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.testng.Assert.assertTrue;

import com.google.common.base.Throwables;
import java.util.Arrays;
import org.testng.ITestListener;
import org.testng.ITestResult;
Expand All @@ -25,7 +26,7 @@ public Throwable getTestError() {
}

@Test
public void verifyTimeoutStacktrace() {
public void verifyTimeoutStacktraceNewExecutor() {
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] {TimeoutStacktraceTestSample.class});
TimeoutStacktraceTestListener listener = new TimeoutStacktraceTestListener();
Expand All @@ -39,4 +40,21 @@ public void verifyTimeoutStacktrace() {
Arrays.stream(testError.getStackTrace())
.anyMatch(s -> s.getMethodName().equals("testTimeoutStacktrace")));
}

@Test
public void verifyTimeoutStacktraceNoExecutor() {
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] {TimeoutStacktraceTestSample.class});
TimeoutStacktraceTestListener listener = new TimeoutStacktraceTestListener();
testng.addListener(listener);
testng.setSuiteThreadPoolSize(2);
testng.run();

Throwable testError = listener.getTestError();
assertTrue(testError instanceof ThreadTimeoutException);
assertTrue(
Throwables.getCausalChain(testError).stream()
.flatMap((Throwable throwable) -> Arrays.stream(throwable.getStackTrace()))
.anyMatch(s -> s.getMethodName().equals("testTimeoutStacktrace")));
}
}
Loading