Skip to content

Commit

Permalink
build(test): add automatic retry to all mocha tests. (#6005)
Browse files Browse the repository at this point in the history
## Problem
There are many unreliable tests that seem to fail very rarely or even
only once. If they are truly failing so rarely, retrying them should
keep CI green. This also allows us to avoid investigating flaky tests
that aren't having a meaningful negative impact on the dev experience.

## Solution
- retry failed tests up to 3 times. 

---

<!--- REMINDER: Ensure that your PR meets the guidelines in
CONTRIBUTING.md -->

License: I confirm that my contribution is made under the terms of the
Apache 2.0 license.
  • Loading branch information
Hweinstock authored Nov 18, 2024
1 parent 4158d67 commit ccba819
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
9 changes: 5 additions & 4 deletions packages/core/src/test/testRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function runTests(
testFolder: string | string[],
extensionId: string,
initTests: string[] = [],
testFiles?: string[]
options?: { retries?: number; testFiles?: string[] }
): Promise<void> {
if (!process.env['AWS_TOOLKIT_AUTOMATION']) {
throw new Error('Expected the "AWS_TOOLKIT_AUTOMATION" environment variable to be set for tests.')
Expand Down Expand Up @@ -79,6 +79,7 @@ export async function runTests(
mochaFile: outputFile,
},
},
retries: options?.retries ?? 0,
timeout: 0,
})

Expand All @@ -91,7 +92,7 @@ export async function runTests(
testFilePath = testFile ? path.resolve(dist, testFile) : undefined
}

if (testFile && testFiles) {
if (testFile && options?.testFiles) {
throw new Error('Individual file and list of files given to run tests on. One must be chosen.')
}

Expand Down Expand Up @@ -143,8 +144,8 @@ export async function runTests(
}

let files: string[] = []
if (testFiles) {
files = testFiles
if (options?.testFiles) {
files = options.testFiles
} else {
for (const f of Array.isArray(testFolder) ? testFolder : [testFolder]) {
files = [...files, ...(await glob(testFilePath ?? `**/${f}/**/**.test.js`, { cwd: dist }))]
Expand Down
9 changes: 6 additions & 3 deletions packages/toolkit/test/unit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { runTests } from 'aws-core-vscode/test'
import { VSCODE_EXTENSION_ID } from 'aws-core-vscode/utils'

export function run(): Promise<void> {
return runTests(process.env.TEST_DIR ?? ['test/unit', '../../core/dist/src/test'], VSCODE_EXTENSION_ID.awstoolkit, [
'../../core/dist/src/test/globalSetup.test.ts',
])
return runTests(
process.env.TEST_DIR ?? ['test/unit', '../../core/dist/src/test'],
VSCODE_EXTENSION_ID.awstoolkit,
['../../core/dist/src/test/globalSetup.test.ts'],
{ retries: 3 }
)
}

0 comments on commit ccba819

Please sign in to comment.