Skip to content

Commit 2b9c41a

Browse files
committed
Create processes lazily
As mentioned in [1]: > JUnit creates a new instance of the test class before invoking each > @test method. This helps provide independence between test methods and > avoids unintentional side effects in the test code. Because each test > method runs on a new test class instance, we can’t reuse instance > variable values across test methods. Each `@Test` method would create a new instance of the test classes, which means each `@Test` method would create N new processes. [1]: https://stackoverflow.com/questions/14010222/junit-new-instance-before-invoking-each-test-method-what-are-the-benefits
1 parent 7ca6a47 commit 2b9c41a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ trait RunnerOrchestration {
4949
def runMain(classPath: String)(implicit summaryReport: SummaryReporting): Status =
5050
monitor.runMain(classPath)
5151

52-
lazy private val monitor = new RunnerMonitor
52+
private val monitor = new RunnerMonitor
5353

5454
/** The runner monitor object keeps track of child JVM processes by keeping
5555
* them in two structures - one for free, and one for busy children.
@@ -167,14 +167,15 @@ trait RunnerOrchestration {
167167
.start()
168168
}
169169

170-
private val allRunners = List.fill(numberOfSlaves)(new Runner(createProcess))
171-
private val freeRunners = mutable.Queue(allRunners: _*)
170+
private val freeRunners = mutable.Queue.empty[Runner]
172171
private val busyRunners = mutable.Set.empty[Runner]
173172

174173
private def getRunner(): Runner = synchronized {
175-
while (freeRunners.isEmpty) wait()
174+
while (freeRunners.isEmpty && busyRunners.size >= numberOfSlaves) wait()
176175

177-
val runner = freeRunners.dequeue()
176+
val runner =
177+
if (freeRunners.isEmpty) new Runner(createProcess)
178+
else freeRunners.dequeue()
178179
busyRunners += runner
179180

180181
notify()
@@ -194,7 +195,9 @@ trait RunnerOrchestration {
194195
result
195196
}
196197

197-
private def killAll(): Unit = allRunners.foreach(_.kill())
198+
private def killAll(): Unit =
199+
freeRunners.foreach(_.kill())
200+
busyRunners.foreach(_.kill())
198201

199202
// On shutdown, we need to kill all runners:
200203
sys.addShutdownHook(killAll())

0 commit comments

Comments
 (0)