Skip to content

Commit f9220e3

Browse files
magleasoDanny McCormick
authored andcommitted
Add Retries to Tool Retrieval (#55)
* Add Retries to Tool Retrieval Per #10170 * nit: misspelled test name and var name * Wrote test for timeouts on downloadTool * Update tests and dependencies (#2) * Updated dependencies, fixed timeout test * Updated gitignore to ignore vscode files * Removed vscode directory * Removed weird spacing change * Remove old retry code, fix max retries * Updated dependencies, fixed timeout test * Updated gitignore to ignore vscode files * Removed vscode directory * Removed weird spacing change * Removed old retry code, fixed max retries to match tests. * Removed retry on timeout test (#4) * Updated dependencies, fixed timeout test * Updated gitignore to ignore vscode files * Removed vscode directory * Removed weird spacing change * Removed old retry code, fixed max retries to match tests. * Removed retry on timeout test
1 parent e545bc7 commit f9220e3

File tree

5 files changed

+52
-65
lines changed

5 files changed

+52
-65
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,7 @@ package-lock.json
4545
.node_repl_history
4646

4747
# Temp directories
48-
TEMP
48+
TEMP
49+
50+
# VS Code Files
51+
.vscode

package-lock.json

Lines changed: 28 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "azure-pipelines-tool-lib",
3-
"version": "0.13.0",
3+
"version": "0.13.1",
44
"description": "Azure Pipelines Tool Installer Lib for CI/CD Tasks",
55
"main": "tool.js",
66
"scripts": {
@@ -24,22 +24,22 @@
2424
"homepage": "https://github.com/microsoft/azure-pipelines-tool-lib#readme",
2525
"dependencies": {
2626
"@types/semver": "^5.3.0",
27-
"@types/uuid": "^3.0.1",
27+
"@types/uuid": "^3.4.5",
2828
"azure-pipelines-task-lib": "^2.8.0",
29-
"semver": "^5.3.0",
29+
"semver": "^5.7.0",
3030
"semver-compare": "^1.0.0",
31-
"typed-rest-client": "1.0.9",
32-
"uuid": "^3.0.1"
31+
"typed-rest-client": "1.5.0",
32+
"uuid": "^3.3.2"
3333
},
3434
"devDependencies": {
35-
"typescript": "3.1.5",
36-
"@types/node": "^8.0.19",
37-
"nock": "9.6.1",
38-
"mocha": "^3.2.0",
3935
"@types/mocha": "^2.2.41",
36+
"@types/node": "^8.10.50",
37+
"@types/shelljs": "^0.7.9",
38+
"@types/xml2js": "^0.4.4",
39+
"mocha": "^3.2.0",
40+
"nock": "9.6.1",
4041
"shelljs": "^0.7.6",
41-
"@types/shelljs": "^0.7.4",
42-
"xml2js": "^0.4.17",
43-
"@types/xml2js": "^0.4.0"
42+
"typescript": "3.1.5",
43+
"xml2js": "^0.4.17"
4444
}
4545
}

test/tests/toolTests.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,18 @@ describe('Tool Tests', function () {
6969
});
7070
});
7171

72-
it('downloads to an aboslute path', function () {
72+
it('downloads to an absolute path', function () {
7373
this.timeout(5000);
7474

7575
return new Promise<void>(async(resolve, reject)=> {
7676
try {
7777
let tempDownloadFolder: string = 'temp_' + Math.floor(Math.random() * 2000000000);
78-
let aboslutePath: string = path.join(tempPath, tempDownloadFolder);
79-
let downPath: string = await toolLib.downloadTool("http://httpbin.org/bytes/100", aboslutePath);
78+
let absolutePath: string = path.join(tempPath, tempDownloadFolder);
79+
let downPath: string = await toolLib.downloadTool("http://httpbin.org/bytes/100", absolutePath);
8080
toolLib.debug('downloaded path: ' + downPath);
8181

8282
assert(tl.exist(downPath), 'downloaded file exists');
83-
assert(aboslutePath == downPath);
83+
assert(absolutePath == downPath);
8484

8585
resolve();
8686
}

tool.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ let userAgent = 'vsts-task-installer/' + pkg.version;
1717
let requestOptions = {
1818
// ignoreSslError: true,
1919
proxy: tl.getHttpProxyConfiguration(),
20-
cert: tl.getHttpCertConfiguration()
20+
cert: tl.getHttpCertConfiguration(),
21+
allowRedirects: true,
22+
allowRetries: true,
23+
maxRetries: 2
2124
} as ifm.IRequestOptions;
2225
tl.setResourcePath(path.join(__dirname, 'lib.json'));
2326

@@ -225,18 +228,7 @@ export async function downloadTool(url: string, fileName?: string, handlers?: if
225228
}
226229

227230
tl.debug('downloading');
228-
const statusCodesToRetry = [httpm.HttpCodes.BadGateway, httpm.HttpCodes.ServiceUnavailable, httpm.HttpCodes.GatewayTimeout];
229-
let retryCount: number = 1;
230-
const maxRetries: number = 3;
231231
let response: httpm.HttpClientResponse = await http.get(url);
232-
233-
while(retryCount < maxRetries && statusCodesToRetry.indexOf(response.message.statusCode) > -1) {
234-
tl.debug(`Download attempt "${retryCount}" of "${maxRetries}" failed with status code "${response.message.statusCode}".`);
235-
retryCount += 1;
236-
await delay(1000);
237-
tl.debug(`Downloading attempt "${retryCount}" of "${maxRetries}"`);
238-
response = await http.get(url);
239-
}
240232

241233
if (response.message.statusCode != 200) {
242234
let err: Error = new Error('Unexpected HTTP response: ' + response.message.statusCode);

0 commit comments

Comments
 (0)