From 0f332e7b0b6245ab812558009103038cf4212dbf Mon Sep 17 00:00:00 2001 From: Phillip Jensen Date: Mon, 23 Oct 2023 11:14:44 +0200 Subject: [PATCH 01/12] test: retry compose down before erroring out --- tests/docker/manageDocker.sh | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/docker/manageDocker.sh diff --git a/tests/docker/manageDocker.sh b/tests/docker/manageDocker.sh new file mode 100644 index 000000000..8f64c3d76 --- /dev/null +++ b/tests/docker/manageDocker.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# Maximum number of attempts to bring down the Docker Compose +max_attempts=5 + +# Counter for the number of attempts +attempt=0 + +# Path to your docker-compose file +compose_file="tests/docker/docker-compose.yml" + +# Function to bring up the services +start_services() { + docker-compose -f $compose_file up -d +} + +# Loop to attempt 'docker-compose down' with retries +while [ $attempt -lt $max_attempts ]; do + # Increment the attempt counter + ((attempt=attempt+1)) + + # Try to bring down the services + docker-compose -f $compose_file down + + # Check if the command succeeded + if [ $? -eq 0 ]; then + echo "Successfully brought down the services." + # If successful, break out of the loop + break + else + echo "Attempt $attempt failed..." + # If max attempts reached, show error and exit + if [ $attempt -eq $max_attempts ]; then + echo "Failed to bring down the services after $max_attempts attempts." + exit 1 + fi + # If not, wait for a bit before retrying + echo "Retrying in 5 seconds..." + sleep 5 + fi +done + +# If we reached here, it means we successfully brought the services down. +# So we start them up again. +start_services From a245d7f49ca1bd208cc9489be199e8f2b309929f Mon Sep 17 00:00:00 2001 From: Phillip Jensen Date: Mon, 23 Oct 2023 11:16:58 +0200 Subject: [PATCH 02/12] test: use new script to manage docker on action run --- .github/workflows/cypress-nightly.yml | 2 +- .github/workflows/examples-nightly.yml | 2 +- .github/workflows/goth-nightly.yml | 2 +- .github/workflows/release.yml | 2 +- tests/docker/Requestor.Dockerfile | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cypress-nightly.yml b/.github/workflows/cypress-nightly.yml index ca7253bf4..6cf4b4440 100644 --- a/.github/workflows/cypress-nightly.yml +++ b/.github/workflows/cypress-nightly.yml @@ -24,7 +24,7 @@ jobs: - name: Start the docker containers # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 - run: docker compose -f tests/docker/docker-compose.yml down && docker compose -f tests/docker/docker-compose.yml up -d + run: /manageDocker.sh - name: Fund the requestor # Use a funding script which will retry funding the requestor 3 times, else it exits with error. The faucet is not reliable and sometimes fails to fund the requestor, thus the retry. diff --git a/.github/workflows/examples-nightly.yml b/.github/workflows/examples-nightly.yml index a5daacefd..ad7612ae8 100644 --- a/.github/workflows/examples-nightly.yml +++ b/.github/workflows/examples-nightly.yml @@ -40,7 +40,7 @@ jobs: - name: Start the docker containers # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 - run: docker compose -f tests/docker/docker-compose.yml down && docker compose -f tests/docker/docker-compose.yml up -d + run: /manageDocker.sh - name: Fund the requestor # Use a funding script which will retry funding the requestor 3 times, else it exits with error. The faucet is not reliable and sometimes fails to fund the requestor, thus the retry. diff --git a/.github/workflows/goth-nightly.yml b/.github/workflows/goth-nightly.yml index ca10cb93d..4e583f6bb 100644 --- a/.github/workflows/goth-nightly.yml +++ b/.github/workflows/goth-nightly.yml @@ -40,7 +40,7 @@ jobs: - name: Start the docker containers # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 - run: docker compose -f tests/docker/docker-compose.yml down && docker compose -f tests/docker/docker-compose.yml up -d + run: /manageDocker.sh - name: Fund the requestor # Use a funding script which will retry funding the requestor 3 times, else it exits with error. The faucet is not reliable and sometimes fails to fund the requestor, thus the retry. diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ef1b52405..d1a73088b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -63,7 +63,7 @@ jobs: - name: Start the docker containers # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 - run: docker compose -f tests/docker/docker-compose.yml down && docker compose -f tests/docker/docker-compose.yml up -d + run: /manageDocker.sh - name: Fund the requestor # Use a funding script which will retry funding the requestor 3 times, else it exits with error. The faucet is not reliable and sometimes fails to fund the requestor, thus the retry. diff --git a/tests/docker/Requestor.Dockerfile b/tests/docker/Requestor.Dockerfile index b64167fdd..2b56c5f76 100644 --- a/tests/docker/Requestor.Dockerfile +++ b/tests/docker/Requestor.Dockerfile @@ -40,5 +40,6 @@ RUN apt-get update -q \ COPY ./startRequestor.sh /startRequestor.sh +COPY ./manageDocker.sh /manageDocker.sh CMD ["bash", "-c", "/startRequestor.sh"] From 13e3eb1dca86f9ae7653945bd7ff5ce35873483f Mon Sep 17 00:00:00 2001 From: Phillip Jensen Date: Mon, 23 Oct 2023 11:30:46 +0200 Subject: [PATCH 03/12] test: use correct file path --- .github/workflows/cypress-nightly.yml | 2 +- .github/workflows/examples-nightly.yml | 2 +- .github/workflows/goth-nightly.yml | 2 +- .github/workflows/release.yml | 2 +- tests/docker/Requestor.Dockerfile | 1 - tests/docker/{manageDocker.sh => startDocker.sh} | 0 6 files changed, 4 insertions(+), 5 deletions(-) rename tests/docker/{manageDocker.sh => startDocker.sh} (100%) mode change 100644 => 100755 diff --git a/.github/workflows/cypress-nightly.yml b/.github/workflows/cypress-nightly.yml index 6cf4b4440..f8e07d128 100644 --- a/.github/workflows/cypress-nightly.yml +++ b/.github/workflows/cypress-nightly.yml @@ -24,7 +24,7 @@ jobs: - name: Start the docker containers # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 - run: /manageDocker.sh + run: tests/docker/startDocker.sh - name: Fund the requestor # Use a funding script which will retry funding the requestor 3 times, else it exits with error. The faucet is not reliable and sometimes fails to fund the requestor, thus the retry. diff --git a/.github/workflows/examples-nightly.yml b/.github/workflows/examples-nightly.yml index ad7612ae8..0b4fd7de3 100644 --- a/.github/workflows/examples-nightly.yml +++ b/.github/workflows/examples-nightly.yml @@ -40,7 +40,7 @@ jobs: - name: Start the docker containers # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 - run: /manageDocker.sh + run: tests/docker/startDocker.sh - name: Fund the requestor # Use a funding script which will retry funding the requestor 3 times, else it exits with error. The faucet is not reliable and sometimes fails to fund the requestor, thus the retry. diff --git a/.github/workflows/goth-nightly.yml b/.github/workflows/goth-nightly.yml index 4e583f6bb..fcbc66d25 100644 --- a/.github/workflows/goth-nightly.yml +++ b/.github/workflows/goth-nightly.yml @@ -40,7 +40,7 @@ jobs: - name: Start the docker containers # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 - run: /manageDocker.sh + run: tests/docker/startDocker.sh - name: Fund the requestor # Use a funding script which will retry funding the requestor 3 times, else it exits with error. The faucet is not reliable and sometimes fails to fund the requestor, thus the retry. diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d1a73088b..9ac91d286 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -63,7 +63,7 @@ jobs: - name: Start the docker containers # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 - run: /manageDocker.sh + run: tests/docker/startDocker.sh - name: Fund the requestor # Use a funding script which will retry funding the requestor 3 times, else it exits with error. The faucet is not reliable and sometimes fails to fund the requestor, thus the retry. diff --git a/tests/docker/Requestor.Dockerfile b/tests/docker/Requestor.Dockerfile index 2b56c5f76..b64167fdd 100644 --- a/tests/docker/Requestor.Dockerfile +++ b/tests/docker/Requestor.Dockerfile @@ -40,6 +40,5 @@ RUN apt-get update -q \ COPY ./startRequestor.sh /startRequestor.sh -COPY ./manageDocker.sh /manageDocker.sh CMD ["bash", "-c", "/startRequestor.sh"] diff --git a/tests/docker/manageDocker.sh b/tests/docker/startDocker.sh old mode 100644 new mode 100755 similarity index 100% rename from tests/docker/manageDocker.sh rename to tests/docker/startDocker.sh From a014c73c48108a5c89d1e0d78277403c8e6d0454 Mon Sep 17 00:00:00 2001 From: Phillip Jensen Date: Mon, 23 Oct 2023 11:32:51 +0200 Subject: [PATCH 04/12] test: fix command --- tests/docker/startDocker.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/docker/startDocker.sh b/tests/docker/startDocker.sh index 8f64c3d76..ca5df56e3 100755 --- a/tests/docker/startDocker.sh +++ b/tests/docker/startDocker.sh @@ -11,16 +11,16 @@ compose_file="tests/docker/docker-compose.yml" # Function to bring up the services start_services() { - docker-compose -f $compose_file up -d + docker compose -f $compose_file up -d } -# Loop to attempt 'docker-compose down' with retries +# Loop to attempt 'docker compose down' with retries while [ $attempt -lt $max_attempts ]; do # Increment the attempt counter ((attempt=attempt+1)) # Try to bring down the services - docker-compose -f $compose_file down + docker compose -f $compose_file down # Check if the command succeeded if [ $? -eq 0 ]; then From 44d2be60246f31e23382f938d440cbe81e8a45eb Mon Sep 17 00:00:00 2001 From: Phillip Jensen Date: Mon, 23 Oct 2023 11:36:09 +0200 Subject: [PATCH 05/12] test: restart docker service --- tests/docker/startDocker.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/docker/startDocker.sh b/tests/docker/startDocker.sh index ca5df56e3..b5f5a24fd 100755 --- a/tests/docker/startDocker.sh +++ b/tests/docker/startDocker.sh @@ -1,5 +1,7 @@ #!/bin/bash +# Restart docker first as it may be in a bad state. +sudo service docker restart # Maximum number of attempts to bring down the Docker Compose max_attempts=5 From cee329a29ef9418c379b3ad5f56fc06b8c4cdf9a Mon Sep 17 00:00:00 2001 From: Phillip Jensen Date: Tue, 24 Oct 2023 08:23:32 +0200 Subject: [PATCH 06/12] test: scratch script and just restart docker --- .github/workflows/cypress-nightly.yml | 2 +- .github/workflows/examples-nightly.yml | 2 +- .github/workflows/goth-nightly.yml | 2 +- .github/workflows/release.yml | 6 ++-- tests/docker/startDocker.sh | 47 -------------------------- 5 files changed, 6 insertions(+), 53 deletions(-) delete mode 100755 tests/docker/startDocker.sh diff --git a/.github/workflows/cypress-nightly.yml b/.github/workflows/cypress-nightly.yml index f8e07d128..9cfdee853 100644 --- a/.github/workflows/cypress-nightly.yml +++ b/.github/workflows/cypress-nightly.yml @@ -24,7 +24,7 @@ jobs: - name: Start the docker containers # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 - run: tests/docker/startDocker.sh + run: sudo service docker restart && docker compose -f tests/docker/docker-compose.yml down && docker compose -f tests/docker/docker-compose.yml up -d - name: Fund the requestor # Use a funding script which will retry funding the requestor 3 times, else it exits with error. The faucet is not reliable and sometimes fails to fund the requestor, thus the retry. diff --git a/.github/workflows/examples-nightly.yml b/.github/workflows/examples-nightly.yml index 0b4fd7de3..7d2f311d9 100644 --- a/.github/workflows/examples-nightly.yml +++ b/.github/workflows/examples-nightly.yml @@ -40,7 +40,7 @@ jobs: - name: Start the docker containers # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 - run: tests/docker/startDocker.sh + run: sudo service docker restart && docker compose -f tests/docker/docker-compose.yml down && docker compose -f tests/docker/docker-compose.yml up -d - name: Fund the requestor # Use a funding script which will retry funding the requestor 3 times, else it exits with error. The faucet is not reliable and sometimes fails to fund the requestor, thus the retry. diff --git a/.github/workflows/goth-nightly.yml b/.github/workflows/goth-nightly.yml index fcbc66d25..34f9aeeca 100644 --- a/.github/workflows/goth-nightly.yml +++ b/.github/workflows/goth-nightly.yml @@ -40,7 +40,7 @@ jobs: - name: Start the docker containers # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 - run: tests/docker/startDocker.sh + run: sudo service docker restart && docker compose -f tests/docker/docker-compose.yml down && docker compose -f tests/docker/docker-compose.yml up -d - name: Fund the requestor # Use a funding script which will retry funding the requestor 3 times, else it exits with error. The faucet is not reliable and sometimes fails to fund the requestor, thus the retry. diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9ac91d286..3c2d26a74 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -55,15 +55,15 @@ jobs: uses: actions/checkout@v3 - name: Use random string for subnet + # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 run: echo "YAGNA_SUBNET=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 8 ; echo '')" >> $GITHUB_ENV - name: Build the docker containers - # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 run: docker compose -f tests/docker/docker-compose.yml build - name: Start the docker containers - # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 - run: tests/docker/startDocker.sh + # Restart docker to avoid issues with the docker compose down due to improper cleanup of the previous run. + run: sudo service docker restart && docker compose -f tests/docker/docker-compose.yml down && docker compose -f tests/docker/docker-compose.yml up -d - name: Fund the requestor # Use a funding script which will retry funding the requestor 3 times, else it exits with error. The faucet is not reliable and sometimes fails to fund the requestor, thus the retry. diff --git a/tests/docker/startDocker.sh b/tests/docker/startDocker.sh deleted file mode 100755 index b5f5a24fd..000000000 --- a/tests/docker/startDocker.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -# Restart docker first as it may be in a bad state. -sudo service docker restart -# Maximum number of attempts to bring down the Docker Compose -max_attempts=5 - -# Counter for the number of attempts -attempt=0 - -# Path to your docker-compose file -compose_file="tests/docker/docker-compose.yml" - -# Function to bring up the services -start_services() { - docker compose -f $compose_file up -d -} - -# Loop to attempt 'docker compose down' with retries -while [ $attempt -lt $max_attempts ]; do - # Increment the attempt counter - ((attempt=attempt+1)) - - # Try to bring down the services - docker compose -f $compose_file down - - # Check if the command succeeded - if [ $? -eq 0 ]; then - echo "Successfully brought down the services." - # If successful, break out of the loop - break - else - echo "Attempt $attempt failed..." - # If max attempts reached, show error and exit - if [ $attempt -eq $max_attempts ]; then - echo "Failed to bring down the services after $max_attempts attempts." - exit 1 - fi - # If not, wait for a bit before retrying - echo "Retrying in 5 seconds..." - sleep 5 - fi -done - -# If we reached here, it means we successfully brought the services down. -# So we start them up again. -start_services From c6d7989522c7ca530af573513e34c7f12b29b48e Mon Sep 17 00:00:00 2001 From: Phillip Jensen Date: Tue, 24 Oct 2023 09:32:17 +0200 Subject: [PATCH 07/12] test(example): reduce custom price array length check --- .../examples/selecting-providers/custom-price.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/docs-examples/examples/selecting-providers/custom-price.mjs b/examples/docs-examples/examples/selecting-providers/custom-price.mjs index d4a604006..411bbaa84 100644 --- a/examples/docs-examples/examples/selecting-providers/custom-price.mjs +++ b/examples/docs-examples/examples/selecting-providers/custom-price.mjs @@ -12,10 +12,10 @@ const myFilter = async (proposal) => { let counterIdx = usageVector.findIndex((ele) => ele === "golem.usage.duration_sec"); let proposedCost = proposal.properties["golem.com.pricing.model.linear.coeffs"][counterIdx]; costData.push(proposedCost); - if (costData.length < 11) return false; + if (costData.length < 6) return false; else { costData.shift(); - let averageProposedCost = costData.reduce((part, x) => part + x, 0) / 10; + let averageProposedCost = costData.reduce((part, x) => part + x, 0) / 5; if (proposedCost <= 1.2 * averageProposedCost) decision = true; if (decision) { console.log(proposedCost, averageProposedCost); From 458423cb8654e75e20b198b5f4a9d41bc1e7f6d0 Mon Sep 17 00:00:00 2001 From: Phillip Jensen Date: Tue, 24 Oct 2023 10:18:57 +0200 Subject: [PATCH 08/12] test: update comments --- .github/workflows/cypress-nightly.yml | 4 ++-- .github/workflows/examples-nightly.yml | 4 ++-- .github/workflows/goth-nightly.yml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cypress-nightly.yml b/.github/workflows/cypress-nightly.yml index 9cfdee853..65f60f231 100644 --- a/.github/workflows/cypress-nightly.yml +++ b/.github/workflows/cypress-nightly.yml @@ -16,14 +16,14 @@ jobs: uses: actions/checkout@v3 - name: Use random string for subnet + # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 run: echo "YAGNA_SUBNET=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 8 ; echo '')" >> $GITHUB_ENV - name: Build the docker containers - # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 run: docker compose -f tests/docker/docker-compose.yml build - name: Start the docker containers - # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 + # Restart docker to avoid issues with the docker compose down due to improper cleanup of the previous run. run: sudo service docker restart && docker compose -f tests/docker/docker-compose.yml down && docker compose -f tests/docker/docker-compose.yml up -d - name: Fund the requestor diff --git a/.github/workflows/examples-nightly.yml b/.github/workflows/examples-nightly.yml index 7d2f311d9..9ddb33568 100644 --- a/.github/workflows/examples-nightly.yml +++ b/.github/workflows/examples-nightly.yml @@ -32,14 +32,14 @@ jobs: uses: actions/checkout@v3 - name: Use random string for subnet + # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 run: echo "YAGNA_SUBNET=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 8 ; echo '')" >> $GITHUB_ENV - name: Build the docker containers - # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 run: docker compose -f tests/docker/docker-compose.yml build - name: Start the docker containers - # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 + # Restart docker to avoid issues with the docker compose down due to improper cleanup of the previous run. run: sudo service docker restart && docker compose -f tests/docker/docker-compose.yml down && docker compose -f tests/docker/docker-compose.yml up -d - name: Fund the requestor diff --git a/.github/workflows/goth-nightly.yml b/.github/workflows/goth-nightly.yml index 34f9aeeca..f6c4cd505 100644 --- a/.github/workflows/goth-nightly.yml +++ b/.github/workflows/goth-nightly.yml @@ -32,14 +32,14 @@ jobs: uses: actions/checkout@v3 - name: Use random string for subnet + # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 run: echo "YAGNA_SUBNET=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 8 ; echo '')" >> $GITHUB_ENV - name: Build the docker containers - # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 run: docker compose -f tests/docker/docker-compose.yml build - name: Start the docker containers - # Use a random string to avoid other providers on the same subnet which might cause tests to fail because it expects only providers named provider-1 and provider-2 + # Restart docker to avoid issues with the docker compose down due to improper cleanup of the previous run. run: sudo service docker restart && docker compose -f tests/docker/docker-compose.yml down && docker compose -f tests/docker/docker-compose.yml up -d - name: Fund the requestor From a3b94ca8256a951bac04f040783743362fe16583 Mon Sep 17 00:00:00 2001 From: Grzegorz Godlewski Date: Thu, 9 Nov 2023 09:05:40 +0100 Subject: [PATCH 09/12] ci: update dependabot.yml --- .github/dependabot.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 3a3cce576..77c0a3c8c 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,5 +7,6 @@ version: 2 updates: - package-ecosystem: "npm" # See documentation for possible values directory: "/" # Location of package manifests + target-branch: "beta" schedule: interval: "weekly" From ed16a8135821ffd18966ed052d177f576915bd3b Mon Sep 17 00:00:00 2001 From: Seweryn Kras Date: Fri, 10 Nov 2023 13:26:31 +0100 Subject: [PATCH 10/12] fix(executor): deprecate `map` and `forEach` --- src/executor/executor.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/executor/executor.ts b/src/executor/executor.ts index bb162c576..fbdaffd1c 100644 --- a/src/executor/executor.ts +++ b/src/executor/executor.ts @@ -339,6 +339,18 @@ export class TaskExecutor { } /** + * @deprecated This method is marked for removal in a future release. Migrate your code by using `Array.map` and `Promise.all` instead. + * @example + * ```typescript + * const data = [1, 2, 3, 4, 5]; + * const resultsPromises = data.map((item) => + * executor.run((ctx) => { + * console.log((await ctx.run(`echo "${item}"`)).stdout); + * }) + * ); + * await Promise.all(resultsPromises); + * ``` + * * Map iterable data to worker function and return computed Task result as AsyncIterable * * @param data Iterable data @@ -387,6 +399,19 @@ export class TaskExecutor { } /** + * @deprecated This method is marked for removal in a future release. + * Migrate your code by using `Array.map` and `Promise.all` instead. + * @example + * ```typescript + * const data = [1, 2, 3, 4, 5]; + * const resultsPromises = data.map((item) => + * executor.run((ctx) => { + * console.log((await ctx.run(`echo "${item}"`)).stdout); + * }), + * ); + * await Promise.all(resultsPromises); + * ``` + * * Iterates over given data and execute task using worker function * * @param data Iterable data From a8d1fc84edac8c797217c08393de54cc5fefee9a Mon Sep 17 00:00:00 2001 From: Seweryn Kras Date: Mon, 13 Nov 2023 19:51:28 +0100 Subject: [PATCH 11/12] chore: remove executor map and foreach from all examples and tests --- examples/blender/blender.ts | 26 +++++---- .../examples/executing-tasks/action_log.txt | 2 +- .../examples/executing-tasks/before-each.mjs | 17 +++--- .../examples/executing-tasks/foreach.mjs | 8 +-- .../examples/executing-tasks/map.mjs | 9 +++- .../executing-tasks/max-parallel-tasks.mjs | 9 +++- .../running-parallel-tasks/index.mjs | 34 ++++++------ examples/fibonacci/fibonacci.js | 15 ++++-- examples/simple-usage/forEach.ts | 11 ---- examples/simple-usage/map.ts | 19 +++---- examples/ssh/ssh.ts | 51 ++++++++++-------- examples/yacat/yacat.ts | 29 +++++----- src/executor/executor.ts | 8 +-- tests/e2e/blender.spec.ts | 25 +++++---- tests/e2e/gftp.spec.ts | 23 ++++---- tests/e2e/strategies.spec.ts | 54 ++++++++++--------- tests/e2e/tasks.spec.ts | 13 ++--- tests/e2e/yacat.spec.ts | 25 +++++---- 18 files changed, 212 insertions(+), 166 deletions(-) delete mode 100644 examples/simple-usage/forEach.ts diff --git a/examples/blender/blender.ts b/examples/blender/blender.ts index 1c8dc7710..0e2c5f827 100644 --- a/examples/blender/blender.ts +++ b/examples/blender/blender.ts @@ -35,17 +35,21 @@ async function main(subnetTag: string, driver?: string, network?: string, debug? await ctx.uploadFile(`${__dirname}/cubes.blend`, "/golem/resource/scene.blend"); }); - const results = executor.map([0, 10, 20, 30, 40, 50], async (ctx, frame) => { - const result = await ctx - .beginBatch() - .uploadJson(blender_params(frame), "/golem/work/params.json") - .run("/golem/entrypoints/run-blender.sh") - .downloadFile(`/golem/output/out${frame?.toString().padStart(4, "0")}.png`, `${__dirname}/output_${frame}.png`) - .end() - .catch((e) => console.error(e)); - return result?.length ? `output_${frame}.png` : ""; - }); - for await (const result of results) console.log(result); + const futureResults = [0, 10, 20, 30, 40, 50].map((frame) => + executor.run(async (ctx) => { + const result = await ctx + .beginBatch() + .uploadJson(blender_params(frame), "/golem/work/params.json") + .run("/golem/entrypoints/run-blender.sh") + .downloadFile(`/golem/output/out${frame?.toString().padStart(4, "0")}.png`, `${__dirname}/output_${frame}.png`) + .end() + .catch((e) => console.error(e)); + return result?.length ? `output_${frame}.png` : ""; + }), + ); + const results = await Promise.all(futureResults); + results.forEach((result) => console.log(result)); + await executor.end(); } diff --git a/examples/docs-examples/examples/executing-tasks/action_log.txt b/examples/docs-examples/examples/executing-tasks/action_log.txt index bb5749a1f..170536dc7 100644 --- a/examples/docs-examples/examples/executing-tasks/action_log.txt +++ b/examples/docs-examples/examples/executing-tasks/action_log.txt @@ -1 +1 @@ -some action log \ No newline at end of file +some action log diff --git a/examples/docs-examples/examples/executing-tasks/before-each.mjs b/examples/docs-examples/examples/executing-tasks/before-each.mjs index 31913ed4c..fa349bd8d 100644 --- a/examples/docs-examples/examples/executing-tasks/before-each.mjs +++ b/examples/docs-examples/examples/executing-tasks/before-each.mjs @@ -12,13 +12,18 @@ import { TaskExecutor } from "@golem-sdk/golem-js"; await ctx.uploadFile("./action_log.txt", "/golem/input/action_log.txt"); }); - await executor.forEach([1, 2, 3, 4, 5], async (ctx, item) => { - await ctx - .beginBatch() - .run(`echo ` + `'processing item: ` + item + `' >> /golem/input/action_log.txt`) - .downloadFile("/golem/input/action_log.txt", "./output_" + ctx.provider.name + ".txt") - .end(); + const inputs = [1, 2, 3, 4, 5]; + + const futureResults = inputs.map(async (item) => { + return await executor.run(async (ctx) => { + await ctx + .beginBatch() + .run(`echo ` + `'processing item: ` + item + `' >> /golem/input/action_log.txt`) + .downloadFile("/golem/input/action_log.txt", "./output_" + ctx.provider.name + ".txt") + .end(); + }); }); + await Promise.all(futureResults); await executor.end(); })(); diff --git a/examples/docs-examples/examples/executing-tasks/foreach.mjs b/examples/docs-examples/examples/executing-tasks/foreach.mjs index e1cbd7fc1..521f62ac1 100644 --- a/examples/docs-examples/examples/executing-tasks/foreach.mjs +++ b/examples/docs-examples/examples/executing-tasks/foreach.mjs @@ -8,9 +8,11 @@ import { TaskExecutor } from "@golem-sdk/golem-js"; const data = [1, 2, 3, 4, 5]; - await executor.forEach(data, async (ctx, item) => { - console.log((await ctx.run(`echo "${item}"`)).stdout); - }); + for (const item of data) { + await executor.run(async (ctx) => { + console.log((await ctx.run(`echo "${item}"`)).stdout); + }); + } await executor.end(); })(); diff --git a/examples/docs-examples/examples/executing-tasks/map.mjs b/examples/docs-examples/examples/executing-tasks/map.mjs index 9fc089987..8ce0f91ee 100644 --- a/examples/docs-examples/examples/executing-tasks/map.mjs +++ b/examples/docs-examples/examples/executing-tasks/map.mjs @@ -8,9 +8,14 @@ import { TaskExecutor } from "@golem-sdk/golem-js"; const data = [1, 2, 3, 4, 5]; - const results = executor.map(data, (ctx, item) => ctx.run(`echo "${item}"`)); + const futureResults = data.map(async (item) => + executor.run(async (ctx) => { + return await ctx.run(`echo "${item}"`); + }), + ); - for await (const result of results) console.log(result.stdout); + const results = await Promise.all(futureResults); + results.forEach((result) => console.log(result.stdout)); await executor.end(); })(); diff --git a/examples/docs-examples/examples/executing-tasks/max-parallel-tasks.mjs b/examples/docs-examples/examples/executing-tasks/max-parallel-tasks.mjs index 0e1a11572..bc19a8bcd 100644 --- a/examples/docs-examples/examples/executing-tasks/max-parallel-tasks.mjs +++ b/examples/docs-examples/examples/executing-tasks/max-parallel-tasks.mjs @@ -9,9 +9,14 @@ import { TaskExecutor } from "@golem-sdk/golem-js"; const data = [1, 2, 3, 4, 5]; - const results = executor.map(data, (ctx, item) => ctx.run(`echo "${item}"`)); + const futureResults = data.map(async (item) => + executor.run(async (ctx) => { + return await ctx.run(`echo "${item}"`); + }), + ); - for await (const result of results) console.log(result.stdout); + const results = await Promise.all(futureResults); + results.forEach((result) => console.log(result.stdout)); await executor.end(); })(); diff --git a/examples/docs-examples/tutorials/running-parallel-tasks/index.mjs b/examples/docs-examples/tutorials/running-parallel-tasks/index.mjs index 6342bf373..71d20b2a9 100644 --- a/examples/docs-examples/tutorials/running-parallel-tasks/index.mjs +++ b/examples/docs-examples/tutorials/running-parallel-tasks/index.mjs @@ -19,24 +19,28 @@ async function main(args) { const step = Math.floor(keyspace / args.numberOfProviders + 1); const range = [...Array(Math.floor(keyspace / step) + 1).keys()].map((i) => i * step); - const results = executor.map(range, async (ctx, skip = 0) => { - const results = await ctx - .beginBatch() - .run( - `hashcat -a 3 -m 400 '${args.hash}' '${args.mask}' --skip=${skip} --limit=${Math.min( - keyspace, - skip + step, - )} -o pass.potfile`, - ) - .run("cat pass.potfile") - .end() - .catch((err) => console.error(err)); - if (!results?.[1]?.stdout) return false; - return results?.[1]?.stdout.toString().split(":")[1]; + const futureResults = range.map(async (skip = 0) => { + return executor.run(async (ctx) => { + const results = await ctx + .beginBatch() + .run( + `hashcat -a 3 -m 400 '${args.hash}' '${args.mask}' --skip=${skip} --limit=${Math.min( + keyspace, + skip + step, + )} -o pass.potfile`, + ) + .run("cat pass.potfile") + .end() + .catch((err) => console.error(err)); + if (!results?.[1]?.stdout) return false; + return results?.[1]?.stdout.toString().split(":")[1]; + }); }); + const results = await Promise.all(futureResults); + let password = ""; - for await (const result of results) { + for (const result of results) { if (result) { password = result; break; diff --git a/examples/fibonacci/fibonacci.js b/examples/fibonacci/fibonacci.js index 79e6e9ce2..78430d651 100644 --- a/examples/fibonacci/fibonacci.js +++ b/examples/fibonacci/fibonacci.js @@ -9,12 +9,17 @@ async function main(fiboN = 1, tasksCount = 1, subnetTag, driver, network, debug logLevel: debug ? "debug" : "info", }); - const data = Array(tasksCount).fill(null); + const runningTasks = []; + for (let i = 0; i < tasksCount; i++) { + runningTasks.push( + executor.run(async (ctx) => { + const result = await ctx.run("/usr/local/bin/node", ["/golem/work/fibo.js", fiboN.toString()]); + console.log(result.stdout); + }), + ); + } - await executor.forEach(data, async (ctx) => { - const result = await ctx.run("/usr/local/bin/node", ["/golem/work/fibo.js", fiboN.toString()]); - console.log(result.stdout); - }); + await Promise.all(runningTasks); await executor.end(); } program diff --git a/examples/simple-usage/forEach.ts b/examples/simple-usage/forEach.ts deleted file mode 100644 index 9ef76ec6a..000000000 --- a/examples/simple-usage/forEach.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { TaskExecutor } from "@golem-sdk/golem-js"; - -(async function main() { - const executor = await TaskExecutor.create("golem/alpine:latest"); - const data = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]; - await executor.forEach(data, async (ctx, x) => { - const res = await ctx.run(`echo "${x}"`); - console.log(`Result=${res.stdout}`); - }); - await executor.end(); -})(); diff --git a/examples/simple-usage/map.ts b/examples/simple-usage/map.ts index be464a905..20b4652ea 100644 --- a/examples/simple-usage/map.ts +++ b/examples/simple-usage/map.ts @@ -4,14 +4,15 @@ import { TaskExecutor } from "@golem-sdk/golem-js"; const executor = await TaskExecutor.create("golem/alpine:latest"); const data = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]; - const results = executor.map(data, async (ctx, x) => { - const res = await ctx.run(`echo "${x}"`); - return res.stdout?.toString().trim(); - }); - const finalOutput: string[] = []; - for await (const res of results) { - if (res) finalOutput.push(res); - } - console.log("RESULTS = ", finalOutput.join(", ")); + const futureResults = data.map((x) => + executor.run(async (ctx) => { + const res = await ctx.run(`echo "${x}"`); + return res.stdout?.toString().trim(); + }), + ); + + const results = await Promise.all(futureResults); + console.log(results); + await executor.end(); })(); diff --git a/examples/ssh/ssh.ts b/examples/ssh/ssh.ts index a2df5d088..6cf7253a1 100644 --- a/examples/ssh/ssh.ts +++ b/examples/ssh/ssh.ts @@ -12,31 +12,36 @@ async function main(subnetTag, driver, network, count = 2, sessionTimeout = 100, payment: { driver, network }, logLevel: debug ? "debug" : "info", }); - const data = new Array(count).fill(null); const appKey = process.env["YAGNA_APPKEY"]; - await executor.forEach(data, async (ctx) => { - const password = crypto.randomBytes(3).toString("hex"); - const results = await ctx - .beginBatch() - .run("syslogd") - .run("ssh-keygen -A") - .run(`echo -e "${password}\n${password}" | passwd`) - .run("/usr/sbin/sshd") - .end() - .catch((e) => console.error(e)); - if (!results) return; - console.log("\n------------------------------------------"); - console.log(`Connect via ssh to provider "${ctx.provider?.name}" with:`); - console.log( - `ssh -o ProxyCommand='websocat asyncstdio: ${ctx.getWebsocketUri( - 22, - )} --binary -H=Authorization:"Bearer ${appKey}"' root@${crypto.randomBytes(10).toString("hex")}`, + const runningTasks: Promise[] = []; + for (let i = 0; i < count; i++) { + runningTasks.push( + executor.run(async (ctx) => { + const password = crypto.randomBytes(3).toString("hex"); + const results = await ctx + .beginBatch() + .run("syslogd") + .run("ssh-keygen -A") + .run(`echo -e "${password}\n${password}" | passwd`) + .run("/usr/sbin/sshd") + .end() + .catch((e) => console.error(e)); + if (!results) return; + console.log("\n------------------------------------------"); + console.log(`Connect via ssh to provider "${ctx.provider?.name}" with:`); + console.log( + `ssh -o ProxyCommand='websocat asyncstdio: ${ctx.getWebsocketUri( + 22, + )} --binary -H=Authorization:"Bearer ${appKey}"' root@${crypto.randomBytes(10).toString("hex")}`, + ); + console.log(`Password: ${password}`); + console.log("------------------------------------------\n"); + await new Promise((res) => setTimeout(res, sessionTimeout * 1000)); + console.log(`Task completed. Session SSH closed after ${sessionTimeout} secs timeout.`); + }), ); - console.log(`Password: ${password}`); - console.log("------------------------------------------\n"); - await new Promise((res) => setTimeout(res, sessionTimeout * 1000)); - console.log(`Task completed. Session SSH closed after ${sessionTimeout} secs timeout.`); - }); + } + await Promise.all(runningTasks); await executor.end(); } diff --git a/examples/yacat/yacat.ts b/examples/yacat/yacat.ts index eec9dd8c0..139fcf50a 100644 --- a/examples/yacat/yacat.ts +++ b/examples/yacat/yacat.ts @@ -23,19 +23,22 @@ async function main(args) { const range = [...Array(Math.floor(keyspace / step)).keys()].map((i) => i * step); console.log(`Keyspace size computed. Keyspace size = ${keyspace}. Tasks to compute = ${range.length}`); - const results = executor.map(range, async (ctx, skip) => { - const results = await ctx - .beginBatch() - .run( - `hashcat -a 3 -m 400 '${args.hash}' '${args.mask}' --skip=${skip} --limit=${ - skip! + step - } -o pass.potfile || true`, - ) - .run("cat pass.potfile || true") - .end(); - if (!results?.[1]?.stdout) return false; - return results?.[1]?.stdout.toString().trim().split(":")[1]; - }); + const futureResults = range.map((skip) => + executor.run(async (ctx) => { + const results = await ctx + .beginBatch() + .run( + `hashcat -a 3 -m 400 '${args.hash}' '${args.mask}' --skip=${skip} --limit=${ + skip! + step + } -o pass.potfile || true`, + ) + .run("cat pass.potfile || true") + .end(); + if (!results?.[1]?.stdout) return false; + return results?.[1]?.stdout.toString().trim().split(":")[1]; + }), + ); + const results = await Promise.all(futureResults); let password = ""; for await (const result of results) { diff --git a/src/executor/executor.ts b/src/executor/executor.ts index fbdaffd1c..285b17533 100644 --- a/src/executor/executor.ts +++ b/src/executor/executor.ts @@ -343,12 +343,12 @@ export class TaskExecutor { * @example * ```typescript * const data = [1, 2, 3, 4, 5]; - * const resultsPromises = data.map((item) => + * const futureResults = data.map((item) => * executor.run((ctx) => { * console.log((await ctx.run(`echo "${item}"`)).stdout); * }) * ); - * await Promise.all(resultsPromises); + * const results = await Promise.all(futureResults); * ``` * * Map iterable data to worker function and return computed Task result as AsyncIterable @@ -404,12 +404,12 @@ export class TaskExecutor { * @example * ```typescript * const data = [1, 2, 3, 4, 5]; - * const resultsPromises = data.map((item) => + * const futureResults = data.map((item) => * executor.run((ctx) => { * console.log((await ctx.run(`echo "${item}"`)).stdout); * }), * ); - * await Promise.all(resultsPromises); + * await Promise.all(futureResults); * ``` * * Iterates over given data and execute task using worker function diff --git a/tests/e2e/blender.spec.ts b/tests/e2e/blender.spec.ts index 2f29a54db..5fce268be 100644 --- a/tests/e2e/blender.spec.ts +++ b/tests/e2e/blender.spec.ts @@ -38,20 +38,23 @@ describe("Blender rendering", function () { const data = [0, 10, 20, 30, 40, 50]; - const results = executor.map(data, async (ctx, frame) => { - const result = await ctx - .beginBatch() - .uploadJson(blenderParams(frame), "/golem/work/params.json") - .run("/golem/entrypoints/run-blender.sh") - .downloadFile(`/golem/output/out${frame?.toString().padStart(4, "0")}.png`, `output_${frame}.png`) - .end() - .catch((error) => console.error(error.toString())); - return result ? `output_${frame}.png` : ""; - }); + const futureResults = data.map((frame) => + executor.run(async (ctx) => { + const result = await ctx + .beginBatch() + .uploadJson(blenderParams(frame), "/golem/work/params.json") + .run("/golem/entrypoints/run-blender.sh") + .downloadFile(`/golem/output/out${frame?.toString().padStart(4, "0")}.png`, `output_${frame}.png`) + .end() + .catch((error) => console.error(error.toString())); + return result ? `output_${frame}.png` : ""; + }), + ); + const results = await Promise.all(futureResults); const expectedResults = data.map((d) => `output_${d}.png`); - for await (const result of results) { + for (const result of results) { expect(expectedResults).toContain(result); } diff --git a/tests/e2e/gftp.spec.ts b/tests/e2e/gftp.spec.ts index d57fafd9c..a38f11a52 100644 --- a/tests/e2e/gftp.spec.ts +++ b/tests/e2e/gftp.spec.ts @@ -20,19 +20,22 @@ describe("GFTP transfers", function () { const data = [0, 1, 2, 3, 4, 5]; - const results = executor.map(data, async (ctx, frame) => { - const result = await ctx - .beginBatch() - .run("ls -Alh /golem/work/eiffel.blend") - .downloadFile(`/golem/work/eiffel.blend`, `copy_${frame}.blend`) - .end() - .catch((error) => console.error(error.toString())); - return result ? `copy_${frame}.blend` : ""; - }); + const futureResults = data.map((frame) => + executor.run(async (ctx) => { + const result = await ctx + .beginBatch() + .run("ls -Alh /golem/work/eiffel.blend") + .downloadFile(`/golem/work/eiffel.blend`, `copy_${frame}.blend`) + .end() + .catch((error) => console.error(error.toString())); + return result ? `copy_${frame}.blend` : ""; + }), + ); + const results = await Promise.all(futureResults); const expectedResults = data.map((d) => `copy_${d}.blend`); - for await (const result of results) { + for (const result of results) { expect(expectedResults).toContain(result); } diff --git a/tests/e2e/strategies.spec.ts b/tests/e2e/strategies.spec.ts index b13528bc2..9c22225ad 100644 --- a/tests/e2e/strategies.spec.ts +++ b/tests/e2e/strategies.spec.ts @@ -15,12 +15,13 @@ describe("Strategies", function () { logger, }); const data = ["one", "two", "three"]; - const results = executor.map(data, async (ctx, x) => { - const res = await ctx.run(`echo "${x}"`); - return res.stdout?.toString().trim(); - }); - const finalOutputs: string[] = []; - for await (const res of results) if (res) finalOutputs.push(res); + const futureResults = data.map((x) => + executor.run(async (ctx) => { + const res = await ctx.run(`echo "${x}"`); + return res.stdout?.toString().trim(); + }), + ); + const finalOutputs = (await Promise.all(futureResults)).filter((x) => !!x); expect(finalOutputs).toEqual(expect.arrayContaining(data)); await logger.expectToInclude(`Proposal rejected by Proposal Filter`, 5000); await logger.expectToInclude(`Task 1 computed by provider provider-1`, 5000); @@ -36,12 +37,13 @@ describe("Strategies", function () { logger, }); const data = ["one", "two", "three"]; - const results = executor.map(data, async (ctx, x) => { - const res = await ctx.run(`echo "${x}"`); - return res.stdout?.toString().trim(); - }); - const finalOutputs: string[] = []; - for await (const res of results) if (res) finalOutputs.push(res); + const futureResults = data.map((x) => + executor.run(async (ctx) => { + const res = await ctx.run(`echo "${x}"`); + return res.stdout?.toString().trim(); + }), + ); + const finalOutputs = (await Promise.all(futureResults)).filter((x) => !!x); expect(finalOutputs).toEqual(expect.arrayContaining(data)); await logger.expectToInclude(`Proposal rejected by Proposal Filter`, 5000); await logger.expectToInclude(`Task 1 computed by provider provider-2`, 5000); @@ -58,12 +60,14 @@ describe("Strategies", function () { logger, }); const data = ["one", "two"]; - const results = executor.map(data, async (ctx, x) => { - const res = await ctx.run(`echo "${x}"`); - return res.stdout?.toString().trim(); - }); - const finalOutputs: string[] = []; - for await (const res of results) if (res) finalOutputs.push(res); + const futureResults = data.map((x) => + executor.run(async (ctx) => { + const res = await ctx.run(`echo "${x}"`); + return res.stdout?.toString().trim(); + }), + ); + const finalOutputs = (await Promise.all(futureResults)).filter((x) => !!x); + expect(finalOutputs).toEqual(expect.arrayContaining(data)); await executor.end(); await logger.expectToInclude(`Reason: Invoice rejected by Invoice Filter`, 100); @@ -76,12 +80,14 @@ describe("Strategies", function () { logger, }); const data = ["one", "two"]; - const results = executor.map(data, async (ctx, x) => { - const res = await ctx.run(`echo "${x}"`); - return res.stdout?.toString().trim(); - }); - const finalOutputs: string[] = []; - for await (const res of results) if (res) finalOutputs.push(res); + const futureResults = data.map((x) => + executor.run(async (ctx) => { + const res = await ctx.run(`echo "${x}"`); + return res.stdout?.toString().trim(); + }), + ); + const finalOutputs = (await Promise.all(futureResults)).filter((x) => !!x); + expect(finalOutputs).toEqual(expect.arrayContaining(data)); await executor.end(); await logger.expectToInclude(`DebitNote rejected by DebitNote Filter`, 100); diff --git a/tests/e2e/tasks.spec.ts b/tests/e2e/tasks.spec.ts index 0d070e86c..ff5c68ddc 100644 --- a/tests/e2e/tasks.spec.ts +++ b/tests/e2e/tasks.spec.ts @@ -67,12 +67,13 @@ describe("Task Executor", function () { logger, }); const data = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]; - const results = executor.map(data, async (ctx, x) => { - const res = await ctx.run(`echo "${x}"`); - return res.stdout?.toString().trim(); - }); - const finalOutputs: string[] = []; - for await (const res of results) if (res) finalOutputs.push(res); + const futureResults = data.map((x) => + executor.run(async (ctx) => { + const res = await ctx.run(`echo "${x}"`); + return res.stdout?.toString().trim(); + }), + ); + const finalOutputs = (await Promise.all(futureResults)).filter((x) => !!x); expect(finalOutputs).toEqual(expect.arrayContaining(data)); }); diff --git a/tests/e2e/yacat.spec.ts b/tests/e2e/yacat.spec.ts index f9612bc2a..22ebfc5dc 100644 --- a/tests/e2e/yacat.spec.ts +++ b/tests/e2e/yacat.spec.ts @@ -34,17 +34,22 @@ describe("Password cracking", function () { if (!keyspace) return; const step = Math.floor(keyspace / 3); const ranges = range(0, keyspace, step); - const results = executor.map(ranges, async (ctx, skip) => { - const results = await ctx - .beginBatch() - .run(`hashcat -a 3 -m 400 '${hash}' '${mask}' --skip=${skip} --limit=${skip! + step} -o pass.potfile -D 1,2`) - .run("cat pass.potfile") - .end(); - if (!results?.[1]?.stdout) return false; - return results?.[1]?.stdout.toString().split(":")?.[1]?.trim(); - }); + const futureResults = ranges.map((skip) => + executor.run(async (ctx) => { + const results = await ctx + .beginBatch() + .run( + `hashcat -a 3 -m 400 '${hash}' '${mask}' --skip=${skip} --limit=${skip! + step} -o pass.potfile -D 1,2`, + ) + .run("cat pass.potfile") + .end(); + if (!results?.[1]?.stdout) return false; + return results?.[1]?.stdout.toString().split(":")?.[1]?.trim(); + }), + ); + const results = await Promise.all(futureResults); let password = ""; - for await (const result of results) { + for (const result of results) { if (result) { password = result; break; From 3c7b11d84da1f7a653edac21070c5b7aa8265871 Mon Sep 17 00:00:00 2001 From: Seweryn Kras Date: Tue, 14 Nov 2023 10:43:41 +0100 Subject: [PATCH 12/12] chore: fix error message formatting --- src/executor/executor.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/executor/executor.ts b/src/executor/executor.ts index 285b17533..f454ede24 100644 --- a/src/executor/executor.ts +++ b/src/executor/executor.ts @@ -573,8 +573,8 @@ export class TaskExecutor { proposalsCount.initial === 0 && proposalsCount.confirmed === 0 ? "Check your demand if it's not too restrictive or restart yagna." : proposalsCount.initial === proposalsCount.rejected - ? "All off proposals got rejected." - : "Check your proposal filters if they are not too restrictive."; + ? "All off proposals got rejected." + : "Check your proposal filters if they are not too restrictive."; this.handleCriticalError( new Error( `Could not start any work on Golem. Processed ${proposalsCount.initial} initial proposals from yagna, filters accepted ${proposalsCount.confirmed}. ${hint}`,