Skip to content

Commit

Permalink
cancellation test
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Sep 27, 2023
1 parent 035c0d5 commit b1e86f0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ final class BatchedFunction[A, B](
extends (Seq[A] => Future[B])
with Function2[Seq[A], () => Unit, Future[B]]
with Pauseable {
val rand = new scala.util.Random

/**
* Call the function with the given arguments.
Expand Down
39 changes: 39 additions & 0 deletions tests/unit/src/test/scala/tests/BillLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import scala.meta.internal.metals.ServerCommands
import scala.meta.io.AbsolutePath

import bill._
import ch.epfl.scala.bsp4j.StatusCode

class BillLspSuite extends BaseLspSuite("bill") {

Expand Down Expand Up @@ -222,4 +223,42 @@ class BillLspSuite extends BaseLspSuite("bill") {
Bill.installGlobal(globalBsp.toNIO, "Bob")
testSelectServerDialogue()
}

test("cancel-compile") {
val cancelPattern =
"""Sending notification '\$\/cancelRequest'\s*Params: \{\s*\"id\": \"([0-9]+)\"\s*\}""".r
cleanWorkspace()
Bill.installWorkspace(workspace.toNIO, "Bill")
def trace = workspace.resolve(".metals/bsp.trace.json").readText
for {
_ <- initialize(
"""|/src/com/App.scala
|object App {
| val x: Int = 1
|}
|/.metals/bsp.trace.json
|""".stripMargin
)
(compileReport, _) <- server.server.compilations
.compileFile(
workspace.resolve("src/com/App.scala")
)
.zip {
// wait until the compilation start
while (!trace.contains(s"buildTarget/compile")) {
Thread.sleep(1)
}
server.executeCommand(ServerCommands.CancelCompile)
}
_ = assertEquals(compileReport.getStatusCode(), StatusCode.CANCELLED)
currentTrace = trace
cancelId = cancelPattern.findFirstMatchIn(currentTrace).get.group(1)
_ = assert(currentTrace.contains(s"buildTarget/compile - ($cancelId)"))
compileReport <- server.server.compilations
.compileFile(
workspace.resolve("src/com/App.scala")
)
_ = assertEquals(compileReport.getStatusCode(), StatusCode.OK)
} yield ()
}
}

0 comments on commit b1e86f0

Please sign in to comment.