Skip to content

Commit af68124

Browse files
authored
test(amazonq): performance test for building index and sending to LSP. (aws#5685)
## Problem continuation of reliability work ## Solution `buildIndex` in `src/amazonq/lsp/lspController.ts` captures many potentially high risk paths in a single function, such as some I/O operations and searching for project directories. Thresholds determined by running in CI a few times and multiplying the observed median by 1.5 to 2.0 depending on variance. The "many files" test does 250 files w/ 10 bytes each. The "large files" does 10 files w/ 1000 bytes each. These values were chosen to avoid flakiness in CI. Included in this PR is removing the use of fs-extra in `src/amazonq/lsp/lspController.ts` --- <!--- 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.
1 parent 3f80141 commit af68124

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { performanceTest } from '../shared/performance/performance'
7+
import * as sinon from 'sinon'
8+
import * as vscode from 'vscode'
9+
import assert from 'assert'
10+
import { LspClient, LspController } from '../amazonq'
11+
import { LanguageClient, ServerOptions } from 'vscode-languageclient'
12+
import { createTestWorkspace } from '../test/testUtil'
13+
import { GetUsageRequestType, IndexRequestType } from '../amazonq/lsp/types'
14+
import { getRandomString } from '../shared'
15+
16+
interface SetupResult {
17+
clientReqStub: sinon.SinonStub
18+
}
19+
20+
async function verifyResult(setup: SetupResult) {
21+
assert.ok(setup.clientReqStub.calledTwice)
22+
assert.ok(setup.clientReqStub.firstCall.calledWith(IndexRequestType))
23+
assert.ok(setup.clientReqStub.secondCall.calledWith(GetUsageRequestType))
24+
}
25+
26+
async function setupWithWorkspace(numFiles: number, options: { fileContent: string }): Promise<SetupResult> {
27+
// Force VSCode to find my test workspace only to keep test contained and controlled.
28+
const testWorksapce = await createTestWorkspace(numFiles, options)
29+
sinon.stub(vscode.workspace, 'workspaceFolders').value([testWorksapce])
30+
// Avoid sending real request to lsp.
31+
const clientReqStub = sinon.stub(LanguageClient.prototype, 'sendRequest').resolves(true)
32+
LspClient.instance.client = new LanguageClient('amazonq', 'test-client', {} as ServerOptions, {})
33+
return { clientReqStub }
34+
}
35+
36+
describe('buildIndex', function () {
37+
describe('performanceTests', function () {
38+
afterEach(function () {
39+
sinon.restore()
40+
})
41+
performanceTest({}, 'indexing many small files', function () {
42+
return {
43+
setup: async () => setupWithWorkspace(250, { fileContent: '0123456789' }),
44+
execute: async () => {
45+
await LspController.instance.buildIndex()
46+
},
47+
verify: verifyResult,
48+
}
49+
})
50+
performanceTest({}, 'indexing few large files', function () {
51+
return {
52+
setup: async () => setupWithWorkspace(10, { fileContent: getRandomString(1000) }),
53+
execute: async () => {
54+
await LspController.instance.buildIndex()
55+
},
56+
verify: verifyResult,
57+
}
58+
})
59+
})
60+
})

0 commit comments

Comments
 (0)