chore: update mocha config + fix epehermal tests

This commit is contained in:
Danish Arora 2025-01-23 14:25:10 +05:30
parent 1932ef5fdc
commit f05a27f9d0
No known key found for this signature in database
GPG Key ID: 1C6EF37CDAE1426E
3 changed files with 59 additions and 41 deletions

View File

@ -7,7 +7,7 @@ const config = {
'loader=ts-node/esm'
],
exit: true,
retries: 4
retries: 2
};
if (process.env.CI) {

View File

@ -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);
});
}

View File

@ -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 () {