-- Виталий
Are there any plans to implement this in the near future?
I agree it would be a huge improvement for data based testing.
-- Erik Putrycz, Ph.D - http://blog.erikputrycz.net - Mobile: 613-286-6365
I would suggest making the threadpool size the number of CPUs by default.
And could this parameter be on the @Test directly and use a "global" thread pool for all testng?
On Wed, Apr 8, 2009 at 12:37 PM, Erik Putrycz <erik.p...@gmail.com> wrote:
I would suggest making the threadpool size the number of CPUs by default.
And could this parameter be on the @Test directly and use a "global" thread pool for all testng?
It seems to make more sense to put this attribute on @DataProvider but I haven't really thought about the pros of cons of each approach. What are your thoughts?
As for the global pool, I think it's a bit tricky from an implementation perspective since I'm not sure it's possible to start an ExecutorService with a set of tasks, make it block until all the threads terminate and while it's waiting, add more tasks to it.
My concern is if you end up running in parallel n tests with each a @DataProvider with 10 threads - you end up with n * 10 threads. Having the thread count on data provider or global isn't so much the issue, it is rather to limit the number of threads.
Another reason would be to keep things simple. In the end, I'd like to be able to simply say @DataProvider(parallel = true) instead of the number of threads - which is not necessarily something easy to figure out when you write a test.
I did quite a bit of work with the concurrent API. Until you don't call shutdown on the ThreadPoolExecutor, you can still submit new tasks. However, I don't remember exactly if I figured out a good way to wait for the tasks to terminate - I'll need to check. In the end, I ended up redesigning all concurrent stuff in my application with Scala and actors.
The main problem here is to know when to exit. For example, let's say we start by running a DataProvider that returns 3 results, so 3 threads get allocated. Then another DataProvider returns 5 results, 5 more threads get allocated.
That is easier. invokeAll <http://java.sun.com/javase/6/docs/api/java/util/concurrent/ExecutorService.html#invokeAll(java.util.Collection)> blocks until all the child threads have run. Its sister method will terminate early if a timeout expires.
Now, here is the execution with "maximal threading": test thread on (parallel="methods") and data provider threading on:Thread:16 f(2)
Thread:15 f2(13)
Thread:14 f2(12)
Thread:12 f2(11)
Thread:17 f(3)
Thread:13 f(1)
Thread:15 f2(14)
Thread:17 f(4)
This time, each method is invoked in its own thread and in turn, each data provider invocation is running in its own thread, so we are seeing 2*3=6 threads in action. Both the methods and the values they receive are interleaved.