Skip to content

Commit 3a1219b

Browse files
committed
Retry integration tests when they fail
1 parent 018e9c0 commit 3a1219b

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

extensions/ql-vscode/src/vscode-tests/run-integration-tests.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,41 @@
11
import * as path from 'path';
22
import { runTests } from 'vscode-test';
33

4+
// A subset of the fields in TestOptions from vscode-test, which we
5+
// would simply use instead, but for the fact that it doesn't export
6+
// it.
7+
type Suite = {
8+
extensionDevelopmentPath: string,
9+
extensionTestsPath: string,
10+
launchArgs: string[]
11+
};
12+
13+
/**
14+
* Run an integration test suite `suite` at most `tries` times, or
15+
* until it succeeds, whichever comes first.
16+
*
17+
* TODO: Presently there is no way to distinguish a legitimately
18+
* failed test run from the test runner being terminated by a signal.
19+
* If in the future there arises a way to distinguish these cases
20+
* (e.g. https://github.com/microsoft/vscode-test/pull/56) only retry
21+
* in the terminated-by-signal case.
22+
*/
23+
async function runTestsWithRetry(suite: Suite, tries: number): Promise<void> {
24+
for (let t = 0; t < tries; t++) {
25+
try {
26+
// Download and unzip VS Code if necessary, and run the integration test suite.
27+
await runTests(suite);
28+
return;
29+
} catch (err) {
30+
console.error(`Exception raised while running tests: ${err}`);
31+
if (t < tries - 1)
32+
console.error('Retrying...');
33+
}
34+
}
35+
console.error(`Tried running suite ${tries} time(s), still failed, giving up.`);
36+
process.exit(1);
37+
}
38+
439
/**
540
* Integration test runner. Launches the VSCode Extension Development Host with this extension installed.
641
* See https://github.com/microsoft/vscode-test/blob/master/sample/test/runTest.ts
@@ -32,11 +67,10 @@ async function main() {
3267
];
3368

3469
for (const integrationTestSuite of integrationTestSuites) {
35-
// Download and unzip VS Code if necessary, and run the integration test suite.
36-
await runTests(integrationTestSuite);
70+
await runTestsWithRetry(integrationTestSuite, 2);
3771
}
3872
} catch (err) {
39-
console.error('Failed to run tests');
73+
console.error('Unexpected exception while running tests');
4074
process.exit(1);
4175
}
4276
}

0 commit comments

Comments
 (0)