mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-19 09:52:09 +01:00
2024 01 31 Refactor BitcoindRpcTestUtil.{startSevers(),stopSevers()}
to use Future.traverse()
(#5382)
* Refactor BitcoindRpcTestUtil.startServers() to use Future.traverse() * Refactor BitcoindRpcTestUtil.stopServers() to use Future.traverse()
This commit is contained in:
parent
451e019225
commit
1685c84eea
@ -42,12 +42,10 @@ import org.bitcoins.util.ListUtil
|
||||
import java.io.File
|
||||
import java.net.{InetSocketAddress, URI}
|
||||
import java.nio.file.{Files, Path}
|
||||
import scala.collection.immutable.Map
|
||||
import scala.collection.mutable
|
||||
import scala.concurrent._
|
||||
import scala.concurrent.duration.{DurationInt, FiniteDuration}
|
||||
import scala.util._
|
||||
import scala.util.control.NonFatal
|
||||
|
||||
//noinspection AccessorLikeMethodIsEmptyParen
|
||||
trait BitcoindRpcTestUtil extends Logging {
|
||||
@ -332,7 +330,7 @@ trait BitcoindRpcTestUtil extends Logging {
|
||||
|
||||
def startServers(servers: Vector[BitcoindRpcClient])(implicit
|
||||
ec: ExecutionContext): Future[Unit] = {
|
||||
val startedServers = servers.map { server =>
|
||||
val startedServersF = Future.traverse(servers) { server =>
|
||||
server.start().flatMap { res =>
|
||||
val createWalletF = for {
|
||||
version <- server.version
|
||||
@ -341,16 +339,13 @@ trait BitcoindRpcTestUtil extends Logging {
|
||||
false
|
||||
case V23 | V24 => true
|
||||
}
|
||||
_ <- res.createWallet("", descriptors = true)
|
||||
_ <- res.createWallet("", descriptors = descriptors)
|
||||
} yield res
|
||||
|
||||
createWalletF.recoverWith { case NonFatal(_) =>
|
||||
Future.successful(res)
|
||||
}
|
||||
createWalletF
|
||||
}
|
||||
}
|
||||
|
||||
Future.sequence(startedServers).map(_ => ())
|
||||
startedServersF.map(_ => ())
|
||||
}
|
||||
|
||||
/** Stops the given servers and deletes their data directories
|
||||
@ -359,7 +354,7 @@ trait BitcoindRpcTestUtil extends Logging {
|
||||
system: ActorSystem): Future[Unit] = {
|
||||
implicit val ec: ExecutionContextExecutor = system.getDispatcher
|
||||
|
||||
val serverStops = servers.map { s =>
|
||||
val serverStopsF = Future.traverse(servers) { s =>
|
||||
val stopF = s.stop()
|
||||
stopF.onComplete {
|
||||
case Failure(exception) =>
|
||||
@ -372,7 +367,7 @@ trait BitcoindRpcTestUtil extends Logging {
|
||||
_ <- removeDataDirectory(s)
|
||||
} yield ()
|
||||
}
|
||||
Future.sequence(serverStops).map(_ => ())
|
||||
serverStopsF.map(_ => ())
|
||||
}
|
||||
|
||||
/** Stops the given server and deletes its data directory
|
||||
|
Loading…
Reference in New Issue
Block a user