diff --git a/packages/tests/src/utils/custom_mocha_hooks.ts b/packages/tests/src/utils/custom_mocha_hooks.ts index b2c4a43722..1f55855a23 100644 --- a/packages/tests/src/utils/custom_mocha_hooks.ts +++ b/packages/tests/src/utils/custom_mocha_hooks.ts @@ -7,7 +7,7 @@ const log = new Logger("test:mocha-hook"); function withGracefulTimeout( asyncOperation: () => Promise, doneCallback: (error?: unknown) => void, - timeoutDuration: number = MOCHA_HOOK_MAX_TIMEOUT + timeoutDuration = MOCHA_HOOK_MAX_TIMEOUT ): void { let operationCompleted = false; @@ -45,24 +45,26 @@ function withGracefulTimeout( export const beforeEachCustom = function ( suite: Suite, - cb: () => Promise + cb: () => Promise, + timeout = MOCHA_HOOK_MAX_TIMEOUT ): void { const timeoutBefore = suite.timeout(); - suite.timeout(MOCHA_HOOK_MAX_TIMEOUT); + suite.timeout(timeout); suite.beforeEach((done) => { - withGracefulTimeout(cb, done); + withGracefulTimeout(cb, done, timeout); }); suite.timeout(timeoutBefore); // restore timeout to the original value }; export const afterEachCustom = function ( suite: Suite, - cb: () => Promise + cb: () => Promise, + timeout = MOCHA_HOOK_MAX_TIMEOUT ): void { const timeoutBefore = suite.timeout(); - suite.timeout(MOCHA_HOOK_MAX_TIMEOUT); + suite.timeout(timeout); suite.afterEach((done) => { - withGracefulTimeout(cb, done); + withGracefulTimeout(cb, done, timeout); }); suite.timeout(timeoutBefore); // restore timeout to the original value }; diff --git a/packages/tests/tests/peer-exchange/index.spec.ts b/packages/tests/tests/peer-exchange/index.spec.ts index af49d30640..84aea0fb86 100644 --- a/packages/tests/tests/peer-exchange/index.spec.ts +++ b/packages/tests/tests/peer-exchange/index.spec.ts @@ -19,7 +19,7 @@ export const log = new Logger("test:pe"); const pubsubTopic = [singleShardInfoToPubsubTopic({ clusterId: 0, shard: 2 })]; describe("Peer Exchange", function () { - this.timeout(100_000); + this.timeout(150_000); let waku: LightNode; let nwaku1: ServiceNode; let nwaku2: ServiceNode; @@ -96,7 +96,8 @@ describe("Peer Exchange", function () { expect(connected_bootstram.length).to.eq(1); }); - it("new peer added after a peer was already found", async function () { + // will be skipped until https://github.com/waku-org/js-waku/issues/1860 is fixed + it.skip("new peer added after a peer was already found", async function () { waku = await createLightNode({ libp2p: { peerDiscovery: [ diff --git a/packages/tests/tests/peer-exchange/query.spec.ts b/packages/tests/tests/peer-exchange/query.spec.ts index 09603cd325..2ed1e782ce 100644 --- a/packages/tests/tests/peer-exchange/query.spec.ts +++ b/packages/tests/tests/peer-exchange/query.spec.ts @@ -26,7 +26,7 @@ export const log = new Logger("test:pe"); const pubsubTopic = [singleShardInfoToPubsubTopic({ clusterId: 0, shard: 2 })]; -describe("Query", function () { +describe("Peer Exchange Query", function () { this.timeout(30_000); let waku: LightNode; let nwaku1: ServiceNode; @@ -40,63 +40,67 @@ describe("Query", function () { let numPeersToRequest: number; let peerInfos: PeerInfo[]; - beforeEachCustom(this, async () => { - nwaku1 = new ServiceNode(makeLogFileName(this.ctx) + "1"); - nwaku2 = new ServiceNode(makeLogFileName(this.ctx) + "2"); - nwaku3 = new ServiceNode(makeLogFileName(this.ctx) + "3"); - await nwaku1.start({ - pubsubTopic: pubsubTopic, - discv5Discovery: true, - peerExchange: true, - relay: true - }); - nwaku1PeerId = await nwaku1.getPeerId(); - await nwaku2.start({ - pubsubTopic: pubsubTopic, - discv5Discovery: true, - peerExchange: true, - discv5BootstrapNode: (await nwaku1.info()).enrUri, - relay: true - }); - await nwaku3.start({ - pubsubTopic: pubsubTopic, - discv5Discovery: true, - peerExchange: true, - discv5BootstrapNode: (await nwaku2.info()).enrUri, - relay: true - }); - nwaku3MA = await nwaku3.getMultiaddrWithId(); - nwaku3PeerId = await nwaku3.getPeerId(); - waku = await createLightNode({ - libp2p: { - peerDiscovery: [ - bootstrap({ list: [nwaku3MA.toString()] }), - wakuPeerExchangeDiscovery(pubsubTopic) - ] - } - }); - await waku.start(); - await waku.libp2p.dialProtocol(nwaku3MA, PeerExchangeCodec); - await waitForRemotePeerWithCodec(waku, PeerExchangeCodec, nwaku3PeerId); + beforeEachCustom( + this, + async () => { + nwaku1 = new ServiceNode(makeLogFileName(this.ctx) + "1"); + nwaku2 = new ServiceNode(makeLogFileName(this.ctx) + "2"); + nwaku3 = new ServiceNode(makeLogFileName(this.ctx) + "3"); + await nwaku1.start({ + pubsubTopic: pubsubTopic, + discv5Discovery: true, + peerExchange: true, + relay: true + }); + nwaku1PeerId = await nwaku1.getPeerId(); + await nwaku2.start({ + pubsubTopic: pubsubTopic, + discv5Discovery: true, + peerExchange: true, + discv5BootstrapNode: (await nwaku1.info()).enrUri, + relay: true + }); + await nwaku3.start({ + pubsubTopic: pubsubTopic, + discv5Discovery: true, + peerExchange: true, + discv5BootstrapNode: (await nwaku2.info()).enrUri, + relay: true + }); + nwaku3MA = await nwaku3.getMultiaddrWithId(); + nwaku3PeerId = await nwaku3.getPeerId(); + waku = await createLightNode({ + libp2p: { + peerDiscovery: [ + bootstrap({ list: [nwaku3MA.toString()] }), + wakuPeerExchangeDiscovery(pubsubTopic) + ] + } + }); + await waku.start(); + await waku.libp2p.dialProtocol(nwaku3MA, PeerExchangeCodec); + await waitForRemotePeerWithCodec(waku, PeerExchangeCodec, nwaku3PeerId); - components = waku.libp2p.components as unknown as Libp2pComponents; - peerExchange = new WakuPeerExchange(components, pubsubTopic); - numPeersToRequest = 2; + components = waku.libp2p.components as unknown as Libp2pComponents; + peerExchange = new WakuPeerExchange(components, pubsubTopic); + numPeersToRequest = 2; - // querying the connected peer - peerInfos = []; - while (peerInfos.length != numPeersToRequest) { - try { - peerInfos = (await peerExchange.query({ - peerId: nwaku3PeerId, - numPeers: numPeersToRequest - })) as PeerInfo[]; - } catch (error) { - log.error("Error encountered, retrying..."); + // querying the connected peer + peerInfos = []; + while (peerInfos.length != numPeersToRequest) { + try { + peerInfos = (await peerExchange.query({ + peerId: nwaku3PeerId, + numPeers: numPeersToRequest + })) as PeerInfo[]; + } catch (error) { + log.error("Error encountered, retrying..."); + } + await delay(2000); } - await delay(2000); - } - }); + }, + 100000 + ); afterEachCustom(this, async () => { await tearDownNodes([nwaku1, nwaku2, nwaku3], waku);