Parallel Test Execution with Gradle maxParallelForks property
<p><em>I have been searching for the answers last few days and unable to find one. The closest answer I could find is <a href="https://discuss.gradle.org/t/not-using-all-test-executors-when-executing-junit-tests-filtered-by-the-category-annotation/12855" rel="noreferrer">this</a> which does not exactly answer the questions I have.</em></p>
<p>By the way, I have a Selenium Test Project which is based on Gradle. We build the project on Jenkins run the tests in 20 concurrent threads. Total number of unique test classes I have is 87. So, I expect gradle to exeute at least 5 batches The test project is build using Cucumber JVM, build and triggers tests by Jenkins to Selenium Hub. I tried to increase the parallelism of the tests by utilizing the grid as much as possible. But, the problem started when the number of tests started growing.</p>
<p>When I started the tests from Jenkins, I observed at first shot the test executed all 20 test processes and I see the second batch also started with same amount of processes. After the second batch the processes went back to single mode and the entire job took 14 hours to complete which defeats the purpose of having parallel test execution.</p>
<p>Gradle properties:</p>
<pre><code>jvmArgs '-Xms128m', '-Xmx1024m', '-XX:MaxPermSize=128m'
Runtime.runtime.availableProcessors().toString()) as int        
maxParallelForks =  PropertyUtils.getProperty('test.parallel', '15') as int
forkEvery =  PropertyUtils.getProperty('test.forkEvery', '0') as int
</code></pre>
<p>CLI:</p>
<pre><code>gradle clean test -Dtest.single=*TestRun --info
</code></pre>
<p>I have read all the documents I can possibly find but failed to get answer. It would be greatly appreciated if someone can help me with these questions</p>
<p><strong>1. How Gradle batch the test runner internally? For example if 20 executors starts and test 1,2,3 done executing faster than the others, do the three executors gets three more test classes or waits for the entire batch to finish executing?</strong></p>
<p><em><strong>2. Can forkEvery impact how the execution works during parallel testing?</strong></em></p>
<p>Jenkins log</p>
<blockquote>
<p>Successfully started process 'Gradle Test Executor 6'</p>
<p>Successfully started process 'Gradle Test Executor 13'</p>
<p>Successfully started process 'Gradle Test Executor 14'</p>
<p>Successfully started process 'Gradle Test Executor 5'</p>
<p>Successfully started process 'Gradle Test Executor 16'</p>
<p>Successfully started process 'Gradle Test Executor 8'</p>
<p>Successfully started process 'Gradle Test Executor 19'</p>
<p>Successfully started process 'Gradle Test Executor 4'</p>
<p>Successfully started process 'Gradle Test Executor 2'</p>
<p>Successfully started process 'Gradle Test Executor 11'</p>
<p>Successfully started process 'Gradle Test Executor 10'</p>
<p>Successfully started process 'Gradle Test Executor 18'</p>
<p>Successfully started process 'Gradle Test Executor 1'</p>
<p>Successfully started process 'Gradle Test Executor 20'</p>
<p>Successfully started process 'Gradle Test Executor 7'</p>
<p>Successfully started process 'Gradle Test Executor 9'</p>
<p>Successfully started process 'Gradle Test Executor 3'</p>
<p>Successfully started process 'Gradle Test Executor 15'</p>
<p>Successfully started process 'Gradle Test Executor 17'</p>
<p>Successfully started process 'Gradle Test Executor 12'</p>
<p>Gradle Test Executor 13 started executing tests.</p>
<p>Gradle Test Executor 14 started executing tests.</p>
<p>Gradle Test Executor 6 started executing tests.</p>
<p>Gradle Test Executor 5 started executing tests.</p>
<p>Gradle Test Executor 16 started executing tests.</p>
<p>Gradle Test Executor 19 started executing tests.</p>
<p>Gradle Test Executor 8 started executing tests.</p>
<p>Gradle Test Executor 4 started executing tests.</p>
<p>Gradle Test Executor 2 started executing tests.</p>
<p>Gradle Test Executor 10 started executing tests.</p>
<p>Gradle Test Executor 11 started executing tests.</p>
<p>Gradle Test Executor 18 started executing tests.</p>
<p>Gradle Test Executor 1 started executing tests.</p>
<p>Gradle Test Executor 20 started executing tests.</p>
<p>Gradle Test Executor 7 started executing tests.</p>
<p>Gradle Test Executor 3 started executing tests.</p>
<p>Gradle Test Executor 9 started executing tests.</p>
<p>Gradle Test Executor 17 started executing tests.</p>
<p>Gradle Test Executor 15 started executing tests.</p>
<p>Gradle Test Executor 12 started executing tests.</p>
</blockquote>