mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
cc90fca2f6
The benchmark script can now be set to retry upon failure, like the E2E tests do. The default is zero, just as with the E2E tests. A retry of 2 has been set in CI to match the E2E tests as well. The `retry` module had to be adjusted to throw an error in the case of failure. Previously it just set the exit code, but that only worked because it was the last thing called before the process ended. That is no longer the case.
24 lines
603 B
JavaScript
24 lines
603 B
JavaScript
/**
|
|
* Run the given function, retrying it upon failure until reaching the
|
|
* specified number of retries.
|
|
*
|
|
* @param {number} retries - The number of retries upon failure to attempt.
|
|
* @param {function} functionToRetry - The function that will be retried upon failure.
|
|
*/
|
|
async function retry(retries, functionToRetry) {
|
|
let attempts = 0;
|
|
while (attempts <= retries) {
|
|
try {
|
|
await functionToRetry();
|
|
return;
|
|
} catch (error) {
|
|
console.error(error);
|
|
} finally {
|
|
attempts += 1;
|
|
}
|
|
}
|
|
throw new Error('Retry limit reached');
|
|
}
|
|
|
|
module.exports = { retry };
|