From df8d21e09d053dd19bc0b2f900558d97a8de3eea Mon Sep 17 00:00:00 2001 From: seaona Date: Tue, 21 May 2024 09:19:17 +0200 Subject: [PATCH] address dev review: move retries to variable remove try/catch --- development/lib/retry.js | 8 ++++---- test/e2e/fetch-changed-files.js | 2 +- test/e2e/run-all.js | 13 +++++-------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/development/lib/retry.js b/development/lib/retry.js index 1981d679c3d3..21a71134f263 100644 --- a/development/lib/retry.js +++ b/development/lib/retry.js @@ -46,12 +46,12 @@ async function retry( console.error('error caught in retry():', error); } - if (attempts < retries) { - console.log('Ready to retry() again'); + if (retryUntilFailure) { + throw new Error('Test failed. No more retries will be performed'); } - if (retryUntilFailure) { - return null; + if (attempts < retries) { + console.log('Ready to retry() again'); } } finally { attempts += 1; diff --git a/test/e2e/fetch-changed-files.js b/test/e2e/fetch-changed-files.js index 364e1da43f38..28c1ee696360 100644 --- a/test/e2e/fetch-changed-files.js +++ b/test/e2e/fetch-changed-files.js @@ -26,7 +26,7 @@ async function fetchChangedE2eFiles() { return filesChanged; } catch (error) { console.error('Error making request:', error); - throw error; + return ''; } } diff --git a/test/e2e/run-all.js b/test/e2e/run-all.js index 6b99f0e646ea..528db85645c9 100644 --- a/test/e2e/run-all.js +++ b/test/e2e/run-all.js @@ -213,12 +213,9 @@ async function main() { console.log('My test list:', myTestList); - let changedOrNewTests = ''; - try { - changedOrNewTests = await fetchChangedE2eFiles(); - } catch (error) { - console.error('Error fetching changed e2e files:', error); - } + const changedOrNewTests = await fetchChangedE2eFiles(); + const retriesForChangedOrNewTests = 5; + console.log('Spec files that will be re-run:', changedOrNewTests); // spawn `run-e2e-test.js` for each test in myTestList @@ -228,14 +225,14 @@ async function main() { console.log(`\nExecuting testPath: ${testPath}\n`); const testFileName = testPath.split('/').pop(); - const isTestChangedOrNew = changedOrNewTests.includes(testFileName); + const isTestChangedOrNew = changedOrNewTests?.includes(testFileName); const retryIndex = args.indexOf('--retries'); if (retryIndex !== -1) { args.splice(retryIndex, 2); } const extraArgs = isTestChangedOrNew - ? ['--retry-until-failure', '--retries=5'] + ? ['--retry-until-failure', `--retries=${retriesForChangedOrNewTests}`] : []; await runInShell('node', [...args, ...extraArgs, testPath]); }