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