Fix postgres database not clearing after test (#4558)

* fix postgres database not clearing after test

* Empty commit to run CI

Co-authored-by: Chris Stewart <stewart.chris1234@gmail.com>
This commit is contained in:
Shreyansh 2022-08-01 18:19:55 +05:30 committed by GitHub
parent f487c1270e
commit 8b646802b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 20 deletions

View file

@ -52,7 +52,7 @@ trait NodeTestWithCachedBitcoind extends BaseNodeTest with CachedTor {
makeDependentFixture[NeutrinoNodeConnectedWithBitcoind]( makeDependentFixture[NeutrinoNodeConnectedWithBitcoind](
build = nodeWithBitcoindBuilder, build = nodeWithBitcoindBuilder,
{ x: NeutrinoNodeConnectedWithBitcoind => { x: NeutrinoNodeConnectedWithBitcoind =>
NodeUnitTest.destroyNode(x.node) NodeUnitTest.destroyNode(x.node, appConfig)
})(test) })(test)
} }
@ -75,7 +75,7 @@ trait NodeTestWithCachedBitcoind extends BaseNodeTest with CachedTor {
makeDependentFixture[NeutrinoNodeConnectedWithBitcoind]( makeDependentFixture[NeutrinoNodeConnectedWithBitcoind](
build = nodeWithBitcoindBuilder, build = nodeWithBitcoindBuilder,
{ x: NeutrinoNodeConnectedWithBitcoind => { x: NeutrinoNodeConnectedWithBitcoind =>
tearDownNode(x.node) tearDownNode(x.node, appConfig)
})(test) })(test)
} }
@ -100,7 +100,7 @@ trait NodeTestWithCachedBitcoind extends BaseNodeTest with CachedTor {
makeDependentFixture[NeutrinoNodeConnectedWithBitcoinds]( makeDependentFixture[NeutrinoNodeConnectedWithBitcoinds](
build = nodeWithBitcoindBuilder, build = nodeWithBitcoindBuilder,
{ x: NeutrinoNodeConnectedWithBitcoinds => { x: NeutrinoNodeConnectedWithBitcoinds =>
tearDownNode(x.node) tearDownNode(x.node, appConfig)
})(test) })(test)
} }
@ -124,7 +124,7 @@ trait NodeTestWithCachedBitcoind extends BaseNodeTest with CachedTor {
makeDependentFixture[NeutrinoNodeConnectedWithBitcoinds]( makeDependentFixture[NeutrinoNodeConnectedWithBitcoinds](
build = nodeWithBitcoindBuilder, build = nodeWithBitcoindBuilder,
{ x: NeutrinoNodeConnectedWithBitcoinds => { x: NeutrinoNodeConnectedWithBitcoinds =>
tearDownNode(x.node) tearDownNode(x.node, appConfig)
})(test) })(test)
} }
@ -148,7 +148,7 @@ trait NodeTestWithCachedBitcoind extends BaseNodeTest with CachedTor {
makeDependentFixture[NeutrinoNodeConnectedWithBitcoind]( makeDependentFixture[NeutrinoNodeConnectedWithBitcoind](
build = nodeWithBitcoindBuilder, build = nodeWithBitcoindBuilder,
{ x: NeutrinoNodeConnectedWithBitcoind => { x: NeutrinoNodeConnectedWithBitcoind =>
tearDownNode(x.node) tearDownNode(x.node, appConfig)
})(test) })(test)
} }
@ -165,7 +165,7 @@ trait NodeTestWithCachedBitcoind extends BaseNodeTest with CachedTor {
bitcoind, bitcoind,
walletCallbacks = walletCallbacks)(system, appConfig), walletCallbacks = walletCallbacks)(system, appConfig),
{ x: NeutrinoNodeFundedWalletBitcoind => { x: NeutrinoNodeFundedWalletBitcoind =>
tearDownNodeWithBitcoind(x) tearDownNodeWithBitcoind(x, appConfig)
} }
)(test) )(test)
} }
@ -180,9 +180,10 @@ trait NodeTestWithCachedBitcoind extends BaseNodeTest with CachedTor {
} }
private def tearDownNodeWithBitcoind( private def tearDownNodeWithBitcoind(
nodeWithBitcoind: NodeFundedWalletBitcoind): Future[Unit] = { nodeWithBitcoind: NodeFundedWalletBitcoind,
appConfig: BitcoinSAppConfig): Future[Unit] = {
val node = nodeWithBitcoind.node val node = nodeWithBitcoind.node
val destroyNodeF = tearDownNode(node) val destroyNodeF = tearDownNode(node, appConfig)
val destroyWalletF = val destroyWalletF =
BitcoinSWalletTest.destroyWallet(nodeWithBitcoind.wallet) BitcoinSWalletTest.destroyWallet(nodeWithBitcoind.wallet)
for { for {
@ -191,8 +192,10 @@ trait NodeTestWithCachedBitcoind extends BaseNodeTest with CachedTor {
} yield () } yield ()
} }
private def tearDownNode(node: Node): Future[Unit] = { private def tearDownNode(
val destroyNodeF = NodeUnitTest.destroyNode(node) node: Node,
appConfig: BitcoinSAppConfig): Future[Unit] = {
val destroyNodeF = NodeUnitTest.destroyNode(node, appConfig)
for { for {
_ <- destroyNodeF _ <- destroyNodeF
//need to stop chainAppConfig too since this is a test //need to stop chainAppConfig too since this is a test

View file

@ -1,6 +1,7 @@
package org.bitcoins.testkit.node package org.bitcoins.testkit.node
import akka.actor.ActorSystem import akka.actor.ActorSystem
import org.bitcoins.asyncutil.AsyncUtil
import org.bitcoins.chain.blockchain.ChainHandlerCached import org.bitcoins.chain.blockchain.ChainHandlerCached
import org.bitcoins.chain.config.ChainAppConfig import org.bitcoins.chain.config.ChainAppConfig
import org.bitcoins.chain.models._ import org.bitcoins.chain.models._
@ -29,6 +30,7 @@ import org.scalatest.FutureOutcome
import java.net.InetSocketAddress import java.net.InetSocketAddress
import java.time.Instant import java.time.Instant
import scala.concurrent.duration.DurationInt
import scala.concurrent.{ExecutionContext, Future} import scala.concurrent.{ExecutionContext, Future}
trait NodeUnitTest extends BaseNodeTest { trait NodeUnitTest extends BaseNodeTest {
@ -234,13 +236,15 @@ object NodeUnitTest extends P2PLogger {
} }
def destroyNode(node: Node)(implicit ec: ExecutionContext): Future[Unit] = { def destroyNode(node: Node, appConfig: BitcoinSAppConfig)(implicit
ec: ExecutionContext): Future[Unit] = {
for { for {
_ <- node.stop() _ <- node.stop()
_ <- node.nodeAppConfig.stop() _ <- node.nodeAppConfig.stop()
_ <- node.chainAppConfig.stop() _ <- node.chainAppConfig.stop()
} yield { } yield {
() cleanTables(appConfig)
} }
} }
@ -253,9 +257,8 @@ object NodeUnitTest extends P2PLogger {
val node = nodeConnectedWithBitcoind.node val node = nodeConnectedWithBitcoind.node
val bitcoind = nodeConnectedWithBitcoind.bitcoind val bitcoind = nodeConnectedWithBitcoind.bitcoind
val resultF = for { val resultF = for {
_ <- destroyNode(node) _ <- destroyNode(node, appConfig)
_ <- ChainUnitTest.destroyBitcoind(bitcoind) _ <- ChainUnitTest.destroyBitcoind(bitcoind)
_ = cleanTables(appConfig)
_ <- appConfig.stop() _ <- appConfig.stop()
} yield { } yield {
logger.debug(s"Done with teardown of node connected with bitcoind!") logger.debug(s"Done with teardown of node connected with bitcoind!")
@ -274,8 +277,7 @@ object NodeUnitTest extends P2PLogger {
import system.dispatcher import system.dispatcher
val node = nodeConnectedWithBitcoind.node val node = nodeConnectedWithBitcoind.node
val resultF = for { val resultF = for {
_ <- destroyNode(node) _ <- destroyNode(node, appConfig)
_ = cleanTables(appConfig)
_ <- appConfig.stop() _ <- appConfig.stop()
} yield { } yield {
logger.debug(s"Done with teardown of node connected with bitcoind!") logger.debug(s"Done with teardown of node connected with bitcoind!")
@ -513,9 +515,13 @@ object NodeUnitTest extends P2PLogger {
_ <- NodeTestUtil.awaitSync(node, bitcoind) _ <- NodeTestUtil.awaitSync(node, bitcoind)
_ <- NodeTestUtil.awaitCompactFilterHeadersSync(node, bitcoind) _ <- NodeTestUtil.awaitCompactFilterHeadersSync(node, bitcoind)
_ <- NodeTestUtil.awaitCompactFiltersSync(node, bitcoind) _ <- NodeTestUtil.awaitCompactFiltersSync(node, bitcoind)
syncing <- node.chainApiFromDb().flatMap(_.isSyncing()) _ <- AsyncUtil.retryUntilSatisfiedF(
_ = assert(!syncing) () => {
val syncingF = node.chainApiFromDb().flatMap(_.isSyncing())
syncingF.map(!_)
},
interval = 1.second,
maxTries = 5)
} yield node } yield node
} }
@ -527,7 +533,7 @@ object NodeUnitTest extends P2PLogger {
*/ */
private def cleanTables(appConfig: BitcoinSAppConfig): Unit = { private def cleanTables(appConfig: BitcoinSAppConfig): Unit = {
appConfig.nodeConf.clean() appConfig.nodeConf.clean()
//appConfig.walletConf.clean() appConfig.walletConf.clean()
appConfig.chainConf.clean() appConfig.chainConf.clean()
() ()
} }