Skip to content

Commit

Permalink
NIT Move the BSP-related JMH tests to the JmhTests suite
Browse files Browse the repository at this point in the history
  • Loading branch information
Gedochao committed Aug 21, 2024
1 parent 974ebb8 commit bfc4133
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,54 +263,6 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
}
}

for {
useDirective <- Seq(None, Some("//> using jmh"))
directiveString = useDirective.getOrElse("")
jmhOptions = if (useDirective.isEmpty) Seq("--jmh") else Nil
testMessage = useDirective match {
case None => jmhOptions.mkString(" ")
case Some(directive) => directive
}
}
test(s"simple jmh ($testMessage)") {
val inputs = TestInputs(
os.rel / "benchmark.scala" ->
s"""$directiveString
|package bench
|
|import java.util.concurrent.TimeUnit
|import org.openjdk.jmh.annotations._
|
|@BenchmarkMode(Array(Mode.AverageTime))
|@OutputTimeUnit(TimeUnit.NANOSECONDS)
|@Warmup(iterations = 1, time = 100, timeUnit = TimeUnit.MILLISECONDS)
|@Measurement(iterations = 10, time = 100, timeUnit = TimeUnit.MILLISECONDS)
|@Fork(0)
|class Benchmarks {
|
| @Benchmark
| def foo(): Unit = {
| (1L to 10000000L).sum
| }
|
|}
|""".stripMargin
)

withBsp(inputs, Seq(".", "--power") ++ jmhOptions) { (_, _, remoteServer) =>
async {
val buildTargetsResp = await(remoteServer.workspaceBuildTargets().asScala)
val targets = buildTargetsResp.getTargets.asScala.map(_.getId).toSeq
expect(targets.length == 2)

val compileResult =
await(remoteServer.buildTargetCompile(new b.CompileParams(targets.asJava)).asScala)
expect(compileResult.getStatusCode == b.StatusCode.OK)

}
}
}

test("diagnostics") {
val inputs = TestInputs(
os.rel / "Test.scala" ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package scala.cli.integration

import ch.epfl.scala.bsp4j as b
import com.eed3si9n.expecty.Expecty.expect

import java.nio.file.Files

import scala.async.Async.{async, await}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.jdk.CollectionConverters.*
import scala.util.Properties

class JmhTests extends ScalaCliSuite with JmhSuite {
override def group: ScalaCliSuite.TestGroup = ScalaCliSuite.TestGroup.First
class JmhTests extends ScalaCliSuite with JmhSuite with BspSuite {
override def group: ScalaCliSuite.TestGroup = ScalaCliSuite.TestGroup.First
override protected val extraOptions: Seq[String] = TestUtil.extraOptions

for {
useDirective <- Seq(None, Some("//> using jmh"))
Expand Down Expand Up @@ -52,6 +57,22 @@ class JmhTests extends ScalaCliSuite with JmhSuite {
}
}

test(s"bsp ($testMessage)") {
withBsp(simpleBenchmarkingInputs(directiveString), Seq(".", "--power") ++ jmhOptions) {
(_, _, remoteServer) =>
async {
val buildTargetsResp = await(remoteServer.workspaceBuildTargets().asScala)
val targets = buildTargetsResp.getTargets.asScala.map(_.getId).toSeq
expect(targets.length == 2)

val compileResult =
await(remoteServer.buildTargetCompile(new b.CompileParams(targets.asJava)).asScala)
expect(compileResult.getStatusCode == b.StatusCode.OK)

}
}
}

test(s"package ($testMessage)") {
// TODO make package with --jmh build an artifact that actually runs benchmarks
val expectedMessage = "Placeholder main method"
Expand Down

0 comments on commit bfc4133

Please sign in to comment.