Skip to content

Commit

Permalink
Adding the waitTime and maxAttempts configurable with env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
fmacleal committed Jul 12, 2024
1 parent 791953a commit f8d610e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
@@ -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=
2 changes: 2 additions & 0 deletions .github/images/scripts/configure_rit_locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion lib/rsk-utils-legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit f8d610e

Please sign in to comment.