Skip to content

Commit

Permalink
test(scaling): delay running main node service main interval
Browse files Browse the repository at this point in the history
The delay is required for the network bootstrapping (that is, node
connections, peer discovery, etc.).
  • Loading branch information
mkermani144 committed Apr 15, 2024
1 parent 59362b6 commit e1184a7
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions tests/scaling/src/node/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,27 @@ const messages = Array.from({ length: 10 }).map(
`Ping@${new Date().toLocaleTimeString([], { hour12: false })}#${index}:${process.env.NODE_PEER_ID!.slice(-5)}`,
);

setInterval(async () => {
for (const message of messages) {
for (const peer of process.env.ALL_PEER_IDS!.split(',')) {
if (peer !== process.env.NODE_PEER_ID!) {
try {
const actualMessage = `${message}->${peer.slice(-5)}`;
await node.sendMessage(peer, actualMessage);
MessageCounter.increase();
console.info(`Message sent: ${actualMessage}`);
} catch (error) {
console.warn(
`tried to send a message to ${peer.slice(-5)} but failed due to error: ${error}`,
);
setTimeout(() => {
setInterval(async () => {
for (const message of messages) {
for (const peer of process.env.ALL_PEER_IDS!.split(',')) {
if (peer !== process.env.NODE_PEER_ID!) {
try {
const actualMessage = `${message}->${peer.slice(-5)}`;
await node.sendMessage(peer, actualMessage);
MessageCounter.increase();
console.info(`Message sent: ${actualMessage}`);
} catch (error) {
console.warn(
`tried to send a message to ${peer.slice(-5)} but failed due to error: ${error}`,
);
}
await wait();
}
await wait();
}
}
}
}, 10_000);
}, 10_000);
}, 30_000);

node.handleIncomingMessage(async (from, message) => {
if (message?.includes('Pong')) {
Expand Down

0 comments on commit e1184a7

Please sign in to comment.