2022 10 07 node test fixes (#4819)

* Add CachedBitcoindPairNewest

* Try to get ReConnectionTest to use test fixtures

* Empty commit to run CI
This commit is contained in:
Chris Stewart 2022-10-07 09:49:25 -05:00 committed by GitHub
parent 62081a43ec
commit 718053668d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 44 deletions

View File

@ -1,63 +1,68 @@
package org.bitcoins.node.networking
import org.bitcoins.asyncutil.AsyncUtil
import org.bitcoins.asyncutil.AsyncUtil.RpcRetryException
import org.bitcoins.node.models.Peer
import org.bitcoins.node.networking.peer.PeerHandler
import org.bitcoins.server.BitcoinSAppConfig
import org.bitcoins.testkit.BitcoinSTestAppConfig
import org.bitcoins.testkit.node.fixture.NeutrinoNodeConnectedWithBitcoind
import org.bitcoins.testkit.node.{
CachedBitcoinSAppConfig,
NodeTestUtil,
NodeTestWithCachedBitcoindNewest,
NodeUnitTest
}
import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil
import org.bitcoins.testkit.util.{AkkaUtil, BitcoindRpcTest}
import org.bitcoins.testkit.util.AkkaUtil
import org.scalatest.FutureOutcome
import scala.concurrent.Future
import scala.concurrent.duration.DurationInt
class ReConnectionTest extends BitcoindRpcTest with CachedBitcoinSAppConfig {
class ReConnectionTest extends NodeTestWithCachedBitcoindNewest {
lazy val bitcoindRpcF =
BitcoindRpcTestUtil.startedBitcoindRpcClient(clientAccum = clientAccum)
override protected def getFreshConfig: BitcoinSAppConfig =
BitcoinSTestAppConfig.getNeutrinoWithEmbeddedDbTestConfig(pgUrl)
lazy val bitcoindPeerF: Future[Peer] =
bitcoindRpcF.flatMap(b => NodeTestUtil.getBitcoindPeer(b))
override type FixtureParam = NeutrinoNodeConnectedWithBitcoind
override def withFixture(test: OneArgAsyncTest): FutureOutcome = {
val f = for {
bitcoind <- cachedBitcoindWithFundsF
outcome <- withNeutrinoNodeUnstarted(test, bitcoind)(
system,
getFreshConfig).toFuture
} yield outcome
new FutureOutcome(f)
}
behavior of "ReConnectionTest"
it must "attempt to reconnect if max connections are full" in {
val peerHandlerF: Future[PeerHandler] = for {
_ <- cachedConfig.start()
peer <- bitcoindPeerF.flatMap(p => NodeUnitTest.buildPeerHandler(p, None))
} yield peer
nodeConnectedWithBitcoind: NeutrinoNodeConnectedWithBitcoind =>
val bitcoind = nodeConnectedWithBitcoind.bitcoind
val node = nodeConnectedWithBitcoind.node
val peerF = NodeTestUtil.getBitcoindPeer(bitcoind)
val peerHandlerF: Future[PeerHandler] = peerF.flatMap { peer =>
NodeUnitTest.buildPeerHandler(peer, None)(node.nodeConfig,
node.chainConfig,
system)
}
val connectedF = for {
peerHandler <- peerHandlerF
bitcoindRpc <- bitcoindRpcF
val connectedF = for {
_ <- node.start()
peerHandler <- peerHandlerF
_ = peerHandler.peerMsgSender.connect()
_ <- AsyncUtil.retryUntilSatisfiedF(() =>
peerHandler.p2pClient.isInitialized())
nodeUri <- NodeTestUtil.getNodeURIFromBitcoind(bitcoind)
_ <- bitcoind.disconnectNode(nodeUri)
_ <- AkkaUtil.nonBlockingSleep(2.seconds) //time to ensure disconnection
//now we should eventually automatically reconnect
_ <- AsyncUtil.retryUntilSatisfiedF(
conditionF = () => peerHandler.p2pClient.isConnected(),
interval = 500.millis,
maxTries = 60)
} yield succeed
_ = peerHandler.peerMsgSender.connect()
_ <- AsyncUtil
.retryUntilSatisfiedF(() => peerHandler.p2pClient.isInitialized())
.recover { case _: RpcRetryException =>
//expect this to fail, we cannot connect
//because maxconnections=0
()
}
nodeUri <- NodeTestUtil.getNodeURIFromBitcoind(bitcoindRpc)
_ <- bitcoindRpc.disconnectNode(nodeUri)
_ <- AkkaUtil.nonBlockingSleep(2.seconds) //time to ensure disconnection
//now we should eventually automatically reconnect
_ <- AsyncUtil.retryUntilSatisfiedF(
conditionF = () => peerHandler.p2pClient.isConnected(),
interval = 500.millis,
maxTries = 60)
} yield succeed
connectedF
}
override def afterAll(): Unit = {
super[CachedBitcoinSAppConfig].afterAll()
super[BitcoindRpcTest].afterAll()
connectedF
}
}

View File

@ -14,7 +14,7 @@ import org.bitcoins.testkit.node.fixture.{
import org.bitcoins.testkit.rpc.{
CachedBitcoind,
CachedBitcoindNewest,
CachedBitcoindPairV22,
CachedBitcoindPairNewest,
CachedBitcoindV19
}
import org.bitcoins.testkit.tor.CachedTor
@ -216,10 +216,10 @@ trait NodeTestWithCachedBitcoindNewest
trait NodeTestWithCachedBitcoindPair
extends NodeTestWithCachedBitcoind
with CachedBitcoindPairV22 {
with CachedBitcoindPairNewest {
override def afterAll(): Unit = {
super[CachedBitcoindPairV22].afterAll()
super[CachedBitcoindPairNewest].afterAll()
super[NodeTestWithCachedBitcoind].afterAll()
}
}

View File

@ -291,6 +291,25 @@ trait CachedBitcoindPairV22
}
}
trait CachedBitcoindPairNewest
extends CachedBitcoindCollection[BitcoindRpcClient] {
_: BitcoinSAkkaAsyncTest =>
override val version: BitcoindVersion = BitcoindVersion.newest
lazy val clientsF: Future[NodePair[BitcoindV22RpcClient]] = {
BitcoindRpcTestUtil
.createNodePair[BitcoindV22RpcClient](version)
.map(NodePair.fromTuple)
.map { tuple =>
isClientsUsed.set(true)
val clients = cachedClients.get()
cachedClients.set(clients ++ tuple.toVector)
tuple
}
}
}
trait CachedBitcoindTriple[T <: BitcoindRpcClient]
extends CachedBitcoindCollection[T] {
_: BitcoinSAkkaAsyncTest =>