Skip to content

Commit

Permalink
Override engine and archive reader in canton jar used for dev testing (
Browse files Browse the repository at this point in the history
  • Loading branch information
remyhaemmerle-da authored May 2, 2023
1 parent d950f8c commit 1a917b7
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 236 deletions.
29 changes: 29 additions & 0 deletions daml-lf/integration-test-lib/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ load(
da_scala_library(
name = "integration-test-lib",
srcs = glob(["src/main/**/*.scala"]),
data = [
":canton-dev_deploy.jar",
":canton_deploy.jar",
"//test-common/test-certificates",
],
scala_deps = [
"@maven//:com_typesafe_akka_akka_stream",
"@maven//:io_spray_spray_json",
Expand Down Expand Up @@ -42,3 +47,27 @@ da_scala_library(
"@maven//:org_scalatest_scalatest_compatible",
],
)

java_binary(
name = "canton",
main_class = "com.digitalasset.canton.CantonCommunityApp",
visibility = ["//visibility:public"],
runtime_deps = [
# Do not sort
"@canton//:lib",
],
)

# We replace engine and archive classes in canton
# This should be used for testing only
java_binary(
name = "canton-dev",
main_class = "com.digitalasset.canton.CantonCommunityApp",
visibility = ["//visibility:public"],
runtime_deps = [
# Do not sort
"//daml-lf/engine",
"//daml-lf/archive:daml_lf_archive_reader",
"@canton//:lib",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.daml.lf.data.Ref
import com.daml.ledger.api.auth
import com.daml.ledger.resources.{ResourceContext, ResourceOwner, Resource}
import com.daml.platform.services.time.TimeProviderType
import com.daml.ports.{Port, LockedFreePort, PortLock}
import com.daml.ports.{LockedFreePort, Port, PortLock}
import com.daml.scalautil.Statement.discard
import com.daml.timer.RetryStrategy
import com.google.protobuf.ByteString
Expand All @@ -22,7 +22,7 @@ import scala.concurrent.duration.DurationInt
import scala.concurrent.Future
import scala.sys.process.Process
import java.nio.charset.StandardCharsets
import java.nio.file.{Path, Files}
import java.nio.file.{Files, Path, Paths}

object CantonRunner {

Expand All @@ -31,6 +31,10 @@ object CantonRunner {
private[integrationtest] def toJson(s: String): String = JsString(s).toString()
private[integrationtest] def toJson(path: Path): String = toJson(path.toString)

lazy val cantonPath = Paths.get(rlocation("daml-lf/integration-test-lib/canton_deploy.jar"))
lazy val cantonDevPath =
Paths.get(rlocation("daml-lf/integration-test-lib/canton-dev_deploy.jar"))

def run(config: CantonConfig, tmpDir: Path)(implicit
esf: ExecutionSequencerFactory
): ResourceOwner[Vector[Port]] =
Expand All @@ -49,10 +53,7 @@ object CantonRunner {
Vector.fill(nParticipants)(LockedFreePort.find() -> LockedFreePort.find())
val domainPublicApi = LockedFreePort.find()
val domainAdminApi = LockedFreePort.find()

val cantonPath = rlocation(
"external/canton/lib/canton-open-source-2.7.0-SNAPSHOT.jar"
)
val jarPath = if (devMode) cantonDevPath else cantonPath
val exe = if (sys.props("os.name").toLowerCase.contains("windows")) ".exe" else ""
val java = s"${System.getenv("JAVA_HOME")}/bin/java${exe}"
val (timeType, clockType) = timeProviderType match {
Expand Down Expand Up @@ -130,19 +131,26 @@ object CantonRunner {
Process(
java ::
"-jar" ::
cantonPath ::
jarPath.toString ::
"daemon" ::
"--auto-connect-local" ::
"-c" ::
cantonConfigFile.toString ::
debugOptions
).run()
)
_ <- RetryStrategy.constant(attempts = 240, waitTime = 1.seconds) { (_, _) =>
size <- RetryStrategy.constant(attempts = 240, waitTime = 1.seconds) { (_, _) =>
info("waiting for Canton to start")
Future(Files.size(portFile))
if (proc.isAlive())
Future(Files.size(portFile))
else
Future.successful(-1L)
}
_ = info("Canton started")
_ <-
if (size > 0)
Future.successful(info("Canton started"))
else
Future.failed(new Error("canton unexpectedly dies"))
_ <-
Future.traverse(ports) { case (_, ledgerPort) =>
for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ da_scala_test(
"//compiler/damlc",
"//daml-script/daml:daml-script.dar",
"//test-common:dar-files",
"@canton//:lib",
],
resources = ["test/resources/logback-test.xml"],
scala_deps = [
Expand Down
7 changes: 4 additions & 3 deletions daml-script/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ da_scala_test_suite(
":script-test-1.dev.dar",
":script-test-no-ledger.dar",
"//daml-script/runner:daml-script-binary",
"//test-common/test-certificates",
"@canton//:lib",
],
resources = glob(["src/main/resources/**/*"]),
scala_deps = [
Expand All @@ -180,7 +178,10 @@ da_scala_test_suite(
"@maven//:io_spray_spray_json",
"@maven//:org_scalaz_scalaz_core",
],
tags = ["cpu:4"],
tags = [
"canton-dev",
"cpu:4",
],
deps = [
":test-utils",
"//bazel_tools/runfiles:scala_runfiles",
Expand Down
57 changes: 31 additions & 26 deletions ledger-test-tool/ledger-api-test-tool-on-canton/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@
load("//ledger-test-tool/ledger-api-tests:conformance.bzl", "conformance_test")
load("@os_info//:os_info.bzl", "is_windows")

java_binary(
name = "canton",
main_class = "com.digitalasset.canton.CantonCommunityApp",
runtime_deps = ["@canton//:lib"],
)

# Disabled on Windows because `coreutils` and `grpcurl` aren't easily available.
genrule(
name = "canton-test-runner-with-dependencies-script",
srcs = [
":canton-test-runner.sh",
],
outs = ["canton-test-runner-with-dependencies.sh"],
cmd = """
[
[
genrule(
name = "canton%s-test-runner-with-dependencies-script" % suffix,
srcs = [
":canton-test-runner.sh",
],
outs = ["canton%s-test-runner-with-dependencies.sh" % suffix],
cmd = """
cat > $@ <<EOF
#!/usr/bin/env bash
Expand All @@ -34,21 +30,29 @@ source "\\$${RUNFILES_DIR:-/dev/null}/\\$$f" 2>/dev/null || \\
PATH="\\$$(rlocation coreutils_nix/bin):\\$$(rlocation curl_nix/bin):\\$$(rlocation grpcurl_nix/bin):\\$$(rlocation jq_dev_env/bin):\\$$PATH"
export PATH
canton_jar=canton%s_deploy.jar
EOF
cat $< >> $@
""",
) if not is_windows else None
""" % suffix,
),

# Required because running `canton-test-runner-with-dependencies-script` directly fails.
sh_binary(
name = "canton-test-runner-with-dependencies",
srcs = [":canton-test-runner-with-dependencies-script"],
# Ideally these would be part of the script definition above, but that doesn't seem to work.
deps = ["@bazel_tools//tools/bash/runfiles"],
) if not is_windows else None
# Required because running `canton-test-runner-with-dependencies-script` directly fails.
sh_binary(
name = "canton%s-test-runner-with-dependencies" % suffix,
srcs = [":canton%s-test-runner-with-dependencies-script" % suffix],
# Ideally these would be part of the script definition above, but that doesn't seem to work.
deps = ["@bazel_tools//tools/bash/runfiles"],
),
]
for suffix in [
"",
"-dev",
]
if not is_windows
]

conformance_test_extra_data_base = [
":canton_deploy.jar",
":logback-debug.xml",
"@coreutils_nix//:bin/base64",
"@curl_nix//:bin/curl",
Expand Down Expand Up @@ -87,6 +91,7 @@ conformance_test(
name = "conformance-test",
extra_data =
conformance_test_extra_data_base + [
"//daml-lf/integration-test-lib:canton_deploy.jar",
":bootstrap.canton",
":canton.conf",
],
Expand All @@ -110,22 +115,22 @@ conformance_test(
dev_mod_flag = "",
extra_data =
conformance_test_extra_data_base + [
"//daml-lf/integration-test-lib:canton-dev_deploy.jar",
":bootstrap-dev.canton",
":canton-dev.conf",
],
extra_runner_args = ["7000"],
lf_versions = [
"default",
"preview",
"dev",
],
ports = conformance_test_ports,
preview_mod_flag = "",
runner = "@//bazel_tools/client_server/runner_with_health_check",
server = ":canton-test-runner-with-dependencies",
server = ":canton-dev-test-runner-with-dependencies",
server_args = [
"--config=$$(canonicalize_rlocation $(rootpath :canton-dev.conf))",
"--bootstrap=$$(canonicalize_rlocation $(rootpath :bootstrap-dev.canton))",
],
tags = ["canton-dev"],
test_tool_args = conformance_test_tool_args,
) if not is_windows else None
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -o pipefail

JAVA="$(rlocation local_jdk/bin/java)"

command=("$(rlocation com_github_digital_asset_daml/ledger-test-tool/ledger-api-test-tool-on-canton/canton_deploy.jar)" daemon "$@")
command=("$(rlocation com_github_digital_asset_daml/daml-lf/integration-test-lib/${canton_jar})" daemon "$@")

# Change HOME since Canton uses ammonite in the default configuration, which tries to write to
# ~/.ammonite/cache, which is read-only when sandboxing is enabled.
Expand Down
3 changes: 0 additions & 3 deletions navigator/backend/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,6 @@ da_scala_test_suite(
"src/test/**/*Spec.scala",
"src/test/**/*Test.scala",
]),
data = [
"@canton//:lib",
],
scala_deps = [
"@maven//:com_typesafe_akka_akka_actor",
"@maven//:com_typesafe_akka_akka_http",
Expand Down
Loading

0 comments on commit 1a917b7

Please sign in to comment.