Limiting the number of parallel tests with ThreadCount TestNG

醉酒当歌 提交于 2021-02-19 04:29:08

问题


I have a head scratcher here and I do not know how to handle this. I have several test classes that run via xml. Around 90 test classes, each with about 10+ @Test steps inside them. I have a selenium grid configued, with a maxSession=5 so no more than 5 parallel browser instances can run parallel on a single node. Heres the part I do NOT understand. Lets say I kick off this xml file with all of these test classes, I set my thread-count=10 hoping that 10 tests will kick off at a time. What happens is ALL of my test classes start, they dont wait in a queue (as I thought setting a thread-count to 10 would do) and they skip, timeout, fail, whatever. I understand how maxSession can handle what gets run on the grid, but when the xml is kicked off how can I limit the the number of test classes starting so I dont overload the grid!


回答1:


you can use parallel attribute to set parallel classes.

<suite name="Example" verbose="0" thread-count="5" parallel="classes"> 
...
</suite>

The other important point here is, do you have your implementation threadsafe? If not then it will not work properly.




回答2:


Actually testNG can create much more threads than defined in thread-count. This happens in next cases (list is not exact):

  • you have @DataProvider with parallel=true. Each invoked provider can occupy up to dataproviderthreadcount additional threads (so with thread-count=10 and dataproviderthreadcount = 5 you'll have up to 50 threads)
  • you have @Test with threadPoolSize > 1 and invocationCount > 1. Each such test will add min(threadPoolSize, invocationCount) threads.

Also be careful with timeout for web-driver tests on grid. Because when you call

WebDriver wd = new RemoteWebDriver(...);

this will pause your test execution until grid-hub will have free node for you (by default hub waits forever, see newSessionWaitTimeout parameter). So even if 'active' phase of you tests takes only 120sec, total test duration can be much more (depends on grid load, on structure of your test classes, execution order etc)



来源:https://stackoverflow.com/questions/37304962/limiting-the-number-of-parallel-tests-with-threadcount-testng

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!