Skip to content

Commit 27d34fd

Browse files
committed
Port over cached thread pool changes into Framework.
1 parent 9d8061c commit 27d34fd

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

scalatest-test/src/test/scala/org/scalatest/tools/FrameworkSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ class FrameworkSuite extends FunSuite {
10961096
assert(iae.getMessage === "-P without specifying <numthreads> is not supported when running ScalaTest from sbt, please use sbt parallel configuration instead.")
10971097
}
10981098

1099-
test("Framework.runner accept without problem when -P 4 is passed in") {
1099+
test("Framework.runner accept without problem when -P4 is passed in") {
11001100
framework.runner(Array("-P4"), Array.empty, testClassLoader)
11011101
}
11021102

scalatest/src/main/scala/org/scalatest/tools/Framework.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,11 @@ class Framework extends SbtFramework {
698698
else
699699
concurrentConfig.numThreads
700700

701-
val execSvc: ExecutorService = Executors.newFixedThreadPool(poolSize, threadFactory)
701+
val execSvc: ExecutorService =
702+
if (poolSize > 0)
703+
Executors.newFixedThreadPool(poolSize, threadFactory)
704+
else
705+
Executors.newCachedThreadPool(threadFactory)
702706

703707
private def createTask(td: TaskDef): ScalaTestTask =
704708
new ScalaTestTask(

scalatest/src/main/scala/org/scalatest/tools/Runner.scala

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,11 @@ private[tools] case class SlowpokeConfig(delayInMillis: Long, periodInMillis: Lo
153153
* <tr><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center"><code>-R <em>&lt;runpath elements&gt;</em></code></td><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">the <a href="#specifyingARunpath">specifies the <em>runpath</em></a> from which tests classes will be<br/>discovered and loaded (Note: only one <code>-R</code> allowed)</td><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center"><em>Unix</em>: <code>-R target/classes:target/generated/classes</code><br/><em>Windows</em>: <code>-R target\classes;target\generated\classes</code></td></tr>
154154
* <tr><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center"><code>-n <em>&lt;tag name&gt;</em></code></td><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center"><a href="#specifyingTagsToIncludeAndExclude">specifies a tag to include</a> (Note: only one tag name allowed per <code>-n</code>)</td><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center"><code>-n UnitTests -n FastTests</code></td></tr>
155155
* <tr><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center"><code>-l <em>&lt;tag name&gt;</em></code></td><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center"><a href="#specifyingTagsToIncludeAndExclude">specifies a tag to exclude</a> (Note: only one tag name allowed per <code>-l</code>)</td><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center"><code>-l SlowTests -l PerfTests</code></td></tr>
156+
<<<<<<< HEAD
156157
* <tr><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center"><code>-P<em>[CS][integer thread count]</em></code></td><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center"><a href="#executingSuitesInParallel">specifies a parallel run</a>, with optional cached thread pool, suite sorting and thread count<br/>(Note: only one <code>-P</code> allowed)</td><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center"><code>-P</code>, <code>-PS</code>, <code>-PS8</code>, <code>-P8</code>, <code>-PC</code> <em>or</em> <code>-PCS</code>. Negative or zero number of thread count is not allowed.</td></tr>
158+
=======
159+
* <tr><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center"><code>-P<em>[S][integer thread count]</em></code></td><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center"><a href="#executingSuitesInParallel">specifies a parallel run</a>, with optional suite sorting and thread count<br/>(Note: only one <code>-P</code> allowed)</td><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center"><code>-P</code>, <code>-PS</code>, <code>-PS8</code>, <code>-P8</code>, <code>-PS-8</code> <em>or</em> <code>-PS-8</code>. Specify a negative number if you would like to use Executors.newCachedThreadPool.</td></tr>
160+
>>>>>>> 4bf710921... Made -P to accept negative thread count, which when passed in will use Executors.newCachedThreadPool.
157161
* <tr><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center"><code>-s <em>&lt;suite class name&gt;</em></code></td><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">specifies a <a href="#executingSuites">suite class</a> to run</td><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center"><code>-s com.company.project.StackSpec</code></td></tr>
158162
* <tr><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center"><code>-m <em>&lt;members-only package&gt;</em></code></td><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">requests that suites that are <a href="#membersOnlyWildcard">direct members of the specified package</a><br/> be discovered and run</td><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center"><code>-m com.company.project</code></td></tr>
159163
* <tr><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center"><code>-w <em>&lt;wildcard package&gt;</em></code></td><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">requests that suites that are <a href="#membersOnlyWildcard">members of the specified package or its subpackages</a><br/>be discovered and run</td><td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center"><code>-w com.company.project</code></td></tr>
@@ -1248,8 +1252,10 @@ object Runner {
12481252
// Because some tests may do IO, will create a pool of 2 times the number of processors reported
12491253
// by the Runtime's availableProcessors method.
12501254
val poolSize =
1251-
if (concurrentConfig.numThreads > 0) concurrentConfig.numThreads
1252-
else Runtime.getRuntime.availableProcessors * 2
1255+
if (concurrentConfig.numThreads == 0)
1256+
Runtime.getRuntime.availableProcessors * 2
1257+
else
1258+
concurrentConfig.numThreads
12531259

12541260
val distributedSuiteSorter =
12551261
if (concurrentConfig.enableSuiteSortingReporter)
@@ -1272,7 +1278,11 @@ object Runner {
12721278
thread
12731279
}
12741280
}
1275-
val execSvc: ExecutorService = Executors.newFixedThreadPool(poolSize, threadFactory)
1281+
val execSvc: ExecutorService =
1282+
if (poolSize > 0)
1283+
Executors.newFixedThreadPool(poolSize, threadFactory)
1284+
else
1285+
Executors.newCachedThreadPool(threadFactory)
12761286
try {
12771287

12781288
val distributor = new ConcurrentDistributor(Args(dispatch, stopper, Filter(if (tagsToIncludeSet.isEmpty) None else Some(tagsToIncludeSet), tagsToExcludeSet), configMap, None, tracker, chosenStyleSet, false, None, None), execSvc)

0 commit comments

Comments
 (0)