chore: add delays for nwaku setup

This commit is contained in:
Danish Arora 2025-02-17 18:33:24 +05:30
parent 98179ce129
commit 7615f8fa84
No known key found for this signature in database
GPG Key ID: 1C6EF37CDAE1426E
4 changed files with 24 additions and 12 deletions

View File

@ -434,7 +434,7 @@ interface RpcInfoResponse {
export async function verifyServiceNodesConnected(
nodes: ServiceNode[]
): Promise<void> {
): Promise<boolean> {
for (const node of nodes) {
const peers = await node.peers();
log.info(`Service node ${node.containerName} peers:`, peers.length);
@ -442,9 +442,9 @@ export async function verifyServiceNodesConnected(
if (nodes.length > 1 && peers.length === 0) {
log.error(`Service node ${node.containerName} has no peers connected`);
throw new Error(
`Service node ${node.containerName} has no peers connected`
);
return false;
}
}
return true;
}

View File

@ -7,7 +7,7 @@ import {
Protocols
} from "@waku/interfaces";
import { createLightNode } from "@waku/sdk";
import { derivePubsubTopicsFromNetworkConfig } from "@waku/utils";
import { delay, derivePubsubTopicsFromNetworkConfig } from "@waku/utils";
import { Context } from "mocha";
import pRetry from "p-retry";
@ -37,7 +37,10 @@ export async function runMultipleNodes(
);
if (numServiceNodes > 1) {
await verifyServiceNodesConnected(serviceNodes.nodes);
const success = await verifyServiceNodesConnected(serviceNodes.nodes);
if (!success) {
throw new Error("Failed to verify that service nodes are connected");
}
}
const wakuOptions: CreateNodeOptions = {
@ -55,12 +58,21 @@ export async function runMultipleNodes(
throw new Error("Failed to initialize waku");
}
//TODO: reinvestigate the need for these delays with nwaku:0.35.0: https://github.com/waku-org/js-waku/issues/2264
await delay(2000);
for (const node of serviceNodes.nodes) {
await waku.dial(await node.getMultiaddrWithId());
await waku.waitForPeers([Protocols.Filter, Protocols.LightPush]);
await node.ensureSubscriptions(
const success = await node.ensureSubscriptions(
derivePubsubTopicsFromNetworkConfig(networkConfig)
);
if (!success) {
throw new Error("Failed to ensure subscriptions");
}
//TODO: reinvestigate the need for these delays with nwaku:0.35.0: https://github.com/waku-org/js-waku/issues/2264
await delay(2000);
await node.waitForLog(waku.libp2p.peerId.toString(), 100);
}

View File

@ -22,7 +22,7 @@ import {
const ContentTopic = "/waku/2/content/test.js";
describe("Static Sharding: Running Nodes", function () {
this.timeout(15_000);
this.timeout(60_000);
let waku: LightNode;
let serviceNodes: ServiceNodesFleet;
@ -42,7 +42,8 @@ describe("Static Sharding: Running Nodes", function () {
store: true,
lightpush: true,
relay: true,
pubsubTopic: shardInfoToPubsubTopics(shardInfo)
pubsubTopic: shardInfoToPubsubTopics(shardInfo),
clusterId: singleShardInfo.clusterId
},
false,
2,
@ -80,7 +81,8 @@ describe("Static Sharding: Running Nodes", function () {
store: true,
lightpush: true,
relay: true,
pubsubTopic: shardInfoToPubsubTopics(shardInfo)
pubsubTopic: shardInfoToPubsubTopics(shardInfo),
clusterId: singleShardInfo.clusterId
},
false,
2,

View File

@ -175,8 +175,6 @@ describe("Waku Store (Autosharding), custom pubsub topic", function () {
};
beforeEachCustom(this, async () => {
console.log("running nodes");
[serviceNodes, waku] = await runMultipleNodes(
this.ctx,
contentTopicInfoBothShards,