Skip to content

Commit f9e4f77

Browse files
committed
Add basic exponential backoff to failing puppeteer integration tests
1 parent 4356f92 commit f9e4f77

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

helpers/integration-tests/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ const runIntegrationTests = async () => {
88

99
try {
1010
for (const test of [runStaticTests, runScannerTest]) {
11-
const errorFound = await test();
11+
const success = await test();
1212

13-
if (errorFound) {
13+
if (!success) {
1414
error = true;
1515
}
1616
}

helpers/integration-tests/scanner.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const runScannerTest = async () => {
2222
}! => Status: ${response.status()}`
2323
);
2424

25-
return response.status() !== 200;
25+
return response.status() === 200;
2626
} catch (error) {
2727
console.error('🚨 Something went wrong while executing Puppeteer: ', error);
2828
await browser.close();

helpers/integration-tests/staticUrls.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ const staticURLsToVerify = [
77
'https://sonarwhal-staging.azurewebsites.net/docs/user-guide/hints/'
88
];
99

10+
const backOffTime = 5000;
11+
const maxRetries = 3;
12+
13+
const delay = (ms) => {
14+
return new Promise(resolve => setTimeout(resolve, ms));
15+
};
16+
1017
const runPuppeteer = async (url) => {
1118
const browser = await puppeteer.launch();
1219

@@ -32,17 +39,23 @@ const runPuppeteer = async (url) => {
3239
};
3340

3441
const runStaticTests = async () => {
35-
let errorFound = false;
42+
let success = true;
43+
let retryCount = 0;
44+
let resultStatus = null;
3645

3746
for (const url of staticURLsToVerify) {
38-
const resultStatus = await runPuppeteer(url);
47+
resultStatus = await runPuppeteer(url);
3948

40-
if (resultStatus !== 200) {
41-
errorFound = true;
49+
while(resultStatus !== 200 && retryCount < maxRetries) {
50+
console.log('Test failed, retrying... Attempt #' + (++retryCount));
51+
await delay(backOffTime * retryCount);
52+
resultStatus = await runPuppeteer(url);
4253
}
54+
55+
success = success && resultStatus === 200;
4356
}
4457

45-
return errorFound;
58+
return success;
4659
};
4760

4861
module.exports = { runStaticTests };

0 commit comments

Comments
 (0)