Skip to content

Commit 25c28d0

Browse files
authored
test(amazonq): add performance test for prepareRepoData (aws#5670)
## Problem Start of reliability work to enhance performance testing of high risk code paths. ## Solution `prepareRepoData` in `src/amazonqFeatureDev/util/files.ts` captures many potentially high risk paths in a single function, such as `collectFiles` and other I/O operations, making it a great place to start performance testing. Two performance tests were added, one for handling a workspace with many small files, and one with few large files. Unsurprisingly, the performance is significantly better on fewer larger files as it reduces # of I/O operations. Thresholds are very lenient to avoid flaky tests. 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. --- <!--- 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 8734c52 commit 25c28d0

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
import assert from 'assert'
6+
import { WorkspaceFolder } from 'vscode'
7+
import { performanceTest } from '../../shared/performance/performance'
8+
import { createTestWorkspace } from '../testUtil'
9+
import { prepareRepoData, TelemetryHelper } from '../../amazonqFeatureDev'
10+
import { AmazonqCreateUpload, getRandomString, Metric } from '../../shared'
11+
12+
type resultType = {
13+
zipFileBuffer: Buffer
14+
zipFileChecksum: string
15+
}
16+
17+
function performanceTestWrapper(numFiles: number, fileSize: number) {
18+
return performanceTest(
19+
{
20+
testRuns: 10,
21+
linux: {
22+
userCpuUsage: 100,
23+
systemCpuUsage: 35,
24+
heapTotal: 4,
25+
},
26+
darwin: {
27+
userCpuUsage: 100,
28+
systemCpuUsage: 35,
29+
heapTotal: 4,
30+
},
31+
win32: {
32+
userCpuUsage: 100,
33+
systemCpuUsage: 35,
34+
heapTotal: 4,
35+
},
36+
},
37+
`handles ${numFiles} files of size ${fileSize} bytes`,
38+
function () {
39+
const telemetry = new TelemetryHelper()
40+
return {
41+
setup: async () => {
42+
return await createTestWorkspace(numFiles, {
43+
fileNamePrefix: 'file',
44+
fileContent: getRandomString(fileSize),
45+
fileNameSuffix: '.md',
46+
})
47+
},
48+
execute: async (workspace: WorkspaceFolder) => {
49+
return await prepareRepoData([workspace.uri.fsPath], [workspace], telemetry, {
50+
record: () => {},
51+
} as unknown as Metric<AmazonqCreateUpload>)
52+
},
53+
verify: async (_w: WorkspaceFolder, result: resultType) => {
54+
verifyResult(result, telemetry, numFiles * fileSize)
55+
},
56+
}
57+
}
58+
)
59+
}
60+
61+
function verifyResult(result: resultType, telemetry: TelemetryHelper, expectedSize: number): void {
62+
assert.ok(result)
63+
assert.strictEqual(Buffer.isBuffer(result.zipFileBuffer), true)
64+
assert.strictEqual(telemetry.repositorySize, expectedSize)
65+
assert.strictEqual(result.zipFileChecksum.length, 44)
66+
}
67+
68+
describe('prepareRepoData', function () {
69+
describe('Performance Tests', function () {
70+
performanceTestWrapper(250, 10)
71+
performanceTestWrapper(10, 1000)
72+
})
73+
})

0 commit comments

Comments
 (0)