chore: attempt stability for test suite

This commit is contained in:
Danish Arora 2025-01-31 17:55:48 +05:30
parent 5119c858da
commit 04cd3571d1
No known key found for this signature in database
GPG Key ID: 1C6EF37CDAE1426E
7 changed files with 59 additions and 42 deletions

View File

@ -33,6 +33,7 @@ env:
jobs:
node:
runs-on: ubuntu-latest
timeout-minutes: 60 # Add a 1-hour timeout to fail faster
env:
WAKUNODE_IMAGE: ${{ inputs.nim_wakunode_image }}
ALLURE_REPORTS: ${{ inputs.allure_reports }}

View File

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

View File

@ -237,6 +237,7 @@ class MultipleNodesMessageCollector {
const startTime = Date.now();
const pubsubTopic = options?.pubsubTopic || DefaultTestPubsubTopic;
const timeoutDuration = options?.timeoutDuration || 400;
const maxTimeout = Math.min(timeoutDuration * numMessages, 30000);
const exact = options?.exact || false;
while (this.messageList.length < numMessages) {
@ -248,7 +249,9 @@ class MultipleNodesMessageCollector {
return msgs.length >= numMessages;
})
);
return results.every((result) => result);
if (results.every((result) => result)) {
return true;
}
} else {
const results = await Promise.all(
this.relayNodes.map(async (node) => {
@ -256,16 +259,19 @@ class MultipleNodesMessageCollector {
return msgs.length >= numMessages;
})
);
return results.some((result) => result);
if (results.some((result) => result)) {
return true;
}
}
}
const elapsed = Date.now() - startTime;
if (elapsed > timeoutDuration * numMessages) {
return false;
}
const elapsed = Date.now() - startTime;
if (elapsed > maxTimeout) {
log.warn(`Timeout waiting for messages after ${elapsed}ms`);
return false;
}
await delay(10);
await delay(10);
}
}
if (exact) {

View File

@ -1,9 +1,9 @@
import {
CreateNodeOptions,
DefaultNetworkConfig,
IWaku,
LightNode,
NetworkConfig,
ProtocolCreateOptions,
Protocols
} from "@waku/interfaces";
import { createLightNode } from "@waku/sdk";
@ -40,7 +40,7 @@ export async function runMultipleNodes(
await verifyServiceNodesConnected(serviceNodes.nodes);
}
const wakuOptions: ProtocolCreateOptions = {
const wakuOptions: CreateNodeOptions = {
staticNoiseKey: NOISE_KEY_1,
libp2p: {
addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] }

View File

@ -6,6 +6,8 @@ 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[]
@ -13,37 +15,47 @@ export async function tearDownNodes(
const nNodes = Array.isArray(nwakuNodes) ? nwakuNodes : [nwakuNodes];
const wNodes = Array.isArray(wakuNodes) ? wakuNodes : [wakuNodes];
const stopNwakuNodes = 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 }
);
}
});
const stopWakuNodes = wNodes.map(async (waku) => {
if (waku) {
await pRetry(
async () => {
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);
throw error;
}
},
{ retries: 3 }
);
}
});
}
})
]);
await Promise.all([...stopNwakuNodes, ...stopWakuNodes]);
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);
}
}

View File

@ -56,7 +56,7 @@ describe("DNS Node Discovery [live data]", function () {
});
it(`should use DNS peer discovery with light client`, async function () {
this.timeout(100000);
this.timeout(100_000);
const maxQuantity = 3;
const nodeRequirements = {

View File

@ -304,13 +304,10 @@ describe("Waku Store, general", function () {
for await (const msg of query) {
if (msg) {
messages.push(msg as DecodedMessage);
console.log(bytesToUtf8(msg.payload!));
}
}
}
console.log(messages.length);
// Messages are ordered from oldest to latest within a page (1 page query)
expect(bytesToUtf8(messages[0].payload!)).to.eq(asymText);
expect(bytesToUtf8(messages[1].payload!)).to.eq(symText);