Skip to content

Commit

Permalink
Improve reset service tests (#11240)
Browse files Browse the repository at this point in the history
* Improve reset service tests

- Increase timeout
- Decrease load
- Improve logging

changelog_begin
changelog_end

* Apply review comments
  • Loading branch information
rautenrieth-da authored Oct 15, 2021
1 parent b3375fd commit 04feb40
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
5 changes: 4 additions & 1 deletion ledger/sandbox-classic/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
),
]
]
Expand Down
1 change: 1 addition & 0 deletions ledger/sandbox-common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 =
Expand Down Expand Up @@ -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] =
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion ledger/sandbox/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
),
]
]
Expand Down

0 comments on commit 04feb40

Please sign in to comment.