From b2c2feab6bed2aeb3e83e444b02fc0b04d854f25 Mon Sep 17 00:00:00 2001 From: Paul Brauner <141240651+paulbrauner-da@users.noreply.github.com> Date: Tue, 13 Aug 2024 09:23:50 +0200 Subject: [PATCH] add flag and instructions for attaching a java debugger to the canton fixture (#19763) * add flag and instructions for attaching a java debugger to the canton fixture * revert leftover debugging code --- .../daml/integrationtest/CantonConfig.scala | 1 + .../daml/integrationtest/CantonFixture.scala | 9 +++++++++ .../daml/integrationtest/CantonRunner.scala | 19 +++++++++++-------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/sdk/test-common/canton/it-lib/src/main/scala/com/daml/integrationtest/CantonConfig.scala b/sdk/test-common/canton/it-lib/src/main/scala/com/daml/integrationtest/CantonConfig.scala index d56b82321f0f..e9a476ff77fe 100644 --- a/sdk/test-common/canton/it-lib/src/main/scala/com/daml/integrationtest/CantonConfig.scala +++ b/sdk/test-common/canton/it-lib/src/main/scala/com/daml/integrationtest/CantonConfig.scala @@ -58,6 +58,7 @@ final case class CantonConfig( bootstrapScript: Option[String] = None, targetScope: Option[String] = None, disableUpgradeValidation: Boolean = false, + enableRemoteJavaDebugging: Boolean = false, ) { lazy val tlsConfig = diff --git a/sdk/test-common/canton/it-lib/src/main/scala/com/daml/integrationtest/CantonFixture.scala b/sdk/test-common/canton/it-lib/src/main/scala/com/daml/integrationtest/CantonFixture.scala index e4f5afa4c43f..8592d3ad825a 100644 --- a/sdk/test-common/canton/it-lib/src/main/scala/com/daml/integrationtest/CantonFixture.scala +++ b/sdk/test-common/canton/it-lib/src/main/scala/com/daml/integrationtest/CantonFixture.scala @@ -88,6 +88,14 @@ trait CantonFixtureWithResource[A] // temporary files after a test is done running protected val cantonFixtureDebugModeRemoveTmpFilesRegardless = false + // When true, the canton process is started with the necessary flags to enable remote debugging and is suspended until + // a debugger is attached. In order to use this feature, launch the test making use of the fixture from IntelliJ + // *in debug mode* and look for "Listening for transport dt_socket at address: 5005" in the console output. IntelliJ + // should display a clickable chip labelled "Attach debugger" next to this line. Clicking on this chip will attach the + // debugger to the canton process and resume execution. Breakpoints in the canton code under canton/* will then be + // taken into account by IntelliJ. + protected val remoteJavaDebugging: Boolean = false + final protected val logger = org.slf4j.LoggerFactory.getLogger(getClass) if (cantonFixtureDebugModeIsDebug) { @@ -127,6 +135,7 @@ trait CantonFixtureWithResource[A] bootstrapScript = bootstrapScript, targetScope = targetScope, disableUpgradeValidation = disableUpgradeValidation, + enableRemoteJavaDebugging = remoteJavaDebugging, ) protected def info(msg: String): Unit = diff --git a/sdk/test-common/canton/it-lib/src/main/scala/com/daml/integrationtest/CantonRunner.scala b/sdk/test-common/canton/it-lib/src/main/scala/com/daml/integrationtest/CantonRunner.scala index 83c4d7434fb1..f1455361089f 100644 --- a/sdk/test-common/canton/it-lib/src/main/scala/com/daml/integrationtest/CantonRunner.scala +++ b/sdk/test-common/canton/it-lib/src/main/scala/com/daml/integrationtest/CantonRunner.scala @@ -192,14 +192,17 @@ object CantonRunner { ) var outputBuffer = "" val cmd = java :: - "-jar" :: - config.jarPath.toString :: - "daemon" :: - "-c" :: - files.configFile.toString :: - "--bootstrap" :: - files.bootstrapFile.toString :: - debugOptions + (if (config.enableRemoteJavaDebugging) + List("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005") + else List.empty) ++ + ("-jar" :: + config.jarPath.toString :: + "daemon" :: + "-c" :: + files.configFile.toString :: + "--bootstrap" :: + files.bootstrapFile.toString :: + debugOptions) info(cmd.mkString("\\\n ")) for { proc <- Future(