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:
Ethan Atkins 2018-03-21 10:16:01 -07:00
parent c6df309073
commit 8eb2d7389d
3 changed files with 30 additions and 0 deletions

View File

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

View File

@ -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)))
}

View File

@ -0,0 +1 @@
> test