Skip to content
110 changes: 110 additions & 0 deletions packages/core/src/test/amazonqFeatureDev/prepareRepoData.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import assert from 'assert'
import { WorkspaceFolder } from 'vscode'
import { performanceTest } from '../../shared/performance/performance'
import { createTestWorkspace } from '../testUtil'
import { prepareRepoData, TelemetryHelper } from '../../amazonqFeatureDev'
import { AmazonqCreateUpload, getRandomString, Metric } from '../../shared'

type resultType = {
zipFileBuffer: Buffer
zipFileChecksum: string
}

describe('prepareRepoDataPerformanceTest', function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably just have a top level describe thats prepareRepoData and then a second describe that has performance test in it, that way it can easily seperate perf tests from non perf tests if anyone wants to add it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are also some existing correctness tests in test/unit/amazonqFeatureDev/util/files.test.ts. I kept the performance tests in core since thats where the startSecurityScan is (src/test/codewhisperer/commands/startSecurityScan.test.ts).

function verifyResult(result: resultType, telemetry: TelemetryHelper, expectedSize: number): void {
assert.ok(result)
assert.strictEqual(Buffer.isBuffer(result.zipFileBuffer), true)
assert.strictEqual(telemetry.repositorySize, expectedSize)
assert.strictEqual(result.zipFileChecksum.length, 44)
}
/**
* Tests 250 files w/ 10 bytes each.
* Running more files can lead to flaky test from timeout.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would there be any value on seeing how this number scales? e.g. for every 50 files it roughly increases the duration by 2 or is it too unpredictable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duration in general was very flaky on this one, and also it seemed to not scale linearly. I would be surprised based on what I've seen so far if an increase of 50 files corresponded so some constant duration increase. I could look into it with less files.

*/
performanceTest(
{
testRuns: 10,
linux: {
userCpuUsage: 90,
systemCpuUsage: 35,
heapTotal: 4,
},
darwin: {
userCpuUsage: 90,
systemCpuUsage: 35,
heapTotal: 4,
},
win32: {
userCpuUsage: 90,
systemCpuUsage: 35,
heapTotal: 4,
},
},
'handles many files',
function () {
const telemetry = new TelemetryHelper()
return {
setup: async () => {
return await createTestWorkspace(250, {
fileNamePrefix: 'file',
fileContent: '0123456789',
fileNameSuffix: '.md',
})
},
execute: async (workspace: WorkspaceFolder) => {
return await prepareRepoData([workspace.uri.fsPath], [workspace], telemetry, {
record: () => {},
} as unknown as Metric<AmazonqCreateUpload>)
},
verify: async (_w: WorkspaceFolder, result: resultType) => verifyResult(result, telemetry, 2500),
}
}
)
/**
* Runs 10 files of size 1000 bytes.
*/
performanceTest(
{
testRuns: 10,
linux: {
userCpuUsage: 65,
systemCpuUsage: 30,
heapTotal: 1,
},
darwin: {
userCpuUsage: 50,
systemCpuUsage: 25,
heapTotal: 1,
},
win32: {
userCpuUsage: 60,
systemCpuUsage: 30,
heapTotal: 1,
},
},

'handles large files',
function () {
const telemetry = new TelemetryHelper()
return {
setup: async () => {
return await createTestWorkspace(10, {
fileNamePrefix: 'file',
fileContent: getRandomString(1000),
fileNameSuffix: '.md',
})
},
execute: async (workspace: WorkspaceFolder) => {
return await prepareRepoData([workspace.uri.fsPath], [workspace], telemetry, {
record: () => {},
} as unknown as Metric<AmazonqCreateUpload>)
},
verify: async (_w: WorkspaceFolder, result: resultType) => verifyResult(result, telemetry, 10000),
}
}
)
})