-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Total thread count in testng parallel tests with dataproviders #2019
Comments
Yes, it is something we can do. |
Seems like you could just modify the Invoker class and change this code: // For invocationCount > 1 and threadPoolSize > 1 run this method in its own pool thread. Add a new conditional for shared thread pool so that data provider tests would also go through this code and share the main threadpool. |
@enivid would you be willing to submit a pull request with this change ? |
I looked at this a bit more and I don't see an easy fix. The TestRunner class is creating the ExecutorService with the thread limit. You'd now have to pass a reference to the ExecutorService down to the TestInvoker so it can use that ExecutorService instead of creating its own executor when running parallel dataproviders or tests with multiple invocation counts. |
Maybe instead of refactoring everything, the easiest thing to do is just make a new BlockingQueue. The BlockingQueue will have a fixed size to how many tests you want running. Now testng can create as many threads as it wants but its still going to limit how many tests run at a time. You could add this into TestNg itself or just make your own ITestListener. You can use the start and finish methods to add and remove from your BlockingQueue. |
Can we setup higher priority for that?
|
Hey @krmahadevan , may I ask is it still on the roadmap? since it's very hard to control the count of threads when I enable method parallel and dataprovider parallel. Better we could have a Max number all threads. |
@xuanzhaopeng Yes this is on the radar. But yet to get to it due to bandwidth issues. Would you be willing to help raise a PR for this ? |
@krmahadevan Is this something that is still going to be worked on?? |
@Dinhbaon - There is plan to get this sorted out. But I haven't been able to get to this yet. Would you like to raise a PR ? |
@krmahadevan @ajmera25 @juherr Is this resolved? If Yes can anyone explain this a bit how can we use it? I am also stuck with a similar problem where I need global thread-count. |
@avishkargautam77 Please refer to https://testng.org/#_controlling_threadpool_usage |
@krmahadevan For example, when I use use-global-thread-count=true and set thread-count=2, with a testng.xml containing two tests—one using a DataProvider with two datasets and the other without any DataProvider—three threads are being initialized. Could you explain why this happens, and is there any way to restrict the thread usage to exactly 2? |
Pls share the following:
|
Also please go through the documentation. There is a flag called useGlobalThreadPool which ensures TestNG uses one thread pool for data driven and non data driven tests ( by default its two different pools ) There is another flag called shareThreadPoolForDataProviders which ensures that all data driven tests in your suite share the same thread pool. |
@krmahadevan <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.1.dtd">
<suite name="XML -Job Suite" thread-count="2" parallel="tests" share-thread-pool-for-data-providers="true">
<listeners>
<listener class-name="com.qa.ExtentReportListener.ExtentReporterNG" />
</listeners>
<test name="Appointment Test Cases-done 1">
<classes>
<class name="com.crm.qa.testcases.AppointmentPageTest">
<methods>
<include name="addAppointment" />
</methods>
</class>
</classes>
</test>
<test name="All Assigned Candidate Page Test Case-11">
<classes>
<class name="com.crm.qa.testcases.AllAssignedCandidatesPageTest">
<methods>
<include name="bulkEmailToCandidateInAllAssignedCandidateListView" />
</methods>
</class>
</classes>
</test>
</suite> Testcases Being Executed: @Test(dataProvider = "getAppointmentDetails")
public void addAppointment(String relatedTo) {
// ... (rest of the test code)
}
@Test
public void bulkEmailToCandidateInAllAssignedCandidateListView() {
// ... (test code)
}
@DataProvider(parallel = true)
public Object[][] getAppointmentDetails() {
return new Object[][] { { "Data1" }, { "Data2" } };
} Testng Version: 7.9.0 |
Please include the xml here instead of the google drive link. Also please try using the latest released version 7.10.2 |
@krmahadevan Let me try. |
Tried with 7.10.2 as well, this still persists. |
I am not sure I understand what the problem is. You have specified this in your suite file <suite name="XML -Job Suite" thread-count="2" parallel="tests" share-thread-pool-for-data-providers="true"> What this means is as below:
So with these in place, you should basically see that at any given point in time irrespective of how many ever data driven tests exist in your suite file, ONLY I am quoting the documentation once again for your reference
|
@krmahadevan , Let me try to make this more clear. What’s actually happening: |
@avishkargautam77 - When you enable <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.1.dtd">
<suite name="XML -Job Suite"
verbose="2"
thread-count="3"
parallel="methods"
use-global-thread-pool="true">
<test name="combined">
<classes>
<class name="com.rationaleemotions.DataDrivenTestCase"/>
<class name="com.rationaleemotions.NormalTestCase"/>
</classes>
</test>
</suite> |
Also please note that this feature is not immune to issues especially when there are data driven tests involved because of the current design of TestNG (TestNG tries to submit additional data driven test tasks from within a data driven test after it figures out that it is dealing with a data driven test, whereas TestNG should first expand a data driven test into n tests and then submit them and implementing this will take time since a lot of internal design would need to be changed). |
TestNG Version
7.0.0-beta3
Expected behavior
Need to have Global thread count so that we can control total thread when we have x number of thread-count and x number of data provider thread count.
Actual behavior
Let say,If we have 10 thread count and 10 data provider thread count then we will end up running 100 thread.
I am not reporting this is as a bug. Created this issue so that it will kick off the discussion around this and if it can be considered as a feature request.
https://groups.google.com/forum/#!topic/testng-users/BKfSgHoAChU
Is the issue reproducible on runner?
Yes
The text was updated successfully, but these errors were encountered: