Skip to content

Commit 74dc701

Browse files
committed
Merge branch 'master' into pTests/systemSpy
2 parents efe25af + 58a2b18 commit 74dc701

File tree

2 files changed

+159
-0
lines changed

2 files changed

+159
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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 { ExportResultArchiveCommandInput } from '@amzn/codewhisperer-streaming'
8+
import * as sinon from 'sinon'
9+
import path from 'path'
10+
import { fs, getRandomString } from '../../shared'
11+
import { createTestWorkspace } from '../../test/testUtil'
12+
import { performanceTest } from '../../shared/performance/performance'
13+
import { downloadExportResultArchive } from '../../shared/utilities/download'
14+
15+
interface SetupResult {
16+
workspace: WorkspaceFolder
17+
exportCommandInput: ExportResultArchiveCommandInput
18+
writeFileStub: sinon.SinonStub
19+
cwStreaming: any
20+
}
21+
22+
interface FakeCommandOutput {
23+
body: { binaryPayloadEvent: { bytes: Buffer } }[]
24+
}
25+
26+
function generateCommandOutput(numPieces: number, pieceSize: number): FakeCommandOutput {
27+
const body = Array.from({ length: numPieces }, (_, i) => {
28+
return {
29+
binaryPayloadEvent: {
30+
bytes: Buffer.from(getRandomString(pieceSize)),
31+
},
32+
}
33+
})
34+
return { body }
35+
}
36+
37+
async function setup(pieces: number, pieceSize: number): Promise<SetupResult> {
38+
// Force VSCode to find test workspace only to keep test contained and controlled.
39+
const workspace = await createTestWorkspace(1, {})
40+
const exportCommandInput = {} as ExportResultArchiveCommandInput
41+
// Manutally stub the CodeWhispererStreaming to avoid constructor call.
42+
const cwStreaming = { exportResultArchive: () => generateCommandOutput(pieces, pieceSize) }
43+
44+
const writeFileStub = sinon.stub(fs, 'writeFile')
45+
return { workspace, exportCommandInput, writeFileStub, cwStreaming }
46+
}
47+
48+
function perfTest(pieces: number, pieceSize: number, label: string) {
49+
return performanceTest(
50+
{
51+
testRuns: 10,
52+
linux: {
53+
userCpuUsage: 200,
54+
systemCpuUsage: 35,
55+
heapTotal: 4,
56+
},
57+
darwin: {
58+
userCpuUsage: 200,
59+
systemCpuUsage: 35,
60+
heapTotal: 4,
61+
},
62+
win32: {
63+
userCpuUsage: 200,
64+
systemCpuUsage: 35,
65+
heapTotal: 4,
66+
},
67+
},
68+
label,
69+
function () {
70+
return {
71+
setup: async () => await setup(pieces, pieceSize),
72+
execute: async ({ workspace, cwStreaming, exportCommandInput, writeFileStub }: SetupResult) => {
73+
await downloadExportResultArchive(
74+
cwStreaming,
75+
exportCommandInput,
76+
path.join(workspace.uri.fsPath, 'result')
77+
)
78+
},
79+
verify: async (setup: SetupResult) => {
80+
assert.ok(setup.writeFileStub.calledOnce)
81+
assert.ok((setup.writeFileStub.firstCall.args[1] as Buffer).length === pieces * pieceSize)
82+
},
83+
}
84+
}
85+
)
86+
}
87+
88+
describe('downloadExportResultArchive', function () {
89+
describe('performanceTests', function () {
90+
afterEach(function () {
91+
sinon.restore()
92+
})
93+
perfTest(1, 1000, '1x1KB')
94+
perfTest(10, 100, '10x100B')
95+
perfTest(100, 10, '100x10B')
96+
perfTest(1000, 1, '1000x1B')
97+
})
98+
})
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 path from 'path'
7+
import { getTestWorkspaceFolder } from '../integrationTestsUtilities'
8+
import { fs, getRandomString } from '../../shared'
9+
import { LspController } from '../../amazonq'
10+
import { performanceTest } from '../../shared/performance/performance'
11+
12+
function performanceTestWrapper(label: string, fileSize: number) {
13+
return performanceTest(
14+
{
15+
testRuns: 1,
16+
linux: {
17+
userCpuUsage: 400,
18+
systemCpuUsage: 35,
19+
heapTotal: 4,
20+
},
21+
darwin: {
22+
userCpuUsage: 400,
23+
systemCpuUsage: 35,
24+
heapTotal: 4,
25+
},
26+
win32: {
27+
userCpuUsage: 400,
28+
systemCpuUsage: 35,
29+
heapTotal: 4,
30+
},
31+
},
32+
label,
33+
function () {
34+
return {
35+
setup: async () => {
36+
const workspace = getTestWorkspaceFolder()
37+
const fileContent = getRandomString(fileSize)
38+
const testFile = path.join(workspace, 'test-file')
39+
await fs.writeFile(testFile, fileContent)
40+
41+
return testFile
42+
},
43+
execute: async (testFile: string) => {
44+
return await LspController.instance.getFileSha384(testFile)
45+
},
46+
verify: async (_testFile: string, result: string) => {
47+
assert.strictEqual(result.length, 96)
48+
},
49+
}
50+
}
51+
)
52+
}
53+
54+
describe('getFileSha384', function () {
55+
describe('performance tests', function () {
56+
performanceTestWrapper('1MB', 1000)
57+
performanceTestWrapper('2MB', 2000)
58+
performanceTestWrapper('4MB', 4000)
59+
performanceTestWrapper('8MB', 8000)
60+
})
61+
})

0 commit comments

Comments
 (0)