Skip to content

Commit 185a34b

Browse files
committed
Add simple parallelism
1 parent 944e1ea commit 185a34b

File tree

3 files changed

+43
-44
lines changed

3 files changed

+43
-44
lines changed
Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,61 @@
11
package dotty.tools.languageserver
22

33
import org.junit.Test
4-
54
import java.lang.reflect.InvocationTargetException
5+
import java.util.concurrent.TimeUnit
6+
7+
import scala.concurrent.{Await, Future}
8+
import scala.concurrent.duration.Duration
9+
import scala.concurrent.ExecutionContext.Implicits.global
610

711
// TODO remove this and use JUnit to run the tests
812
object Main {
913
def main(args: Array[String]): Unit = {
10-
var testsFailed = 0
11-
for (clazz <- testsClasses) {
12-
val t0 = System.currentTimeMillis()
13-
var passed = 0
14-
var failed = 0
15-
println(s"Starting tests in ${clazz.getSimpleName}")
16-
for (method <- clazz.getMethods.sortBy(_.getName)) {
17-
if (method.getAnnotation(classOf[Test]) ne null) {
18-
print(s"Testing $clazz.${method.getName} ")
19-
try {
20-
method.invoke(clazz.getConstructor().newInstance())
21-
println(Console.GREEN + "passed" + Console.RESET)
22-
passed += 1
23-
} catch {
24-
case ex: InvocationTargetException =>
25-
ex.getCause match {
26-
case ex1: AssertionError =>
27-
println(Console.RED + "failed" + Console.RESET)
28-
System.err.println(s"${method.getName} failed with")
29-
ex1.printStackTrace()
30-
failed += 1
31-
case _ => throw ex.getCause
32-
}
33-
}
14+
var failed = 0
15+
var passed = 0
16+
val tests =
17+
for {
18+
clazz <- testsClasses
19+
method <- clazz.getMethods.sortBy(_.getName)
20+
if method.getAnnotation(classOf[Test]) ne null
21+
} yield {
22+
Future {
23+
println(s"Testing ${clazz.getCanonicalName}.${method.getName} ")
24+
try {
25+
method.invoke(clazz.getConstructor().newInstance())
26+
println(s"Testing ${clazz.getCanonicalName}.${method.getName} " + Console.GREEN + "passed" + Console.RESET)
27+
passed += 1
28+
} catch {
29+
case ex: InvocationTargetException =>
30+
ex.getCause match {
31+
case ex1: AssertionError =>
32+
println(s"Testing ${clazz.getCanonicalName}.${method.getName} " + Console.RED + "failed" + Console.RESET)
33+
System.err.println(s"${method.getName} failed with")
34+
ex1.printStackTrace()
35+
failed += 1
36+
case _ => throw ex.getCause
37+
}
38+
}
3439
}
3540
}
3641

37-
val time = (System.currentTimeMillis() - t0).toDouble / 1000
42+
Await.ready(Future.sequence(tests), Duration.Inf)
3843

39-
if (failed == 0) {
40-
println(s"${Console.GREEN}Passed all $passed tests${Console.RESET} in ${time}s")
41-
} else {
42-
testsFailed += 1
43-
System.err.println(s"Passed $passed, ${Console.RED}failed $failed${Console.RESET}, total ${passed + failed} in ${time}s")
44-
}
45-
println()
46-
}
47-
if (testsFailed != 0) {
48-
System.err.println(s"Failed $testsFailed tests")
44+
if (failed != 0) {
45+
System.err.println(s"Failed $failed tests")
4946
System.exit(1)
5047
}
48+
println(Console.GREEN + s"Passed all $passed tests" + Console.RESET)
5149
}
5250

5351
private def testsClasses = List(
52+
classOf[SymbolTest],
53+
classOf[RenameTest],
54+
classOf[ReferencesTest],
55+
classOf[DocumentSymbolTest],
56+
classOf[DefinitionTest],
5457
classOf[HighlightTest],
5558
classOf[CompletionTest],
56-
classOf[DefinitionTest],
5759
classOf[HoverTest],
58-
classOf[ReferencesTest],
59-
classOf[RenameTest],
60-
classOf[DocumentSymbolTest],
61-
classOf[SymbolTest],
6260
)
6361
}

language-server/test/dotty/tools/languageserver/util/CodeTester.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package dotty.tools.languageserver.util
22

3+
import java.nio.file.Paths
4+
35
import dotty.tools.languageserver.util.Code.SourceWithPositions
46
import dotty.tools.languageserver.util.actions._
57
import dotty.tools.languageserver.util.embedded.CodeMarker
68
import dotty.tools.languageserver.util.server.{TestFile, TestServer}
7-
import org.eclipse.lsp4j.SymbolInformation
89

910
class CodeTester(sources: List[SourceWithPositions], actions: List[Action]) {
1011

language-server/test/dotty/tools/languageserver/util/server/TestFile.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ class TestFile(val file: String) extends AnyVal {
99
}
1010

1111
object TestFile {
12-
lazy val testDir: Path = Paths.get("../out/ide-tests").toAbsolutePath
13-
lazy val sourceDir: Path = testDir.resolve("src")
12+
val testDir: Path = Paths.get("../out/ide-tests").toAbsolutePath
13+
val sourceDir: Path = testDir.resolve("src")
1414
}

0 commit comments

Comments
 (0)