Skip to content

Commit 80cad6f

Browse files
committed
Merge branch 'feature-3.1-cache-thread-pool' of https://github.com/cheeseng/scalatest into cheeseng-feature-3.1-cache-thread-pool
2 parents 3086547 + a5bd1a2 commit 80cad6f

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-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: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,8 +1248,10 @@ object Runner {
12481248
// Because some tests may do IO, will create a pool of 2 times the number of processors reported
12491249
// by the Runtime's availableProcessors method.
12501250
val poolSize =
1251-
if (concurrentConfig.numThreads > 0) concurrentConfig.numThreads
1252-
else Runtime.getRuntime.availableProcessors * 2
1251+
if (concurrentConfig.numThreads == 0)
1252+
Runtime.getRuntime.availableProcessors * 2
1253+
else
1254+
concurrentConfig.numThreads
12531255

12541256
val distributedSuiteSorter =
12551257
if (concurrentConfig.enableSuiteSortingReporter)
@@ -1272,7 +1274,11 @@ object Runner {
12721274
thread
12731275
}
12741276
}
1275-
val execSvc: ExecutorService = Executors.newFixedThreadPool(poolSize, threadFactory)
1277+
val execSvc: ExecutorService =
1278+
if (poolSize > 0)
1279+
Executors.newFixedThreadPool(poolSize, threadFactory)
1280+
else
1281+
Executors.newCachedThreadPool(threadFactory)
12761282
try {
12771283

12781284
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)