Skip to content

Commit

Permalink
cancellation test
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Aug 2, 2023
1 parent 26567ad commit 956a014
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 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,40 @@ class BillLspSuite extends BaseLspSuite("bill") {
Bill.installGlobal(globalBsp.toNIO, "Bob")
testSelectServerDialogue()
}

test("basic") {
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
Thread.sleep(1000)
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 956a014

Please sign in to comment.