mirror of https://github.com/sbt/sbt.git
Add test for async utest TestSuites
Sometimes when utest runs async tests (i.e. tests that return a future) the test suite will fail even when none of the individual tests do. This is due to a data race in sbt. Most, but not all, of the time, this test will induce that race.
This commit is contained in:
parent
c6df309073
commit
8eb2d7389d
|
|
@ -0,0 +1,8 @@
|
|||
testFrameworks += new TestFramework("utest.runner.Framework")
|
||||
|
||||
lazy val root = (project in file(".")).
|
||||
settings(
|
||||
scalaVersion := "2.12.4",
|
||||
libraryDependencies += "com.lihaoyi" %% "utest" % "0.6.4" % Test,
|
||||
fork in Test := true
|
||||
)
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
import utest._
|
||||
|
||||
import utest._
|
||||
import utest.framework._
|
||||
|
||||
import scala.concurrent.{ ExecutionContext, Promise }
|
||||
import scala.util.Success
|
||||
|
||||
object ForkAsyncTest extends TestSuite {
|
||||
val g = ExecutionContext.global
|
||||
val n = 10
|
||||
val (testNames, promises) = (1 to n).map(i => Tree(s"$i") -> Promise[Unit]).unzip
|
||||
val testTrees = promises.zipWithIndex.map { case (p, i) =>
|
||||
new TestCallTree(Left {
|
||||
if (i == (n - 1)) promises.foreach(p => g.execute(() => p.tryComplete(Success(()))))
|
||||
p.future
|
||||
})
|
||||
}
|
||||
val tests =
|
||||
Tests(nameTree = Tree("async", testNames: _*), callTree = new TestCallTree(Right(testTrees)))
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
> test
|
||||
Loading…
Reference in New Issue