From f05a27f9d00256646b27fdc8cffee69789aac605 Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Thu, 23 Jan 2025 14:25:10 +0530 Subject: [PATCH] chore: update mocha config + fix epehermal tests --- packages/tests/.mocharc.cjs | 2 +- packages/tests/src/run-tests.js | 9 +++ packages/tests/tests/ephemeral.node.spec.ts | 89 ++++++++++++--------- 3 files changed, 59 insertions(+), 41 deletions(-) diff --git a/packages/tests/.mocharc.cjs b/packages/tests/.mocharc.cjs index f2ea3f66ce..9b9440b3e3 100644 --- a/packages/tests/.mocharc.cjs +++ b/packages/tests/.mocharc.cjs @@ -7,7 +7,7 @@ const config = { 'loader=ts-node/esm' ], exit: true, - retries: 4 + retries: 2 }; if (process.env.CI) { diff --git a/packages/tests/src/run-tests.js b/packages/tests/src/run-tests.js index bc70e48e71..60f3cf6c33 100644 --- a/packages/tests/src/run-tests.js +++ b/packages/tests/src/run-tests.js @@ -40,6 +40,15 @@ async function main() { mocha.on("exit", (code) => { console.log(`Mocha tests exited with code ${code}`); + try { + execAsync( + `docker ps -q -f "ancestor=${WAKUNODE_IMAGE}" | xargs -r docker stop` + ).catch((error) => { + console.error("Error cleaning up containers:", error); + }); + } catch (error) { + console.error("Error cleaning up containers:", error); + } process.exit(code || 0); }); } diff --git a/packages/tests/tests/ephemeral.node.spec.ts b/packages/tests/tests/ephemeral.node.spec.ts index 2abed950d2..cfd8467231 100644 --- a/packages/tests/tests/ephemeral.node.spec.ts +++ b/packages/tests/tests/ephemeral.node.spec.ts @@ -23,11 +23,11 @@ import { afterEachCustom, beforeEachCustom, delay, - makeLogFileName, NOISE_KEY_1, NOISE_KEY_2, - ServiceNode, - tearDownNodes + runMultipleNodes, + ServiceNodesFleet, + teardownNodesWithRedundancy } from "../src/index.js"; const log = new Logger("test:ephemeral"); @@ -76,41 +76,39 @@ const SymDecoder = createSymDecoder(SymContentTopic, symKey, PubsubTopic); describe("Waku Message Ephemeral field", function () { let waku: LightNode; - let nwaku: ServiceNode; + let serviceNodes: ServiceNodesFleet; afterEachCustom(this, async () => { - await tearDownNodes(nwaku, waku); + await teardownNodesWithRedundancy(serviceNodes, waku); }); beforeEachCustom(this, async () => { - nwaku = new ServiceNode(makeLogFileName(this.ctx)); - await nwaku.start({ - filter: true, - lightpush: true, - store: true, - relay: true, - pubsubTopic: [PubsubTopic], - contentTopic: [TestContentTopic, AsymContentTopic, SymContentTopic], - clusterId: ClusterId - }); - await nwaku.ensureSubscriptionsAutosharding([ - TestContentTopic, - AsymContentTopic, - SymContentTopic - ]); + [serviceNodes, waku] = await runMultipleNodes( + this.ctx, + { + clusterId: ClusterId, + contentTopics: [TestContentTopic, AsymContentTopic, SymContentTopic] + }, + { + filter: true, + lightpush: true, + store: true, + relay: true, + pubsubTopic: [PubsubTopic] + }, + true, + 2 + ); - waku = await createLightNode({ - staticNoiseKey: NOISE_KEY_1, - libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }, - networkConfig: { - contentTopics: [TestContentTopic, AsymContentTopic, SymContentTopic], - clusterId: ClusterId - } - }); - await waku.start(); - await waku.dial(await nwaku.getMultiaddrWithId()); - - await waku.waitForPeers([Protocols.Filter, Protocols.LightPush]); + await Promise.all( + serviceNodes.nodes.map(async (node) => { + await node.ensureSubscriptionsAutosharding([ + TestContentTopic, + AsymContentTopic, + SymContentTopic + ]); + }) + ); }); it("Ephemeral messages are not stored", async function () { @@ -130,7 +128,7 @@ describe("Waku Message Ephemeral field", function () { payload: utf8ToBytes(clearText) }; - const [waku1, waku2, nimWakuMultiaddr] = await Promise.all([ + const [waku1, waku2] = await Promise.all([ createLightNode({ staticNoiseKey: NOISE_KEY_1, networkConfig: { @@ -144,16 +142,18 @@ describe("Waku Message Ephemeral field", function () { contentTopics: [TestContentTopic, AsymContentTopic, SymContentTopic], clusterId: ClusterId } - }).then((waku) => waku.start().then(() => waku)), - nwaku.getMultiaddrWithId() + }).then((waku) => waku.start().then(() => waku)) ]); log.info("Waku nodes created"); - await Promise.all([ - waku1.dial(nimWakuMultiaddr), - waku2.dial(nimWakuMultiaddr) - ]); + await Promise.all( + serviceNodes.nodes.map(async (node) => { + const multiaddr = await node.getMultiaddrWithId(); + await waku1.dial(multiaddr); + await waku2.dial(multiaddr); + }) + ); log.info("Waku nodes connected to nwaku"); @@ -186,7 +186,16 @@ describe("Waku Message Ephemeral field", function () { expect(messages?.length).eq(0); - await tearDownNodes([], [waku1, waku2]); + const additionalServiceNodes = await ServiceNodesFleet.createAndRun( + this.ctx, + 0, + false, + { + clusterId: ClusterId, + contentTopics: [TestContentTopic, AsymContentTopic, SymContentTopic] + } + ); + await teardownNodesWithRedundancy(additionalServiceNodes, [waku1, waku2]); }); it("Ephemeral field is preserved - encoder v0", async function () {