mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-15 20:30:17 +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](
|
def makeDependentFixture[T](
|
||||||
build: () => Future[T],
|
build: () => Future[T],
|
||||||
destroy: T => Future[Any])(test: OneArgAsyncTest): FutureOutcome = {
|
destroy: T => Future[Any])(test: OneArgAsyncTest): FutureOutcome = {
|
||||||
val fixtureF = build()
|
val fixtureF: Future[T] = build()
|
||||||
|
|
||||||
val outcomeF: Future[Outcome] = fixtureF
|
val outcomeF: Future[Outcome] = fixtureF
|
||||||
.flatMap { fixture =>
|
.flatMap { fixture =>
|
||||||
|
@ -36,14 +36,21 @@ trait BitcoinSFixture extends BitcoinSAsyncFixtureTest {
|
||||||
FutureOutcome.failed(err).toFuture
|
FutureOutcome.failed(err).toFuture
|
||||||
}
|
}
|
||||||
|
|
||||||
val futOutcome: FutureOutcome = new FutureOutcome(outcomeF)
|
val destructedF: Future[Outcome] = outcomeF.transformWith {
|
||||||
|
case Success(o) =>
|
||||||
val result: FutureOutcome = futOutcome.onOutcomeThen { _ =>
|
for {
|
||||||
fixtureF.flatMap(f => destroy(f))
|
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