forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ledger-api-test-tool: Provide context when expecting a failing Future. (
digital-asset#8690) We use `Future#failed` a _lot_ in the conformance tests. Usually, this works fine, but it has the unfortunate effect of yielding a useless error message when the future was actually a success: ``` Future.failed not completed with a throwable. ``` Combined with the lack of useful stack traces, because futures, this makes the test failure completely useless. This changes all calls of `Future#failed` in our conformance tests to use a new extension method, `#mustFail`, which takes a mandatory "context" parameter to provide context, and includes both the context and the value in the future in case of success. CHANGELOG_BEGIN CHANGELOG_END
- Loading branch information
1 parent
44c7b0b
commit 0d1bc4b
Showing
18 changed files
with
294 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...st-tool/src/main/scala/com/daml/ledger/api/testtool/infrastructure/FutureAssertions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.ledger.api.testtool.infrastructure | ||
|
||
import com.daml.ledger.api.testtool.infrastructure.FutureAssertions.ExpectedFailureException | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
import scala.util.{Failure, Success} | ||
|
||
final class FutureAssertions[T](future: Future[T]) { | ||
|
||
/** Checks that the future failed, and returns the throwable. | ||
* We use this instead of `Future#failed` because the error message that delivers is unhelpful. | ||
* It doesn't tell us what the value actually was. | ||
*/ | ||
def mustFail(context: String)(implicit executionContext: ExecutionContext): Future[Throwable] = | ||
future.transform { | ||
case Failure(throwable) => | ||
Success(throwable) | ||
case Success(value) => | ||
Failure(new ExpectedFailureException(context, value)) | ||
} | ||
} | ||
|
||
object FutureAssertions { | ||
|
||
final class ExpectedFailureException[T](context: String, value: T) | ||
extends NoSuchElementException( | ||
s"Expected a failure when $context, but got a successful result of: $value" | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.