|
1 | 1 | import * as path from 'path'; |
2 | 2 | import { runTests } from 'vscode-test'; |
3 | 3 |
|
| 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 | + |
4 | 39 | /** |
5 | 40 | * Integration test runner. Launches the VSCode Extension Development Host with this extension installed. |
6 | 41 | * See https://github.com/microsoft/vscode-test/blob/master/sample/test/runTest.ts |
@@ -32,11 +67,10 @@ async function main() { |
32 | 67 | ]; |
33 | 68 |
|
34 | 69 | 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); |
37 | 71 | } |
38 | 72 | } catch (err) { |
39 | | - console.error('Failed to run tests'); |
| 73 | + console.error('Unexpected exception while running tests'); |
40 | 74 | process.exit(1); |
41 | 75 | } |
42 | 76 | } |
|
0 commit comments