Improve lnd test suite reliability (#4361)

This commit is contained in:
benthecarman 2022-06-01 14:28:35 -05:00 committed by GitHub
parent 4fc3b05ed5
commit 54c3f77f8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -106,11 +106,15 @@ class LndRpcClient(val instance: LndInstance, binaryOpt: Option[File] = None)(
applier: CallCredentials.MetadataApplier applier: CallCredentials.MetadataApplier
): Unit = { ): Unit = {
appExecutor.execute(() => { appExecutor.execute(() => {
// Wrap in a try, in case the macaroon hasn't been created yet.
Try {
val metadata = new Metadata() val metadata = new Metadata()
val key = val key =
Metadata.Key.of(macaroonKey, Metadata.ASCII_STRING_MARSHALLER) Metadata.Key.of(macaroonKey, Metadata.ASCII_STRING_MARSHALLER)
metadata.put(key, instance.macaroon) metadata.put(key, instance.macaroon)
applier(metadata) applier(metadata)
}
()
}) })
} }
@ -141,6 +145,7 @@ class LndRpcClient(val instance: LndInstance, binaryOpt: Option[File] = None)(
lazy val signer: SignerClient = SignerClient(clientSettings) lazy val signer: SignerClient = SignerClient(clientSettings)
lazy val router: RouterClient = RouterClient(clientSettings) lazy val router: RouterClient = RouterClient(clientSettings)
lazy val invoices: InvoicesClient = InvoicesClient(clientSettings) lazy val invoices: InvoicesClient = InvoicesClient(clientSettings)
lazy val stateClient: StateClient = StateClient(clientSettings)
def genSeed(): Future[GenSeedResponse] = { def genSeed(): Future[GenSeedResponse] = {
logger.trace("lnd calling genseed") logger.trace("lnd calling genseed")
@ -973,9 +978,16 @@ class LndRpcClient(val instance: LndInstance, binaryOpt: Option[File] = None)(
def isStarted: Future[Boolean] = { def isStarted: Future[Boolean] = {
val p = Promise[Boolean]() val p = Promise[Boolean]()
Try(getInfo.onComplete { Try(stateClient.getState(GetStateRequest()).onComplete {
case Success(_) => case Success(state) =>
state.state match {
case WalletState.RPC_ACTIVE | WalletState.SERVER_ACTIVE =>
p.success(true) p.success(true)
case _: WalletState.Unrecognized |
WalletState.WAITING_TO_START | WalletState.UNLOCKED |
WalletState.LOCKED | WalletState.NON_EXISTING =>
p.success(false)
}
case Failure(_) => case Failure(_) =>
p.success(false) p.success(false)
}) })