-
Notifications
You must be signed in to change notification settings - Fork 939
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Third draft to execute the forked tests in parallel.
This feature is not activated by default. To enable it set `testForkedParallel` to `true`. The test-agent then executes the tests in a thread pool. For now it has a fixed size set to the number of available processors. The concurrent restrictions configuration should be used.
- Loading branch information
1 parent
67c879b
commit 4bb0873
Showing
11 changed files
with
289 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
sbt/src/sbt-test/tests/fork-parallel/project/ForkParallelTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import sbt._ | ||
import Keys._ | ||
import Tests._ | ||
import Defaults._ | ||
|
||
object ForkParallelTest extends Build { | ||
val check = taskKey[Unit]("Check that tests are executed in parallel") | ||
|
||
lazy val root = Project("root", file("."), settings = defaultSettings ++ Seq( | ||
scalaVersion := "2.9.2", | ||
libraryDependencies += "com.novocode" % "junit-interface" % "0.10" % "test", | ||
fork in Test := true, | ||
check := { | ||
if( ! (file("max-concurrent-tests_3").exists() || file("max-concurrent-tests_4").exists() )) { | ||
sys.error("Forked tests were not executed in parallel!") | ||
} | ||
} | ||
)) | ||
} |
53 changes: 53 additions & 0 deletions
53
sbt/src/sbt-test/tests/fork-parallel/src/test/scala/tests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
import java.io.File | ||
import java.util.concurrent.atomic.AtomicInteger | ||
import org.junit.Test | ||
import scala.annotation.tailrec | ||
|
||
object ParallelTest { | ||
val nbConcurrentTests = new AtomicInteger(0) | ||
val maxConcurrentTests = new AtomicInteger(0) | ||
|
||
private def updateMaxConcurrentTests(currentMax: Int, newMax: Int) : Boolean = { | ||
if( maxConcurrentTests.compareAndSet(currentMax, newMax) ) { | ||
val f = new File("max-concurrent-tests_" + newMax) | ||
f.createNewFile | ||
true | ||
} else { | ||
false | ||
} | ||
} | ||
|
||
@tailrec | ||
def execute(f : => Unit) { | ||
val nb = nbConcurrentTests.incrementAndGet() | ||
val max = maxConcurrentTests.get() | ||
if( nb <= max || updateMaxConcurrentTests(max, nb)) { | ||
f | ||
nbConcurrentTests.getAndDecrement | ||
} else { | ||
nbConcurrentTests.getAndDecrement | ||
execute(f) | ||
} | ||
} | ||
} | ||
|
||
class Test1 { | ||
@Test | ||
def slow() { ParallelTest.execute { Thread.sleep(1000) } } | ||
} | ||
|
||
class Test2 { | ||
@Test | ||
def slow() { ParallelTest.execute { Thread.sleep(1000) } } | ||
} | ||
|
||
class Test3 { | ||
@Test | ||
def slow() { ParallelTest.execute { Thread.sleep(1000) } } | ||
} | ||
|
||
class Test4 { | ||
@Test | ||
def slow() { ParallelTest.execute { Thread.sleep(1000) } } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
> test | ||
-> check | ||
|
||
> clean | ||
> set testForkedParallel := true | ||
> test | ||
> check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package sbt; | ||
|
||
import java.io.Serializable; | ||
|
||
public final class ForkConfiguration implements Serializable { | ||
private boolean ansiCodesSupported; | ||
private boolean parallel; | ||
|
||
public ForkConfiguration(boolean ansiCodesSupported, boolean parallel) { | ||
this.ansiCodesSupported = ansiCodesSupported; | ||
this.parallel = parallel; | ||
} | ||
|
||
public boolean isAnsiCodesSupported() { | ||
return ansiCodesSupported; | ||
} | ||
|
||
public boolean isParallel() { | ||
return parallel; | ||
} | ||
} |
Oops, something went wrong.