You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After time out in test occurs, testng sends interruption signal to runner thread. Thread is free to ignore that signal and can keep running.
When signal is delivered, testng starts new thread for same test and use next item from data provider. In that time, there are 2 threads running parallel and both of them have the same name.
In MethodInvocationHelper#invokeWithTimeoutWithNewExecutor() one can see that every test invoke creates new executor and that executor has numbering for threads again starting at 1.
Better behaviour would be to share same executor, or somehow name all threads by different thread number.
Is the issue reproductible on runner?
Shell
Maven
Gradle
Ant
Eclipse
IntelliJ
NetBeans
Test case sample
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class ThreadNameTest {
@Test(timeOut = 300, dataProvider = "testDataProvider")
public void test(int i) {
boolean interrupted = false;
while (true) {
try {
Thread.sleep(100);
System.out.println(String.format("test-%s: Name = %s; interrupted = %s", i, Thread.currentThread().getName(), interrupted));
} catch (InterruptedException e) {
interrupted = true;
}
}
}
@DataProvider
public Object[][] testDataProvider() {
return new Object[][] {
{1},
{2}
};
}
And result is something like
test-1: Name = TestNG-method=test-1; interrupted = false
test-1: Name = TestNG-method=test-1; interrupted = false
org.testng.internal.thread.ThreadTimeoutException: Method ThreadNameTest.test() didn't finish within the time-out 300
at [email protected]/java.lang.Thread.sleep(Native Method)
at app//ThreadNameTest.test(ThreadNameTest.java:10)
at [email protected]/java.lang.Thread.run(Thread.java:834)
test-1: Name = TestNG-method=test-1; interrupted = true
test-1: Name = TestNG-method=test-1; interrupted = true
test-2: Name = TestNG-method=test-1; interrupted = false
test-1: Name = TestNG-method=test-1; interrupted = true
test-2: Name = TestNG-method=test-1; interrupted = false
test-1: Name = TestNG-method=test-1; interrupted = true
org.testng.internal.thread.ThreadTimeoutException: Method ThreadNameTest.test() didn't finish within the time-out 300
at [email protected]/java.lang.Thread.sleep(Native Method)
at app//ThreadNameTest.test(ThreadNameTest.java:10)
at [email protected]/java.lang.Thread.run(Thread.java:834)
You can see, that first test is interrupted, but keeps running when second test starts. Both threads have same name (TestNG-method=test-1)
The text was updated successfully, but these errors were encountered:
TestNG Version
Expected behavior
After time out in test occurs, testng sends interruption signal to runner thread. Thread is free to ignore that signal and can keep running.
When signal is delivered, testng starts new thread for same test and use next item from data provider. In that time, there are 2 threads running parallel and both of them have the same name.
In
MethodInvocationHelper#invokeWithTimeoutWithNewExecutor()
one can see that every test invoke creates new executor and that executor has numbering for threads again starting at 1.Better behaviour would be to share same executor, or somehow name all threads by different thread number.
Is the issue reproductible on runner?
Test case sample
And result is something like
You can see, that first test is interrupted, but keeps running when second test starts. Both threads have same name (TestNG-method=test-1)
The text was updated successfully, but these errors were encountered: