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

Test Timeout not respected in parallel="methods" mode #2009

Closed
2 of 7 tasks
Tygerian opened this issue Jan 30, 2019 · 2 comments · Fixed by #2012
Closed
2 of 7 tasks

Test Timeout not respected in parallel="methods" mode #2009

Tygerian opened this issue Jan 30, 2019 · 2 comments · Fixed by #2012

Comments

@Tygerian
Copy link

Tygerian commented Jan 30, 2019

TestNG Version

6.14.3

Expected behavior

Test thread is terminated if it takes longer than its timeout setting when running in parallel="methods" mode.

Actual behavior

Test is allowed to finish no matter how long it takes; the timeout setting only determines whether it will be marked as failed. This is similar to #811.

Is the issue reproducible on runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

Test case sample

import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.TestListenerAdapter;
import org.testng.TestNG;
import org.testng.annotations.Test;
import org.testng.xml.XmlSuite;

public class TestNGTimeOutTest {

    @Test
    public void testTimeOutWhenParallelIsMethods() {
        TestNG tng = new TestNG();
        tng.setParallel(XmlSuite.ParallelMode.METHODS);
        tng.setTestClasses(new Class[]{TimeOutWithParallelSample.class});

        TestListenerAdapter tla = new TestListenerAdapter();
        tng.addListener(tla);

        tng.run();

        Assert.assertEquals(tla.getFailedTests().size(), 1);
        Assert.assertEquals(tla.getSkippedTests().size(), 0);
        Assert.assertEquals(tla.getPassedTests().size(), 0);
        ITestResult result = tla.getFailedTests().get(0);
        Assert.assertTrue(result.getEndMillis() - result.getStartMillis() < 2000);
    }
}
import org.testng.annotations.Test;

public class TimeOutWithParallelSample {

    @Test(timeOut = 1000)
    public void myTestMethod() throws InterruptedException {
        Thread.sleep(2000);
    }
}
@krmahadevan
Copy link
Member

The latest released version of TestNG is 7.0.0-beta3. Please retry using this version and post back the results

krmahadevan added a commit to krmahadevan/testng that referenced this issue Jan 30, 2019
Closes testng-team#2009

When TestNG runs parallel tests without an 
executor monitoring the threads, the timeouts 
defined in the test methods aren’t honored and 
TestNG ends up running the tests till it runs to
completion and then uses the timeout value to 
mark the test as failed.

Fixed this by running the test only for as long as
the timeout has been defined after which the current
thread (which is where the test is running as well)
is interrupted.
krmahadevan added a commit to krmahadevan/testng that referenced this issue Jan 30, 2019
Closes testng-team#2009

When TestNG runs parallel tests without an 
executor monitoring the threads, the timeouts 
defined in the test methods aren’t honored and 
TestNG ends up running the tests till it runs to
completion and then uses the timeout value to 
mark the test as failed.

Fixed this by running the test only for as long as
the timeout has been defined after which the current
thread (which is where the test is running as well)
is interrupted.
@krmahadevan
Copy link
Member

@Tygerian - Please ignore the previous comment. The issue exists and I have fixed it.

krmahadevan added a commit to krmahadevan/testng that referenced this issue Jan 31, 2019
Closes testng-team#2009

When TestNG runs parallel tests without an 
executor monitoring the threads, the timeouts 
defined in the test methods aren’t honored and 
TestNG ends up running the tests till it runs to
completion and then uses the timeout value to 
mark the test as failed.

Fixed this by running the test only for as long as
the timeout has been defined after which the current
thread (which is where the test is running as well)
is interrupted.
krmahadevan added a commit to krmahadevan/testng that referenced this issue Jan 31, 2019
Closes testng-team#2009

When TestNG runs parallel tests without an 
executor monitoring the threads, the timeouts 
defined in the test methods aren’t honored and 
TestNG ends up running the tests till it runs to
completion and then uses the timeout value to 
mark the test as failed.

Fixed this by running the test only for as long as
the timeout has been defined after which the current
thread (which is where the test is running as well)
is interrupted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants