mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-13 11:35:40 +01:00
Fix async bug with destruction of fixtures (#1878)
This commit is contained in:
parent
c6ad90139a
commit
05026e5697
1 changed files with 15 additions and 8 deletions
|
@ -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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue