Skip to content

Commit

Permalink
Improving environment setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ausias-armesto committed May 23, 2024
1 parent 4d95b58 commit a5fddc8
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions k6/src/typescript/setup-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@ import { HoprdNode } from './hoprd-node';

const setupEnvironment = async () => {

// Check nodes
const checkNodes: Promise<boolean> [] = []
nodes.forEach((node:HoprdNode) => { checkNodes.push(node.check())})
await Promise.all(checkNodes).then((results: boolean[]) => {
if (results.filter(result => ! result).length != 0) {
console.error(`[ERROR] Review the previous errors checking nodes`)
process.exit(1);
const maxRetries = 10;
let retries = 0;
let checkNodes: Promise<{node: HoprdNode, status: boolean}>[] = nodes.map((node:HoprdNode) => node.check().then(status => ({node, status})));
while (checkNodes.length > 0 && retries < maxRetries) {
const results: {node: HoprdNode, status: boolean}[] = await Promise.all(checkNodes);

// Filter out the nodes that were checked successfully
checkNodes = results.filter(result => !result.status).map(result => result.node.check().then(status => ({node: result.node, status})));

if (checkNodes.length > 0) {
if (retries < maxRetries - 1) { // if it's not the last iteration
console.error(`[ERROR] Retrying in 60 seconds...`)
await new Promise(resolve => setTimeout(resolve, 60000));
} else {
console.error(`[ERROR] Review the previous errors checking nodes. Exiting after ${maxRetries} attempts.`)
process.exit(1);
}
}
})
retries++;
}

// Open channels nodes
const openChannels: Promise<string[]> [] = []
Expand Down

0 comments on commit a5fddc8

Please sign in to comment.