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

Same thread names when time outed thread keeps running #2091

Open
1 of 7 tasks
rikiel opened this issue Jun 4, 2019 · 0 comments
Open
1 of 7 tasks

Same thread names when time outed thread keeps running #2091

rikiel opened this issue Jun 4, 2019 · 0 comments

Comments

@rikiel
Copy link

rikiel commented Jun 4, 2019

TestNG Version

7.0.0-beta4

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?

  • 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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants