diff --git a/ledger/sandbox-classic/BUILD.bazel b/ledger/sandbox-classic/BUILD.bazel index 1eb83e7d0689..421a8d68a8d1 100644 --- a/ledger/sandbox-classic/BUILD.bazel +++ b/ledger/sandbox-classic/BUILD.bazel @@ -265,6 +265,7 @@ reset_service_pattern = "src/test/suite/**/*ResetService*.scala" [ da_scala_test_suite( name = "sandbox-classic-tests{}".format(suffix), + size = size, srcs = glob( [pattern], exclude = exclusions, @@ -279,18 +280,20 @@ reset_service_pattern = "src/test/suite/**/*ResetService*.scala" scala_deps = scala_test_deps, deps = test_deps, ) - for (suffix, pattern, exclusions, flaky) in [ + for (suffix, pattern, exclusions, flaky, size) in [ ( "", "src/test/suite/**/*.scala", [reset_service_pattern], False, + "medium", # Default timeout of 5min ), ( "-resetservice", reset_service_pattern, [], True, + "large", # Reset service tests have a large variance in their run time, use a timeout of 15min ), ] ] diff --git a/ledger/sandbox-common/BUILD.bazel b/ledger/sandbox-common/BUILD.bazel index ef594511a32d..1d656994b2fa 100644 --- a/ledger/sandbox-common/BUILD.bazel +++ b/ledger/sandbox-common/BUILD.bazel @@ -137,6 +137,7 @@ da_scala_library( "//ledger/participant-integration-api", "//ledger/test-common", "//ledger/test-common:dar-files-default-lib", + "//libs-scala/contextualized-logging", "//libs-scala/ports", "//libs-scala/postgresql-testing", "//libs-scala/resources", diff --git a/ledger/sandbox-common/src/test/lib/scala/platform/sandbox/services/reset/ResetServiceITBase.scala b/ledger/sandbox-common/src/test/lib/scala/platform/sandbox/services/reset/ResetServiceITBase.scala index 69207b216e0e..de6615ab8e06 100644 --- a/ledger/sandbox-common/src/test/lib/scala/platform/sandbox/services/reset/ResetServiceITBase.scala +++ b/ledger/sandbox-common/src/test/lib/scala/platform/sandbox/services/reset/ResetServiceITBase.scala @@ -6,7 +6,6 @@ package com.daml.platform.sandbox.services.reset import java.io.File import java.time.Instant import java.util.UUID - import com.daml.api.util.TimestampConversion import com.daml.bazeltools.BazelRunfiles.rlocation import com.daml.ledger.api.domain.LedgerId @@ -46,6 +45,7 @@ import com.daml.ledger.api.v1.testing.time_service.{ import com.daml.ledger.api.v1.transaction_filter.TransactionFilter import com.daml.ledger.resources.TestResourceContext import com.daml.ledger.test.ModelTestDar +import com.daml.logging.{ContextualizedLogger, LoggingContext} import com.daml.platform.common.LedgerIdMode import com.daml.platform.sandbox.AbstractSandboxFixture import com.daml.platform.sandbox.config.SandboxConfig @@ -61,8 +61,9 @@ import org.scalatest.time.Span import org.scalatest.wordspec.AsyncWordSpec import scalaz.syntax.tag._ -import scala.concurrent.duration.{DurationInt, DurationLong, FiniteDuration} +import scala.concurrent.duration.{DurationInt, DurationLong, FiniteDuration, MILLISECONDS} import scala.concurrent.{ExecutionContext, Future} +import scala.util.{Failure, Success} abstract class ResetServiceITBase extends AsyncWordSpec @@ -74,6 +75,9 @@ abstract class ResetServiceITBase with SuiteResourceManagementAroundAll with TestCommands { + protected val logger: ContextualizedLogger = ContextualizedLogger.get(this.getClass) + protected implicit val loggingContext: LoggingContext = LoggingContext.ForTesting + override def timeLimit: Span = scaled(30.seconds) override protected def config: SandboxConfig = @@ -104,14 +108,25 @@ abstract class ResetServiceITBase // Resets and waits for a new ledger identity to be available protected def reset(ledgerId: LedgerId): Future[LedgerId] = + timedReset(ledgerId).map(_._1) + + protected def timedReset(ledgerId: LedgerId): Future[(LedgerId, FiniteDuration)] = { + logger.info(s"Calling reset on $ledgerId") + val start = System.nanoTime() ResetServiceGrpc .stub(channel) .reset(ResetRequest(ledgerId.unwrap)) .flatMap(_ => waitForLedgerToRestart(ledgerId)) - - protected def timedReset(ledgerId: LedgerId): Future[(LedgerId, FiniteDuration)] = { - val start = System.nanoTime() - reset(ledgerId).map(_ -> (System.nanoTime() - start).nanos) + .map(_ -> (System.nanoTime() - start).nanos) + .andThen { + case Success((newLedgerId, d)) => + info(s"Ledger $ledgerId reset") + logger.info( + s"Reset finished on $ledgerId after ${FiniteDuration(d.toMillis, MILLISECONDS)}, new ledgerId is $newLedgerId" + ) + case Failure(e) => + logger.warn(s"Reset failed on $ledgerId because of $e") + } } protected def allocateParty(hint: String): Future[String] = @@ -201,10 +216,10 @@ abstract class ResetServiceITBase } } - "return new ledger ID - 20 resets" in { + "return new ledger ID - 10 resets" in { Future - .sequence(Iterator.iterate(fetchLedgerId())(_.flatMap(reset)).take(20).toVector) - .map(ids => ids.distinct should have size 20L) + .sequence(Iterator.iterate(fetchLedgerId())(_.flatMap(reset)).take(10).toVector) + .map(ids => ids.distinct should have size 10L) } // 4 attempts with 5 transactions each seem to strike the right balance to complete before the diff --git a/ledger/sandbox/BUILD.bazel b/ledger/sandbox/BUILD.bazel index bb9f04e59d55..1c5ce6cc8c93 100644 --- a/ledger/sandbox/BUILD.bazel +++ b/ledger/sandbox/BUILD.bazel @@ -151,6 +151,7 @@ reset_service_pattern = "src/test/suite/**/*ResetService*.scala" [ da_scala_test_suite( name = "sandbox-tests{}".format(suffix), + size = size, srcs = glob( [pattern], exclude = exclusions, @@ -238,18 +239,20 @@ reset_service_pattern = "src/test/suite/**/*ResetService*.scala" "@maven//:org_slf4j_slf4j_api", ], ) - for (suffix, pattern, exclusions, flaky) in [ + for (suffix, pattern, exclusions, flaky, size) in [ ( "", "src/test/suite/**/*.scala", [reset_service_pattern], False, + "medium", # Default timeout of 5min ), ( "-resetservice", reset_service_pattern, [], True, + "large", # Reset service tests have a large variance in their run time, use a timeout of 15min ), ] ]