Skip to content

Commit

Permalink
Ledger API Test Tool: skip semantic tests on unsupported Ledger API. (d…
Browse files Browse the repository at this point in the history
…igital-asset#1976)

Semantic tests will be skipped if the specified Ledger API endpoint does not
implement TimeService.

This teaches MultiLedgerFixture to deal with cancelled tests.

This improves Ledger API Test Tool reporter to deal with cancellations better.
gleber-da authored and mergify[bot] committed Jul 3, 2019
1 parent ecbe0b1 commit 3dac96f
Showing 4 changed files with 51 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -5,20 +5,29 @@ package com.digitalasset.platform.semantictest

import java.io._

import akka.stream.scaladsl.Sink
import com.digitalasset.daml.bazeltools.BazelRunfiles._
import com.digitalasset.daml.lf.archive.{Decode, UniversalArchiveReader}
import com.digitalasset.daml.lf.data.Ref.QualifiedName
import com.digitalasset.daml.lf.engine.testing.SemanticTester
import com.digitalasset.daml.lf.types.{Ledger => L}
import com.digitalasset.grpc.adapter.client.akka.ClientAdapter
import com.digitalasset.ledger.api.testing.utils.{
AkkaBeforeAndAfterAll,
SuiteResourceManagementAroundAll
}
import com.digitalasset.ledger.api.v1.testing.time_service.GetTimeRequest
import com.digitalasset.platform.apitesting.{MultiLedgerFixture, TestIdsGenerator}
import com.digitalasset.platform.services.time.TimeProviderType
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.exceptions.TestCanceledException
import org.scalatest.{AsyncWordSpec, Matchers}

import scala.concurrent.Future
import scala.util.{Failure, Success}

import scalaz.syntax.tag._

class SandboxSemanticTestsLfRunner
extends AsyncWordSpec
with Matchers
@@ -55,6 +64,20 @@ class SandboxSemanticTestsLfRunner
} {
s"run scenario: $name" in allFixtures { ledger =>
for {
_ <- ClientAdapter
.serverStreaming(GetTimeRequest(ledger.ledgerId.unwrap), ledger.timeService.getTime)
.take(1)
.map(_.getCurrentTime)
.runWith(Sink.head)
.transformWith({
case Failure(throwable) =>
Future.failed(
new TestCanceledException(
"DAML scenario running requires implemented TimeService by the provided Ledger API endpoint.",
throwable,
3))
case Success(ts) => Future.successful(ts)
})
_ <- new SemanticTester(
parties =>
new SemanticTestAdapter(
Original file line number Diff line number Diff line change
@@ -75,6 +75,7 @@ object Cli {
|use numbers lower than 1.0 to make test timeouts more strict.""".stripMargin)

opt[Unit]("verbose")
.abbr("v")
.action((_, c) => c.copy(verbose = true))
.text("Prints full stacktraces on failures.")

Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ class ToolReporter(verbose: Boolean) extends Reporter {
threadName,
timeStamp) =>
testsSucceeded += 1
println(ansiGreen + "")
println(ansiGreen + "" + ansiReset)

case e.TestCanceled(
ordinal,
@@ -102,7 +102,19 @@ class ToolReporter(verbose: Boolean) extends Reporter {
threadName,
timeStamp) =>
testsCancelled += 1
println(ansiRed + "cancelled.")
println(ansiYellow + "cancelled." + ansiReset)
throwable match {
case None =>
println(indented(ansiRed + s"Cancel details missing!", 1, ' '))
case Some(e) =>
println(indented(s"Cancel details:", 1, ' '))
val st = if (verbose) {
ExceptionUtils.getStackTrace(e)
} else {
e.getMessage
}
println(indented(st, 2, '|'))
}

case e.TestFailed(
ordinal,
@@ -188,8 +200,11 @@ class ToolReporter(verbose: Boolean) extends Reporter {
println(ansiYellow + "No tests were run" + ansiReset)
case Statistics(a, s, 0, 0) =>
println(ansiGreen + s"All ${s}/${a} tests were successful!" + ansiReset)
case Statistics(a, 0, c, 0) =>
println(ansiYellow + s"All ${a}/${a} tests were cancelled." + ansiReset)
case Statistics(a, s, c, 0) =>
println(ansiYellow + s"${s}/${a} tests were successful, but ${c} were skipped." + ansiReset)
println(
ansiYellow + s"${s}/${a} tests were successful, but ${c} were cancelled." + ansiReset)
case Statistics(a, s, 0, f) =>
println(ansiRed + s"${s} were successful and ${f} failed out of ${a} tests." + ansiReset)
case _ =>
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import java.util.concurrent.{Executors, ScheduledExecutorService, TimeUnit}
import com.digitalasset.grpc.adapter.utils.DirectExecutionContext
import org.scalatest._
import org.scalatest.concurrent.{AsyncTimeLimitedTests, ScaledTimeSpans}
import org.scalatest.exceptions.TestCanceledException
import org.scalatest.time.Span

import scala.collection.immutable.Iterable
@@ -69,11 +70,15 @@ trait MultiFixtureBase[FixtureId, TestContext]
testFixture: TestFixture,
runTest: TestFixture => Future[Assertion]): Future[Assertion] = {

def failOnFixture(throwable: Throwable): Nothing = {
def failOnFixture(throwable: Throwable): Assertion = {
// Add additional information about failure (which fixture was problematic)
throw new RuntimeException(
s"Test failed on fixture ${testFixture.id} with ${throwable.getClass}: ${throwable.getMessage}",
throwable) with NoStackTrace
throwable match {
case ex: TestCanceledException => throw ex
case _ =>
throw new RuntimeException(
s"Test failed on fixture ${testFixture.id} with ${throwable.getClass}: ${throwable.getMessage}",
throwable) with NoStackTrace
}
}

val timeoutPromise = Promise[Assertion]

0 comments on commit 3dac96f

Please sign in to comment.