Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

Commit

Permalink
[WIP] Close all handles during Jest teardown
Browse files Browse the repository at this point in the history
WIP because there's currently a `yalc` local dependency which will be
replaced once comit-network/comit-js-sdk#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.
  • Loading branch information
luckysori committed Mar 28, 2020
1 parent d51db92 commit 3698f3a
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 10 deletions.
2 changes: 1 addition & 1 deletion api_tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion api_tests/src/actor_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 8 additions & 4 deletions api_tests/src/e2e_test_environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions api_tests/src/wallets/bitcoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,8 @@ export class BitcoinWallet implements Wallet {

return blockchainInfo.mediantime;
}

public async close(): Promise<void> {
return this.inner.close();
}
}
14 changes: 14 additions & 0 deletions api_tests/src/wallets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ export class Wallets {
}
}
}

public async close(): Promise<void[]> {
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(
Expand Down
4 changes: 4 additions & 0 deletions api_tests/src/wallets/lightning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,8 @@ export class LightningWallet implements Wallet {
await sleep(500);
return this.pollUntilChannelIsOpen(outpoint);
}

public async close(): Promise<void> {
return this.bitcoinWallet.close();
}
}
6 changes: 2 additions & 4 deletions api_tests/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3698f3a

Please sign in to comment.