Skip to content

Commit 9b873dc

Browse files
authored
test(amazonq): reduce flakiness by avoiding unnecessary fs operations. (aws#7259)
## Problem This test has been very flaky, and constantly failing CI (aws#7187). This test is run for almost 40 different cases, and does the following: - create a text document - write it to the filesystem. - run the check on the text document. One of the core issues is that when we write the text document to the filesystem, we create a new test workspace folder for each case. This involves creating a directory with a random id for each of the almost 40 different cases. These excessive file system operations could be leading to the flakiness in CI. ## Solution - reuse the same test workspace folder across all test cases. This should cut the file systems operations in half. ## Future Work - If this doesn't reduce flakiness, we could avoid writing the text document to the fs since its not needed by the underlying test, but this involves mocking the text document which is undesirable imo. --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 0b169a8 commit 9b873dc

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/amazonq/test/unit/codewhisperer/util/runtimeLanguageContext.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44
*/
55

66
import assert from 'assert'
7-
import { resetCodeWhispererGlobalVariables, toTextDocument } from 'aws-core-vscode/test'
7+
import { resetCodeWhispererGlobalVariables, TestFolder, toTextDocument } from 'aws-core-vscode/test'
88
import { runtimeLanguageContext, RuntimeLanguageContext, PlatformLanguageId } from 'aws-core-vscode/codewhisperer'
99
import * as codewhispererClient from 'aws-core-vscode/codewhisperer'
1010
import { CodewhispererLanguage } from 'aws-core-vscode/shared'
1111

1212
describe('runtimeLanguageContext', function () {
1313
const languageContext = new RuntimeLanguageContext()
14+
let tempFolder: TestFolder
15+
16+
before(async function () {
17+
tempFolder = await TestFolder.create()
18+
})
1419

1520
describe('test isLanguageSupported', function () {
1621
const cases: [string, boolean][] = [
@@ -104,13 +109,12 @@ describe('runtimeLanguageContext', function () {
104109
['helloUnknown', false],
105110
['helloFoo.foo', false],
106111
]
107-
108112
for (const tuple of cases) {
109113
const fileName = tuple[0]
110114
const expected = tuple[1]
111115

112116
it(`pass document ${fileName} as argument should first try determine by languageId then file extensions`, async function () {
113-
const doc = await toTextDocument('', fileName)
117+
const doc = await toTextDocument('', fileName, tempFolder.path)
114118
const actual = languageContext.isLanguageSupported(doc)
115119
assert.strictEqual(actual, expected)
116120
})

0 commit comments

Comments
 (0)