Skip to content

Commit b967b03

Browse files
authored
Merge pull request #906 from webhintio/azure-pipelines
Update yaml to update slot deployment creds + add exponential backoff to intermittently failing integration tests
2 parents 47e3109 + a513b73 commit b967b03

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

azure-pipelines.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ jobs:
3131
- script: npm run test-staging && node helpers/integration-tests/index.js
3232
displayName: 'Analyze staging with webhint'
3333
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
34-
- bash: |
35-
az login --service-principal -u $AZURE_SERVICE_PRINCIPAL -p $AZURE_SERVICE_PRINCIPAL_PASSWORD --tenant $AZURE_TENANT
36-
az webapp deployment slot swap -g webhint-web -n sonarwhal --slot staging
34+
- task: AzureAppServiceManage@0
3735
displayName: 'Swap into production'
3836
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
39-
env:
40-
AZURE_SERVICE_PRINCIPAL: $(AZURE_SERVICE_PRINCIPAL)
41-
AZURE_SERVICE_PRINCIPAL_PASSWORD: $(AZURE_SERVICE_PRINCIPAL_PASSWORD)
42-
AZURE_TENANT: $(AZURE_TENANT)
37+
inputs:
38+
azureSubscription: 'webhint-web'
39+
Action: 'Swap Slots'
40+
WebAppName: 'sonarwhal'
41+
ResourceGroupName: 'webhint-web'
42+
SourceSlot: 'staging'
4343
- bash: |
4444
curl https://www.google.com/ping?sitemap=https://webhint.io/sitemap.xml
4545
curl https://www.bing.com/ping?sitemap=https://webhint.io/sitemap.xml

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)