Skip to content

Commit 18721ea

Browse files
committed
[nomerge] Cleanup threads created by parallel collections tests
1 parent 71f9b43 commit 18721ea

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

build.sbt

+3
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,9 @@ lazy val scalacheck = project.in(file("test") / "scalacheck")
581581
.settings(
582582
fork in Test := false,
583583
javaOptions in Test += "-Xss1M",
584+
testOptions += Tests.Cleanup { loader =>
585+
ModuleUtilities.getObject("scala.TestCleanup", loader).asInstanceOf[Runnable].run()
586+
},
584587
libraryDependencies ++= Seq(scalacheckDep),
585588
unmanagedSourceDirectories in Compile := Nil,
586589
unmanagedSourceDirectories in Test := List(baseDirectory.value)

test/scalacheck/scala/pc.scala

+14-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,21 @@ class ParCollProperties extends Properties("Parallel collections") {
3838
val ectasks = new collection.parallel.ExecutionContextTaskSupport(ec)
3939
includeAllTestsWith(ectasks, "ectasks")
4040

41-
// no post test hooks in scalacheck, so cannot do:
42-
// ec.shutdown()
41+
// no post test hooks in scalacheck, so the best we can do is:
42+
TestCleanup.register(ec.shutdown())
43+
}
44+
4345

46+
object TestCleanup extends Runnable {
47+
private val cleanups = scala.collection.mutable.Buffer[() => Unit]()
48+
def register(action: => Any) = synchronized {
49+
cleanups += {() => action}
50+
}
51+
// called by the SBT build. Scalacheck doesn't have any native support for cleanup
52+
override def run(): Unit = {
53+
cleanups.foreach(_.apply())
54+
cleanups.clear()
55+
}
4456
}
4557

4658
/*

0 commit comments

Comments
 (0)