Skip to content

Commit

Permalink
Try debug DebugProtocolSpec on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
adpi2 committed Mar 29, 2023
1 parent 6db3c86 commit f367d1e
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 52 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,8 @@ jobs:
- name: Compile and test main projects
run: |
sbt \
"frontend/test:compile; \
backend/test; \
docs/compile; \
frontend/testOnly bloop.ScalaVersionsSpec; \
frontend/testOnly -bloop.ScalaVersionsSpec; \
frontend/runMain bloop.util.CommandsDocGenerator --test; \
frontend/runMain bloop.util.CommandsDocGenerator --out ../docs/cli/reference.md"
"backend/test; \
frontend/testOnly bloop.dap.DebugProtocolSpec"
shell: bash

- name: Check docs are up-to-date
Expand Down
54 changes: 39 additions & 15 deletions frontend/src/main/scala/bloop/bsp/BloopBspServices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ import monix.execution.Scheduler
import monix.execution.atomic.AtomicBoolean
import monix.execution.atomic.AtomicInt
import monix.reactive.subjects.BehaviorSubject
import java.util.Date
import scala.util.control.NonFatal

final class BloopBspServices(
callSiteState: State,
Expand Down Expand Up @@ -641,9 +643,11 @@ final class BloopBspServices(
}
}

println(s"${new Date()} Received debug session start request")
ifInitialized(None) { (state, logger) =>
JavaRuntime.loadJavaDebugInterface match {
case Failure(exception) =>
println(s"${new Date()} failed to load java debug interface")
val message = JavaRuntime.current match {
case JavaRuntime.JDK => Feedback.detectedJdkWithoutJDI(exception)
case JavaRuntime.JRE => Feedback.detectedUnsupportedJreForDebugging(exception)
Expand All @@ -657,6 +661,7 @@ final class BloopBspServices(
logger.error(error)
Task.now((state, Left(Response.invalidRequest(error))))
case Right(mappings) =>
println(s"${new Date()} compiling project")
// FIXME: Add origin id to DAP request
compileProjects(mappings, state, Nil, None, logger).flatMap {
case (state, Left(error)) =>
Expand All @@ -667,26 +672,45 @@ final class BloopBspServices(
)
case (state, Right(_)) =>
val projects = mappings.map(_._2)
println(s"${new Date()} creating debuggee")
inferDebuggee(projects, state) match {
case Right(debuggee) =>
val dapLogger = new DebugServerLogger(logger)
val resolver = new BloopDebugToolsResolver(logger)
println(s"${new Date()} resolving debug tools")
val debugTools = DebugTools(debuggee, resolver, dapLogger)
val handler =
DebugServer.start(
debuggee,
debugTools,
dapLogger,
autoCloseSession = true,
gracePeriod = Duration(5, TimeUnit.SECONDS)
)(ioScheduler)
val listenAndUnsubscribe = Task
.fromFuture(handler.running)
.map(_ => backgroundDebugServers -= handler.uri)
.runAsync(ioScheduler)
backgroundDebugServers += handler.uri -> listenAndUnsubscribe
Task.now((state, Right(new bsp.DebugSessionAddress(handler.uri.toString))))

println(s"${new Date()} starting server")
try {
val handler =
DebugServer.start(
debuggee,
debugTools,
dapLogger,
autoCloseSession = true,
gracePeriod = Duration(5, TimeUnit.SECONDS)
)(ioScheduler)
println(s"${new Date()} server started")
val listenAndUnsubscribe = Task
.fromFuture(handler.running)
.map(_ => backgroundDebugServers -= handler.uri)
.runAsync(ioScheduler)
backgroundDebugServers += handler.uri -> listenAndUnsubscribe
println(s"${new Date()} server listening on ${handler.uri}")
Task.now((state, Right(new bsp.DebugSessionAddress(handler.uri.toString))))
} catch {
case NonFatal(cause) =>
println(
s"${new Date()} Non fatal ${cause.getClass.getSimpleName}: ${cause.getMessage}"
)
cause.printStackTrace()
throw cause
case fatal =>
println(
s"${new Date()} Fatal ${fatal.getClass.getSimpleName}: ${fatal.getMessage}"
)
fatal.printStackTrace()
throw fatal
}
case Left(error) =>
Task.now((state, Left(error)))
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/main/scala/bloop/dap/DebugServerLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package bloop.dap
import bloop.logging.Logger

class DebugServerLogger(logger: Logger) extends ch.epfl.scala.debugadapter.Logger {
override def debug(msg: => String): Unit = logger.debug(() => msg)
override def debug(msg: => String): Unit = logger.info(() => msg)
override def info(msg: => String): Unit = logger.info(() => msg)
override def warn(msg: => String): Unit = logger.warn(() => msg)
override def error(msg: => String): Unit = logger.error(() => msg)
Expand Down
13 changes: 12 additions & 1 deletion frontend/src/test/scala/bloop/bsp/BspBaseSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import monix.execution.Scheduler
import monix.execution.atomic.AtomicInt
import monix.reactive.Observable
import monix.reactive.subjects.BehaviorSubject
import scala.util.control.NonFatal
import java.util.Date

abstract class BspBaseSuite extends BaseSuite with BspClientTest {
final class UnmanagedBspTestState(
Expand All @@ -68,7 +70,16 @@ abstract class BspBaseSuite extends BaseSuite with BspClientTest {

def withinSession(f: ManagedBspTestState => Unit): Unit = {
try f(toUnsafeManagedState)
finally TestUtil.await(FiniteDuration(1, "s"))(closeServer)
catch {
case NonFatal(cause) =>
println(s"${new Date()} Non fatal ${cause.getClass.getSimpleName}: ${cause.getMessage}")
cause.printStackTrace()
throw cause
case fatal: Throwable =>
println(s"${new Date()} Fatal ${fatal.getClass.getSimpleName}: ${fatal.getMessage}")
fatal.printStackTrace()
throw fatal
} finally TestUtil.await(FiniteDuration(1, "s"))(closeServer)
}

def withinSession(f: ManagedBspTestState => Task[Unit]): Task[Unit] = {
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/test/scala/bloop/dap/DebugAdapterProxy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ private[dap] object DebugAdapterProxy {
case "response" => classOf[Messages.Response]
case "event" => classOf[Messages.Event]
}
println(s"Received: $content")

upstream.onNext(JsonUtils.fromJson(content, targetType))
}
Expand All @@ -174,7 +175,9 @@ private[dap] object DebugAdapterProxy {
private final class Writer(underlying: Observer[ByteBuffer])
extends Observer[Messages.ProtocolMessage] {
override def onNext(elem: ProtocolMessage): Future[Ack] = {
val bytes = JsonUtils.toJson(elem).getBytes
val str = JsonUtils.toJson(elem)
println(s"Sent: $str")
val bytes = str.getBytes
val protocolMsg = LowLevelMessage.fromBytes(
Map("Content-Length" -> bytes.length.toString),
bytes
Expand Down
54 changes: 27 additions & 27 deletions frontend/src/test/scala/bloop/dap/DebugProtocolSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -145,33 +145,33 @@ object DebugProtocolSpec extends DebugBspBaseSuite {
}
}

flakyTest("starts test suites", 3) {
TestUtil.withinWorkspace { workspace =>
val logger = new RecordingLogger(ansiCodesSupported = false)
for (suffix <- Seq("0", "x")) {
loadBspBuildFromResources(s"cross-test-build-scalajs-1.$suffix", workspace, logger) {
build =>
val project = build.projectFor("test-project-test")
val testFilters = List("hello.JUnitTest")

val output = build.state.withDebugSession(project, testSuiteParams(testFilters)) {
client =>
for {
_ <- client.initialize()
_ <- client.launch()
_ <- client.configurationDone()
_ <- client.terminated
output <- client.blockForAllOutput
} yield output
}

testFilters.foreach { testSuite =>
assert(output.contains(s"All tests in $testSuite passed"))
}
}
}
}
}
// flakyTest("starts test suites", 3) {
// TestUtil.withinWorkspace { workspace =>
// val logger = new RecordingLogger(ansiCodesSupported = false)
// for (suffix <- Seq("0", "x")) {
// loadBspBuildFromResources(s"cross-test-build-scalajs-1.$suffix", workspace, logger) {
// build =>
// val project = build.projectFor("test-project-test")
// val testFilters = List("hello.JUnitTest")

// val output = build.state.withDebugSession(project, testSuiteParams(testFilters)) {
// client =>
// for {
// _ <- client.initialize()
// _ <- client.launch()
// _ <- client.configurationDone()
// _ <- client.terminated
// output <- client.blockForAllOutput
// } yield output
// }

// testFilters.foreach { testSuite =>
// assert(output.contains(s"All tests in $testSuite passed"))
// }
// }
// }
// }
// }

def mainClassParams(mainClass: String): bsp.BuildTargetIdentifier => bsp.DebugSessionParams = {
target =>
Expand Down

0 comments on commit f367d1e

Please sign in to comment.