mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-15 20:30:17 +01:00
parent
98ecdf7ac3
commit
85975b8b07
2 changed files with 27 additions and 14 deletions
|
@ -31,13 +31,22 @@ class NeutrinoNodeTest extends NodeTestWithCachedBitcoindPair {
|
||||||
|
|
||||||
behavior of "NeutrinoNode"
|
behavior of "NeutrinoNode"
|
||||||
|
|
||||||
it must "be able to connect and then disconnect from all peers" in {
|
it must "be able to connect,initialize and then disconnect from all peers" in {
|
||||||
nodeConnectedWithBitcoind: NeutrinoNodeConnectedWithBitcoinds =>
|
nodeConnectedWithBitcoind: NeutrinoNodeConnectedWithBitcoinds =>
|
||||||
//checking all peers are connected
|
//checking all peers are connected
|
||||||
val node = nodeConnectedWithBitcoind.node
|
val node = nodeConnectedWithBitcoind.node
|
||||||
val connFs = node.peers.indices.map(node.isConnected)
|
val connFs = node.peers.indices.map(node.isConnected)
|
||||||
val connF = Future.sequence(connFs).map(_.forall(_ == true))
|
val connF = Future.sequence(connFs).map(_.forall(_ == true))
|
||||||
val assertion1F = connF.map(assert(_))
|
val connAssertion = connF.map(assert(_))
|
||||||
|
|
||||||
|
//checking all peers are initialized
|
||||||
|
val isInitializedFs = node.peers.indices.map(node.isInitialized)
|
||||||
|
val isInitializedF = for {
|
||||||
|
_ <- connAssertion
|
||||||
|
f <- Future.sequence(isInitializedFs).map(_.forall(_ == true))
|
||||||
|
} yield f
|
||||||
|
|
||||||
|
val initAssertion = isInitializedF.map(assert(_))
|
||||||
|
|
||||||
//checking all peers can be disconnected
|
//checking all peers can be disconnected
|
||||||
def isAllDisconnectedF: Future[Boolean] = {
|
def isAllDisconnectedF: Future[Boolean] = {
|
||||||
|
@ -46,7 +55,7 @@ class NeutrinoNodeTest extends NodeTestWithCachedBitcoindPair {
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
val disconnF = for {
|
val disconnF = for {
|
||||||
_ <- assertion1F
|
_ <- initAssertion
|
||||||
_ <- node.stop()
|
_ <- node.stop()
|
||||||
f <- isAllDisconnectedF
|
f <- isAllDisconnectedF
|
||||||
} yield f
|
} yield f
|
||||||
|
|
|
@ -126,18 +126,22 @@ trait Node extends NodeApi with ChainQueryApi with P2PLogger {
|
||||||
val chainApiF = startConfsF.flatMap(_ => chainApiFromDb())
|
val chainApiF = startConfsF.flatMap(_ => chainApiFromDb())
|
||||||
|
|
||||||
val startNodeF = {
|
val startNodeF = {
|
||||||
peerMsgSenders.foreach(_.connect())
|
val isInitializedFs = peerMsgSenders.indices.map { idx =>
|
||||||
|
peerMsgSenders(idx).connect()
|
||||||
val isInitializedF = for {
|
val isInitializedF = for {
|
||||||
_ <- AsyncUtil.retryUntilSatisfiedF(() => isInitialized(0),
|
_ <- AsyncUtil.retryUntilSatisfiedF(() => isInitialized(idx),
|
||||||
maxTries = 200,
|
maxTries = 200,
|
||||||
interval = 250.millis)
|
interval = 250.millis)
|
||||||
} yield ()
|
} yield ()
|
||||||
|
|
||||||
isInitializedF.failed.foreach(err =>
|
isInitializedF.failed.foreach(err =>
|
||||||
logger.error(s"Failed to connect with peer=${peers(0)} with err=$err"))
|
logger.error(
|
||||||
|
s"Failed to connect with peer=${peers(idx)} with err=$err"))
|
||||||
isInitializedF.map { _ =>
|
isInitializedF.map { _ =>
|
||||||
logger.info(s"Our peer=${peers(0)} has been initialized")
|
logger.info(s"Our peer=${peers(idx)} has been initialized")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future.sequence(isInitializedFs).map { _ =>
|
||||||
logger.info(s"Our node has been full started. It took=${System
|
logger.info(s"Our node has been full started. It took=${System
|
||||||
.currentTimeMillis() - start}ms")
|
.currentTimeMillis() - start}ms")
|
||||||
this
|
this
|
||||||
|
|
Loading…
Add table
Reference in a new issue