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

Parallel classes runs methods from one class in different threads, interleaves two classes in one thread #1050

Closed
markdbullock opened this issue May 27, 2016 · 7 comments

Comments

@markdbullock
Copy link

I have a TestNG suite which runs classes in parallel.
I have encountered failures because test methods which have dependencies ran in different threads.
I created a minimum reproduceable test case.
My Test classes extend an abstract test class. I don't know if this is related to the problem.
I attached a zip file with the Java source, Test.xml and pom.xml
parallelClasses.zip

EXPECTED:
FirstTest.testTwo should run in thread 11. I expect all test methods from one class to run in the same thread.
ThirdTest.test3a should run after SecondTest class finishes. I expect all test methods in a class to run before another class starts running in the same thread.

ACTUAL:
`[TestNG] Running:
C:\Users\mbullock\workspace\Test\Test.xml

thread 11 STARTING METHOD=FirstTest.testOne
thread 12 STARTING METHOD=SecondTest.test2a
thread 12 STARTING METHOD=ThirdTest.test3a
thread 12 STARTING METHOD=SecondTest.test2b
thread 11 STARTING METHOD=ThirdTest.test3b
thread 12 STARTING METHOD=FirstTest.testTwo

Critical
Total tests run: 6, Failures: 0, Skips: 0
===============================================`

@aksharpanchal
Copy link

+1

@dr29bart
Copy link
Contributor

There is a Test annotation parameter : singleThreaded
http://testng.org/doc/documentation-main.html#annotations

Will it solve the issue?

@markdbullock
Copy link
Author

Added the following annotation to all three classes plus the abstract class.
@test(singleThreaded=true)
It doesn't solve the problem.

@markdbullock
Copy link
Author

I also tested making the base class concrete and making the Test classes not extend a class.
The problem still exists in both cases.

@juherr
Copy link
Member

juherr commented Oct 27, 2016

Looks similar to #89

krmahadevan added a commit to krmahadevan/testng that referenced this issue May 14, 2018
Closes testng-team#89, testng-team#1050, testng-team#1066, testng-team#1173, testng-team#1185

This PR aims at assuring that methods that fall
under the below two use cases, all run on the 
same thread when classes are being run in parallel:

* @test methods in a class are ordered by priority
* @test methods have a single dependency on 
another method using “dependsOnMethods” attribute.

The thread affinity feature is supposed to be 
“experimental” and it can be turned on via the
JVM argument : -Dtestng.thread.affinity=true

This feature is turned off by default just to 
ensure that we don’t have any users experiencing
un-usual behavior.
krmahadevan added a commit to krmahadevan/testng that referenced this issue May 14, 2018
Closes testng-team#89, testng-team#1050, testng-team#1066, testng-team#1173, testng-team#1185

This PR aims at assuring that methods that fall
under the below two use cases, all run on the 
same thread when classes are being run in parallel:

* @test methods in a class are ordered by priority
* @test methods have a single dependency on 
another method using “dependsOnMethods” attribute.

The thread affinity feature is supposed to be 
“experimental” and it can be turned on via the
JVM argument : -Dtestng.thread.affinity=true

This feature is turned off by default just to 
ensure that we don’t have any users experiencing
un-usual behavior.
krmahadevan added a commit to krmahadevan/testng that referenced this issue May 15, 2018
Closes testng-team#89, testng-team#1050, testng-team#1066, testng-team#1173, testng-team#1185

This PR aims at assuring that methods that fall
under the below two use cases, all run on the 
same thread when classes are being run in parallel:

* @test methods in a class are ordered by priority
* @test methods have a single dependency on 
another method using “dependsOnMethods” attribute.

The thread affinity feature is supposed to be 
“experimental” and it can be turned on via the
JVM argument : -Dtestng.thread.affinity=true

This feature is turned off by default just to 
ensure that we don’t have any users experiencing
un-usual behavior.
@krmahadevan
Copy link
Member

Fixed by #1783.

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

6 participants
@juherr @krmahadevan @dr29bart @markdbullock @aksharpanchal and others