From f8d610e7a23bf5db69cb250640e6dc4b25815438 Mon Sep 17 00:00:00 2001 From: fmacleal Date: Fri, 12 Jul 2024 16:13:45 +0200 Subject: [PATCH] Adding the waitTime and maxAttempts configurable with env variables --- .env-example | 15 +++++++++++++++ .github/images/scripts/configure_rit_locally.sh | 2 ++ lib/rsk-utils-legacy.js | 4 +++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.env-example b/.env-example index fd4e7b5e..a616c611 100644 --- a/.env-example +++ b/.env-example @@ -1,3 +1,18 @@ INCLUDE_CASES=00_00_01-sync.js,01_01_01-pre_orchid_2wp.js RUN_EACH_TEST_FILE_THESE_TIMES=1 RUN_ALL_TESTS_THESE_TIMES=1 + +# Amount of time in milliseconds for the `waitForBlock` utility function to wait. +# Configurable because depending on the resources of the machine the tests are running on, the wait time might change. +# In a machine with little resources (CPU, RAM, disk), a small wait time might not be enough because blocks can be mined slow and `waitForBlock` +# might fail with a message like `Block number 800 never reached, last seen was 600`, or `Blockchain not advancing after attempting to find a new block 80 times checking every 200 milliseconds. +# Couldn't reach block number 800. Last block number seen was: 600`. In a machine with enough resources having a high wait time might be a waste of time since the tests would run slower because if this wait time. +# In this case, it can be set to a small value. `200` recommended for most machines with enough resources. `500`, `600`, etc., or more for machine with limited resources. +# Adjust as needed, starting with low values so the tests run as fast as they can. +WAIT_FOR_BLOCK_ATTEMPT_TIME_MILLIS= + +# Max attempts for the `waitForBlock` utility function to 'wait' for the given block, trying to find that block once every `WAIT_FOR_BLOCK_ATTEMPT_TIME_MILLIS`. +# The same as the `WAIT_FOR_BLOCK_ATTEMPT_TIME_MILLIS` variable, the value for this variable could be updated depending on the machine the tests are running on. +# `80` recommended for most machines with enough resources. `160`, `250` or more for machine with limited resources. +# Adjust as needed, starting with low values so the tests run as fast as they can. +WAIT_FOR_BLOCK_MAX_ATTEMPTS= diff --git a/.github/images/scripts/configure_rit_locally.sh b/.github/images/scripts/configure_rit_locally.sh index d8ef652f..444d7d63 100755 --- a/.github/images/scripts/configure_rit_locally.sh +++ b/.github/images/scripts/configure_rit_locally.sh @@ -9,6 +9,8 @@ CONFIG_FILE=/usr/src/rit/config/regtest.js LOG_HOME=/usr/src/rit/logs BITCOIND_BIN_PATH=/usr/local/bin/bitcoind BITCOIN_DATA_DIR=/usr/src/bitcoindata +WAIT_FOR_BLOCK_ATTEMPT_TIME_MILLIS=600 +WAIT_FOR_BLOCK_MAX_ATTEMPTS=1000 EOF echo -e "\n\n---------- Configuring RIT to run the tests locally -----------\n\n" diff --git a/lib/rsk-utils-legacy.js b/lib/rsk-utils-legacy.js index 9ef75469..ea78023b 100644 --- a/lib/rsk-utils-legacy.js +++ b/lib/rsk-utils-legacy.js @@ -2,6 +2,8 @@ const expect = require('chai').expect; const btcClientProvider = require('./btc-client-provider'); const { sequentialPromise, wait, interval } = require('./utils'); const { getBridgeAbi, getLatestActiveForkName } = require('./precompiled-abi-forks-util'); +const waitForBlockAttemptTimeMillis = process.env.WAIT_FOR_BLOCK_ATTEMPT_TIME_MILLIS || 200 +const waitForBlockMaxAttempts = process.env. WAIT_FOR_BLOCK_MAX_ATTEMPTS || 160; var getMaxBlockNumber = (rskClients) => { var maxBlockNumber; @@ -26,7 +28,7 @@ var waitForSync = (rskClients) => { }); }; -var waitForBlock = (rskClient, blockNumber, waitTime = 600, maxAttempts = 1000) => { +var waitForBlock = (rskClient, blockNumber, waitTime = waitForBlockAttemptTimeMillis, maxAttempts = waitForBlockMaxAttempts) => { return new Promise((resolve, reject) => { var clearPoll; var attempts = 0;