前面看到了TestRunner类中的privateRun方法,该方法中主要是根据配置决定走并发执行用例还是串行执行用例。因为我在测试过程中回归的时候一般都是并发执行testng.xml,所以今天先研究一下并发执行的具体过程,并发执行的代码如下,现在一行行的分析
if (parallel) {
if (graph.getNodeCount() > 0) {
GraphThreadPoolExecutor<ITestNGMethod> executor =
new GraphThreadPoolExecutor<>(graph, this,
threadCount, threadCount, 0, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>());
executor.run();
try {
long timeOut = m_xmlTest.getTimeOut(XmlTest.DEFAULT_TIMEOUT_MS);
Utils.log("TestRunner", 2, "Starting executor for test " + m_xmlTest.getName()
+ " with time out:" + timeOut + " milliseconds.");
executor.awaitTermination(timeOut, TimeUnit.MILLISECONDS);
executor.shutdownNow();