Danish Arora 26ab836900
chore: upgrade nwaku to 0.34.0 and update tests suite for compatibility (#2170)
* chore: upgrade nwaku to v0.33.1

* chore: upgrade to nwaku 0.34.0

* feat: connect nwaku nodes amongst each other over relay

* chore(lightpush): use multiple service nodes for lightpush (instead of just one)
- nwaku now expects >=1 nodes at least connected

* chore: all single-node lightpush requests should now be expected to fail

* chore: update sharding tests

* chore: update tests

* chore: improve Docker network config reliability

* chore: deduplicate ecies encrypted payloads

* chore: update to precise expects

* fix: return early if expect passes

* chore: lightpush 5 times instead of 30

* fix: non duplicacy should happen in application-specific scenario

* chore: update mocha config + fix epehermal tests

* chore: reinstall deps after rebase

* chore: attempt stability for test suite

* fix: store tests to now use multiple nodes, delete uneeded test

* fix: memory leak

* chore: switch while loop with timeout-promise

* chore: remove redundant nodes startup

* chore: add delays for nwaku setup
2025-02-17 19:21:33 +05:30

62 lines
1.6 KiB
TypeScript

import { IWaku } from "@waku/interfaces";
import { Logger } from "@waku/utils";
import pRetry from "p-retry";
import { ServiceNode } from "../lib/service_node.js";
const log = new Logger("test:teardown");
const TEARDOWN_TIMEOUT = 10000; // 10 seconds timeout for teardown
export async function tearDownNodes(
nwakuNodes: ServiceNode | ServiceNode[],
wakuNodes: IWaku | IWaku[]
): Promise<void> {
const nNodes = Array.isArray(nwakuNodes) ? nwakuNodes : [nwakuNodes];
const wNodes = Array.isArray(wakuNodes) ? wakuNodes : [wakuNodes];
try {
// Use Promise.race to implement timeout
const teardownPromise = Promise.all([
...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, minTimeout: 1000 }
);
}
}),
...wNodes.map(async (waku) => {
if (waku) {
try {
await waku.stop();
} catch (error) {
log.error("Waku failed to stop:", error);
}
}
})
]);
await Promise.race([
teardownPromise,
new Promise((_, reject) =>
setTimeout(
() => reject(new Error("Teardown timeout")),
TEARDOWN_TIMEOUT
)
)
]);
} catch (error) {
log.error("Teardown failed:", error);
// Force process cleanup if needed
process.exit(1);
}
}