mirror of https://github.com/sbt/sbt.git
Tag the actual test task and not a later task. Fixes #692.
This commit is contained in:
parent
77310ac2b6
commit
54b103f4c7
|
|
@ -121,7 +121,7 @@ object Tests
|
|||
}
|
||||
type TestRunnable = (String, () => TestResult.Value)
|
||||
def makeParallel(runnables: Iterable[TestRunnable], setupTasks: Task[Unit], tags: Seq[(Tag,Int)]) =
|
||||
runnables map { case (name, test) => task { (name, test()) } dependsOn setupTasks named name tagw(tags : _*) }
|
||||
runnables map { case (name, test) => task { (name, test()) } tagw(tags : _*) dependsOn setupTasks named name }
|
||||
def makeSerial(runnables: Seq[TestRunnable], setupTasks: Task[Unit], tags: Seq[(Tag,Int)]) =
|
||||
task { runnables map { case (name, test) => (name, test()) } } dependsOn(setupTasks)
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
object Counter {
|
||||
private[this] val Name = "test.count"
|
||||
|
||||
// synchronize on Predef because that is shared between the subprojects
|
||||
def get = Predef.synchronized { System.getProperty(Name, "0").toInt }
|
||||
|
||||
def add(i: Int) = Predef.synchronized {
|
||||
val count = get + i
|
||||
System.setProperty(Name, count.toString)
|
||||
count
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
public class Dummy {
|
||||
public static final Dummy d = new Dummy();
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import sbt._
|
||||
import Keys._
|
||||
|
||||
object SomeBuild extends Build {
|
||||
val buildSettings = Seq(
|
||||
organization := "com.softwaremill",
|
||||
version := "0.0.1-SNAPSHOT",
|
||||
scalaVersion := "2.10.0",
|
||||
libraryDependencies += "org.scalatest" %% "scalatest" % "1.9.1" % "test"
|
||||
)
|
||||
|
||||
lazy val parent: Project = Project("root", file("."), aggregate = Seq(sub1,sub2)).settings(buildSettings : _*)
|
||||
|
||||
lazy val sub1: Project = Project("sub1", file("sub1")).settings(buildSettings : _*).dependsOn(parent)
|
||||
lazy val sub2: Project = Project("sub2", file("sub2")).settings(buildSettings : _*).dependsOn(parent)
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import org.scalatest._
|
||||
import java.util.Date
|
||||
|
||||
class Test1 extends FlatSpec {
|
||||
it should "work" in {
|
||||
val start = Counter.add(13)
|
||||
println(s"Starting test 1 ($start)...")
|
||||
|
||||
Thread.sleep(2000L)
|
||||
|
||||
val end = Counter.get
|
||||
println(s"Test 1 done ($end)")
|
||||
|
||||
assert(end == start, s"Expected Counter to stay at $start, but it changed to $end")
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import org.scalatest._
|
||||
import java.util.Date
|
||||
|
||||
class Test2 extends FlatSpec {
|
||||
it should "work" in {
|
||||
val start = Counter.add(7)
|
||||
println(s"Starting test 2 ($start)...")
|
||||
|
||||
Thread.sleep(5000L)
|
||||
|
||||
val end = Counter.get
|
||||
println(s"Test 2 done ($end)")
|
||||
|
||||
assert(end == start, s"Expected Counter to stay at $start, but it changed to $end")
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
# This verifies that the tests would normally execute concurrently if not
|
||||
# for the restrictions defined later below. However, it will only fail
|
||||
# if the tests are actually executed concurrently. The default concurrent
|
||||
# restrictions limit the number of concurrent tasks to the number of processors,
|
||||
# so we set it to 2.
|
||||
> set concurrentRestrictions in Global := Seq(Tags.limitAll(2))
|
||||
-> test
|
||||
|
||||
# this should prevent concurrent execution of tests
|
||||
> set concurrentRestrictions in Global += Tags.limit(Tags.Test, 1)
|
||||
> test
|
||||
Loading…
Reference in New Issue