From 3698f3a621fc309a768ce7511f391e297be49c5a Mon Sep 17 00:00:00 2001 From: Lucas Soriano del Pino Date: Sat, 28 Mar 2020 15:42:16 +1100 Subject: [PATCH] [WIP] Close all handles during Jest teardown WIP because there's currently a `yalc` local dependency which will be replaced once https://github.com/comit-network/comit-js-sdk/pull/176 is merged and `comit-js-sdk` is released with its changes. We ensure that all nodes are stopped and all wallets are closed during Jest teardown. --- api_tests/package.json | 2 +- api_tests/src/actor_test.ts | 3 ++- api_tests/src/e2e_test_environment.ts | 12 ++++++++---- api_tests/src/wallets/bitcoin.ts | 4 ++++ api_tests/src/wallets/index.ts | 14 ++++++++++++++ api_tests/src/wallets/lightning.ts | 4 ++++ api_tests/yarn.lock | 6 ++---- 7 files changed, 35 insertions(+), 10 deletions(-) diff --git a/api_tests/package.json b/api_tests/package.json index 6bfbdab71d..a43e9009b3 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -43,7 +43,7 @@ "chai-json-schema": "^1.5.0", "chai-string": "^1.5.0", "chai-subset": "^1.6.0", - "comit-sdk": "^0.15.0", + "comit-sdk": "file:.yalc/comit-sdk", "ethers": "^4.0.46", "get-port": "^5.1.1", "jasmine": "^3.5.0", diff --git a/api_tests/src/actor_test.ts b/api_tests/src/actor_test.ts index 6c42e04121..cc1895edbd 100644 --- a/api_tests/src/actor_test.ts +++ b/api_tests/src/actor_test.ts @@ -32,7 +32,8 @@ function nActorTest( throw e; } finally { for (const actorName of actorNames) { - await actors.getActorByName(actorName).stop(); + const actor = actors.getActorByName(actorName); + await Promise.all([actor.stop(), actor.wallets.close()]); } } done(); diff --git a/api_tests/src/e2e_test_environment.ts b/api_tests/src/e2e_test_environment.ts index eecf121c33..f830aab435 100644 --- a/api_tests/src/e2e_test_environment.ts +++ b/api_tests/src/e2e_test_environment.ts @@ -258,19 +258,23 @@ export default class E2ETestEnvironment extends NodeEnvironment { const tasks = []; if (this.bitcoinLedger) { - tasks.push(this.bitcoinLedger.stop); + tasks.push(this.bitcoinLedger.stop()); } if (this.ethereumLedger) { - tasks.push(this.ethereumLedger.stop); + tasks.push(this.ethereumLedger.stop()); } if (this.aliceLightning) { - tasks.push(this.aliceLightning.stop); + tasks.push(this.aliceLightning.stop()); } if (this.bobLightning) { - tasks.push(this.bobLightning.stop); + tasks.push(this.bobLightning.stop()); + } + + for (const [, wallet] of Object.entries(this.global.lndWallets)) { + tasks.push(wallet.close()); } await Promise.all(tasks); diff --git a/api_tests/src/wallets/bitcoin.ts b/api_tests/src/wallets/bitcoin.ts index bbb29ef634..d83aa8a0a6 100644 --- a/api_tests/src/wallets/bitcoin.ts +++ b/api_tests/src/wallets/bitcoin.ts @@ -98,4 +98,8 @@ export class BitcoinWallet implements Wallet { return blockchainInfo.mediantime; } + + public async close(): Promise { + return this.inner.close(); + } } diff --git a/api_tests/src/wallets/index.ts b/api_tests/src/wallets/index.ts index 13e283cf76..6a189b90dd 100644 --- a/api_tests/src/wallets/index.ts +++ b/api_tests/src/wallets/index.ts @@ -83,6 +83,20 @@ export class Wallets { } } } + + public async close(): Promise { + const tasks = []; + + if (this.wallets.lightning) { + tasks.push(this.wallets.lightning.close()); + } + + if (this.wallets.bitcoin) { + tasks.push(this.wallets.bitcoin.close()); + } + + return Promise.all(tasks); + } } export async function pollUntilMinted( diff --git a/api_tests/src/wallets/lightning.ts b/api_tests/src/wallets/lightning.ts index b5540d1a24..52c51046e6 100644 --- a/api_tests/src/wallets/lightning.ts +++ b/api_tests/src/wallets/lightning.ts @@ -172,4 +172,8 @@ export class LightningWallet implements Wallet { await sleep(500); return this.pollUntilChannelIsOpen(outpoint); } + + public async close(): Promise { + return this.bitcoinWallet.close(); + } } diff --git a/api_tests/yarn.lock b/api_tests/yarn.lock index 571c23b4f6..028aaaad00 100644 --- a/api_tests/yarn.lock +++ b/api_tests/yarn.lock @@ -1562,10 +1562,8 @@ combined-stream@^1.0.6, combined-stream@~1.0.6: dependencies: delayed-stream "~1.0.0" -comit-sdk@^0.15.0: - version "0.15.0" - resolved "https://registry.yarnpkg.com/comit-sdk/-/comit-sdk-0.15.0.tgz#d825b19e89bd5920bb5c7f1b0907259d6b9f93af" - integrity sha512-JsBkboA2gI4HT/2zCKqU9vV4rBKxX9PkJsM8RmH2EPXIgpeSZ4S7+jRha88k0Kiu7RvdHp84HvkqrVjmDbWfFw== +"comit-sdk@file:.yalc/comit-sdk": + version "0.15.0-318ac369" dependencies: "@radar/lnrpc" "^0.9.1-beta" axios "^0.19.0"