Fix async bug with destruction of fixtures (#1878)

This commit is contained in:
Chris Stewart 2020-08-23 07:44:53 -05:00 committed by GitHub
parent c6ad90139a
commit 05026e5697

View file

@ -25,7 +25,7 @@ trait BitcoinSFixture extends BitcoinSAsyncFixtureTest {
def makeDependentFixture[T](
build: () => Future[T],
destroy: T => Future[Any])(test: OneArgAsyncTest): FutureOutcome = {
val fixtureF = build()
val fixtureF: Future[T] = build()
val outcomeF: Future[Outcome] = fixtureF
.flatMap { fixture =>
@ -36,14 +36,21 @@ trait BitcoinSFixture extends BitcoinSAsyncFixtureTest {
FutureOutcome.failed(err).toFuture
}
val futOutcome: FutureOutcome = new FutureOutcome(outcomeF)
val result: FutureOutcome = futOutcome.onOutcomeThen { _ =>
fixtureF.flatMap(f => destroy(f))
()
val destructedF: Future[Outcome] = outcomeF.transformWith {
case Success(o) =>
for {
t <- fixtureF
_ <- destroy(t)
} yield o
case Failure(exn) =>
for {
t <- fixtureF
_ <- destroy(t)
} yield {
throw exn
}
}
result
new FutureOutcome(destructedF)
}
/**