50 lines
1.2 KiB
TypeScript
Raw Normal View History

feat: replace `waitForRemotePeers()` with `waku.waitForPeer()` method (#2161) * fix comment of default number of peers * export default number of peers from base protocol sdk * rename to light_push, move class to separate file * move waitForRemotePeer to sdk package * add todo to move waitForGossipSubPeerInMesh into @waku/relay * clean up waitForRemotePeer, split metadata await from event and optimise, decouple from protocol implementations * simplify and rename ILightPush interface * use only connected peers in light push based on connections instead of peer renewal mechanism * improve readability of result processing in light push * fix check & update tests * address tests, add new test cases, fix racing condition in StreamManager * use libp2p.getPeers * feat: confirm metadata and protocols needed in waitForRemotePeer * rely on passed protocols and fallback to mounted * add I prefix to Waku interface * implement waku.connect method * add docs to IWaku interface * remove export and usage of waitForRemotePeer * move wait for remote peer related to Realy out of @waku/sdk * change tests to use new API * fix linting * update size limit * rename .connect to .waitForPeer * export waitForRemotePeer and mark as deprecated * feat: add mocha tests to @waku/sdk and cover waitForRemotePeer (#2163) * feat: add mocha tests to @waku/sdk and cover waitForRemotePeer * add waitForRemote UTs * remove junk * feat: expose peerId and protocols from WakuNode (#2166) * chore: expose peerId and protocols from WakuNode * remove unused method * move to private method * rename to waitForPeers * up test
2024-10-09 00:43:34 +02:00
import { IWaku } 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[],
feat: replace `waitForRemotePeers()` with `waku.waitForPeer()` method (#2161) * fix comment of default number of peers * export default number of peers from base protocol sdk * rename to light_push, move class to separate file * move waitForRemotePeer to sdk package * add todo to move waitForGossipSubPeerInMesh into @waku/relay * clean up waitForRemotePeer, split metadata await from event and optimise, decouple from protocol implementations * simplify and rename ILightPush interface * use only connected peers in light push based on connections instead of peer renewal mechanism * improve readability of result processing in light push * fix check & update tests * address tests, add new test cases, fix racing condition in StreamManager * use libp2p.getPeers * feat: confirm metadata and protocols needed in waitForRemotePeer * rely on passed protocols and fallback to mounted * add I prefix to Waku interface * implement waku.connect method * add docs to IWaku interface * remove export and usage of waitForRemotePeer * move wait for remote peer related to Realy out of @waku/sdk * change tests to use new API * fix linting * update size limit * rename .connect to .waitForPeer * export waitForRemotePeer and mark as deprecated * feat: add mocha tests to @waku/sdk and cover waitForRemotePeer (#2163) * feat: add mocha tests to @waku/sdk and cover waitForRemotePeer * add waitForRemote UTs * remove junk * feat: expose peerId and protocols from WakuNode (#2166) * chore: expose peerId and protocols from WakuNode * remove unused method * move to private method * rename to waitForPeers * up test
2024-10-09 00:43:34 +02:00
wakuNodes: IWaku | IWaku[]
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]);
}