Skip to content

Commit

Permalink
Migrate daml script tests to Sandbox next (#11472)
Browse files Browse the repository at this point in the history
* Migrate daml script tests to Sandbox next

This does not yet drop all dependencies from daml script. In
particular `daml test-script` still depends on Sandbox classic. Will
tackle that in a separate PR.

changelog_begin
changelog_end

* Speedup maxInboundMessageSize tests

changelog_begin
changelog_end
  • Loading branch information
cocreature committed Nov 1, 2021
1 parent df65d02 commit 8ffd835
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 28 deletions.
8 changes: 4 additions & 4 deletions daml-script/test/BUILD.bazel
Expand Up @@ -146,8 +146,8 @@ da_scala_library(
"//ledger/participant-integration-api",
"//ledger/participant-state/kvutils",
"//ledger/participant-state/kvutils/app",
"//ledger/sandbox-classic",
"//ledger/sandbox-classic:sandbox-classic-scala-tests-lib",
"//ledger/sandbox",
"//ledger/sandbox:sandbox-scala-tests-lib",
"//ledger/sandbox-common",
"//ledger/sandbox-common:sandbox-common-scala-tests-lib",
"//libs-scala/ports",
Expand Down Expand Up @@ -206,8 +206,8 @@ da_scala_test_suite(
"//ledger/participant-state",
"//ledger/participant-state/kvutils",
"//ledger/participant-state/kvutils/app",
"//ledger/sandbox-classic",
"//ledger/sandbox-classic:sandbox-classic-scala-tests-lib",
"//ledger/sandbox",
"//ledger/sandbox:sandbox-scala-tests-lib",
"//ledger/sandbox-common",
"//ledger/sandbox-common:sandbox-common-scala-tests-lib",
"//ledger/test-common",
Expand Down
2 changes: 1 addition & 1 deletion daml-script/test/daml/ScriptTest.daml
Expand Up @@ -277,7 +277,7 @@ template MessageSize
testMaxInboundMessageSize : Script () = do
p <- allocateParty "p"
b <- submit p do createCmd (MessageSize p)
submit p do exerciseCmd b CreateN with n = 50000
submit p do exerciseCmd b CreateN with n = 1
return ()

testSetTime : Script (Time, Time) = do
Expand Down
Expand Up @@ -47,7 +47,8 @@ import com.daml.platform.apiserver.services.GrpcClientResource
import com.daml.platform.common.LedgerIdMode
import com.daml.platform.sandbox.config.SandboxConfig
import com.daml.platform.sandbox.services.TestCommands
import com.daml.platform.sandbox.{AbstractSandboxFixture, SandboxServer}
import com.daml.platform.sandbox.AbstractSandboxFixture
import com.daml.platform.sandboxnext
import com.daml.ports.Port
import io.grpc.Channel
import org.scalatest._
Expand All @@ -64,16 +65,14 @@ import com.codahale.metrics.MetricRegistry

trait JsonApiFixture
extends AbstractSandboxFixture
with SuiteResource[(SandboxServer, Channel, ServerBinding)] {
with SuiteResource[(Port, Channel, ServerBinding)] {
self: Suite =>

override protected def darFile = new File(rlocation("daml-script/test/script-test.dar"))

protected val darFileNoLedger = new File(rlocation("daml-script/test/script-test-no-ledger.dar"))

protected def server: SandboxServer = suiteResource.value._1

override protected def serverPort: Port = server.port
override protected def serverPort: Port = suiteResource.value._1
override protected def channel: Channel = suiteResource.value._2
override protected def config: SandboxConfig =
super.config
Expand Down Expand Up @@ -121,17 +120,16 @@ trait JsonApiFixture
}
}

override protected lazy val suiteResource
: TestResource[(SandboxServer, Channel, ServerBinding)] = {
override protected lazy val suiteResource: TestResource[(Port, Channel, ServerBinding)] = {
implicit val context: ResourceContext = ResourceContext(system.dispatcher)
new OwnedResource[ResourceContext, (SandboxServer, Channel, ServerBinding)](
new OwnedResource[ResourceContext, (Port, Channel, ServerBinding)](
for {
jdbcUrl <- database
.fold[ResourceOwner[Option[String]]](ResourceOwner.successful(None))(
_.map(info => Some(info.jdbcUrl))
)
server <- SandboxServer.owner(config.copy(jdbcUrl = jdbcUrl))
channel <- GrpcClientResource.owner(server.port)
serverPort <- new sandboxnext.Runner(config.copy(jdbcUrl = jdbcUrl))
channel <- GrpcClientResource.owner(serverPort)
httpService <- new ResourceOwner[ServerBinding] {
override def acquire()(implicit context: ResourceContext): Resource[ServerBinding] = {
implicit val lc: LoggingContextOf[InstanceUUID] = instanceUUIDLogCtx(
Expand All @@ -140,7 +138,7 @@ trait JsonApiFixture
Resource[ServerBinding] {
val config = new StartSettings.Default {
override val ledgerHost = "localhost"
override val ledgerPort = server.port.value
override val ledgerPort = serverPort.value
override val address = "localhost"
override val httpPort = 0
override val portFile = None
Expand Down Expand Up @@ -169,7 +167,9 @@ trait JsonApiFixture
}((binding: ServerBinding) => binding.unbind().map(_ => ()))
}
}
} yield (server, channel, httpService)
} yield (serverPort, channel, httpService),
acquisitionTimeout = 1.minute,
releaseTimeout = 1.minute,
)
}
}
Expand Down
Expand Up @@ -6,9 +6,10 @@ package com.daml.lf.engine.script.test
import com.daml.ledger.api.testing.utils.SuiteResourceManagementAroundAll
import com.daml.lf.data.Ref._
import com.daml.lf.data.{FrontStack, FrontStackCons, Numeric}
import com.daml.lf.engine.script.{RunnerConfig, ScriptF, StackTrace}
import com.daml.lf.engine.script.{ScriptF, StackTrace}
import com.daml.lf.speedy.SValue
import com.daml.lf.speedy.SValue._
import io.grpc.{Status, StatusRuntimeException}
import org.scalatest.Inside
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AsyncWordSpec
Expand Down Expand Up @@ -218,15 +219,20 @@ abstract class AbstractFuncIT
"succeed despite large message" in {
for {
clients <- participantClients(
maxInboundMessageSize = RunnerConfig.DefaultMaxInboundMessageSize * 10
// Reduce maxInboundMessageSize until we get an error
maxInboundMessageSize = 500
)
v <- run(
clients,
QualifiedName.assertFromString("ScriptTest:testMaxInboundMessageSize"),
dar = stableDar,
ex <- recoverToExceptionIf[ScriptF.FailedCmd](
run(
clients,
QualifiedName.assertFromString("ScriptTest:testMaxInboundMessageSize"),
dar = stableDar,
)
)
} yield {
assert(v == SUnit)
inside(ex.cause) { case e: StatusRuntimeException =>
e.getStatus.getCode() shouldBe Status.Code.RESOURCE_EXHAUSTED
}
}
}
}
Expand Down
Expand Up @@ -14,7 +14,7 @@ import com.daml.ledger.api.testing.utils.AkkaBeforeAndAfterAll
import com.daml.ledger.api.tls.TlsConfiguration
import com.daml.lf.engine.script._
import com.daml.lf.engine.script.ledgerinteraction.ScriptTimeMode
import com.daml.platform.sandbox.services.SandboxFixture
import com.daml.platform.sandboxnext.SandboxNextFixture
import com.daml.platform.services.time.TimeProviderType
import org.scalatest.Suite
import scalaz.syntax.tag._
Expand All @@ -24,7 +24,7 @@ import scala.concurrent.ExecutionContext

trait SandboxAuthParticipantFixture
extends AbstractScriptTest
with SandboxFixture
with SandboxNextFixture
with AkkaBeforeAndAfterAll {
self: Suite =>
private implicit val ec: ExecutionContext = system.dispatcher
Expand Down
Expand Up @@ -6,7 +6,7 @@ package com.daml.lf.engine.script.test
import java.io.File

import com.daml.lf.engine.script.{ApiParameters, Participants, Runner, RunnerConfig}
import com.daml.platform.sandbox.services.SandboxFixture
import com.daml.platform.sandboxnext.SandboxNextFixture
import com.daml.platform.services.time.TimeProviderType
import org.scalatest.Suite
import com.daml.bazeltools.BazelRunfiles._
Expand All @@ -18,7 +18,7 @@ import scala.concurrent.ExecutionContext

trait SandboxParticipantFixture
extends AbstractScriptTest
with SandboxFixture
with SandboxNextFixture
with AkkaBeforeAndAfterAll {
self: Suite =>
private implicit val ec: ExecutionContext = system.dispatcher
Expand Down

0 comments on commit 8ffd835

Please sign in to comment.