50 lines
1.2 KiB
TypeScript
Raw Normal View History

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