js-waku/packages/tests/src/teardown.ts
Danish Arora 0f7d63ef93
feat: Logger with log levels (#1672)
* setup a custom Logger with log level support

* refactor codebase for to use new Logger with log levels

* disallow usage of `debug` directly / only allow usage in/through custom Logger

* remove `debug` from logger
2023-10-20 16:36:47 +05:30

50 lines
1.2 KiB
TypeScript

import { Waku } from "@waku/interfaces";
import { Logger } from "@waku/utils";
import pRetry from "p-retry";
import { NimGoNode } from "./index.js";
const log = new Logger("test:teardown");
export async function tearDownNodes(
nwakuNodes: NimGoNode | NimGoNode[],
wakuNodes: Waku | Waku[]
): Promise<void> {
const nNodes = Array.isArray(nwakuNodes) ? nwakuNodes : [nwakuNodes];
const wNodes = Array.isArray(wakuNodes) ? wakuNodes : [wakuNodes];
const stopNwakuNodes = nNodes.map(async (nwaku) => {
if (nwaku) {
await pRetry(
async () => {
try {
await nwaku.stop();
} catch (error) {
log.error("Nwaku failed to stop:", error);
throw error;
}
},
{ retries: 3 }
);
}
});
const stopWakuNodes = wNodes.map(async (waku) => {
if (waku) {
await pRetry(
async () => {
try {
await waku.stop();
} catch (error) {
log.error("Waku failed to stop:", error);
throw error;
}
},
{ retries: 3 }
);
}
});
await Promise.all([...stopNwakuNodes, ...stopWakuNodes]);
}