diff --git a/main/actions/src/main/scala/sbt/Tests.scala b/main/actions/src/main/scala/sbt/Tests.scala index 7c33183fe..c6549e4e2 100644 --- a/main/actions/src/main/scala/sbt/Tests.scala +++ b/main/actions/src/main/scala/sbt/Tests.scala @@ -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) diff --git a/sbt/src/sbt-test/tests/serial/Counter.scala b/sbt/src/sbt-test/tests/serial/Counter.scala new file mode 100644 index 000000000..f7341df0c --- /dev/null +++ b/sbt/src/sbt-test/tests/serial/Counter.scala @@ -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 + } +} \ No newline at end of file diff --git a/sbt/src/sbt-test/tests/serial/Dummy.java b/sbt/src/sbt-test/tests/serial/Dummy.java new file mode 100644 index 000000000..5f536ab04 --- /dev/null +++ b/sbt/src/sbt-test/tests/serial/Dummy.java @@ -0,0 +1,3 @@ +public class Dummy { + public static final Dummy d = new Dummy(); +} diff --git a/sbt/src/sbt-test/tests/serial/project/Build.scala b/sbt/src/sbt-test/tests/serial/project/Build.scala new file mode 100644 index 000000000..fd4fb1c21 --- /dev/null +++ b/sbt/src/sbt-test/tests/serial/project/Build.scala @@ -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) +} diff --git a/sbt/src/sbt-test/tests/serial/sub1/src/test/scala/Test1.scala b/sbt/src/sbt-test/tests/serial/sub1/src/test/scala/Test1.scala new file mode 100644 index 000000000..8ada90a24 --- /dev/null +++ b/sbt/src/sbt-test/tests/serial/sub1/src/test/scala/Test1.scala @@ -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") + } +} \ No newline at end of file diff --git a/sbt/src/sbt-test/tests/serial/sub2/src/test/scala/Test2.scala b/sbt/src/sbt-test/tests/serial/sub2/src/test/scala/Test2.scala new file mode 100644 index 000000000..3d804713f --- /dev/null +++ b/sbt/src/sbt-test/tests/serial/sub2/src/test/scala/Test2.scala @@ -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") + } +} \ No newline at end of file diff --git a/sbt/src/sbt-test/tests/serial/test b/sbt/src/sbt-test/tests/serial/test new file mode 100644 index 000000000..a657fd48f --- /dev/null +++ b/sbt/src/sbt-test/tests/serial/test @@ -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