-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(amazonq): implement performance test for downloadExportResultArc…
…hieve. (#5710) ## Problem Continuation of work here: #5670 ## Solution In this case `downloadExportResultArchieve` is reading a large collection of objects into a buffer, then writing that buffer to a file. We test this with varying collections of objects. We test 1x1KB, 10x100B, 100x10B, and 1000x1B. --- <!--- 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.
- Loading branch information
1 parent
e5b5545
commit 58a2b18
Showing
1 changed file
with
98 additions
and
0 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
packages/core/src/testInteg/perf/downloadExportResultArchive.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/*! | ||
* 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 { ExportResultArchiveCommandInput } from '@amzn/codewhisperer-streaming' | ||
import * as sinon from 'sinon' | ||
import path from 'path' | ||
import { fs, getRandomString } from '../../shared' | ||
import { createTestWorkspace } from '../../test/testUtil' | ||
import { performanceTest } from '../../shared/performance/performance' | ||
import { downloadExportResultArchive } from '../../shared/utilities/download' | ||
|
||
interface SetupResult { | ||
workspace: WorkspaceFolder | ||
exportCommandInput: ExportResultArchiveCommandInput | ||
writeFileStub: sinon.SinonStub | ||
cwStreaming: any | ||
} | ||
|
||
interface FakeCommandOutput { | ||
body: { binaryPayloadEvent: { bytes: Buffer } }[] | ||
} | ||
|
||
function generateCommandOutput(numPieces: number, pieceSize: number): FakeCommandOutput { | ||
const body = Array.from({ length: numPieces }, (_, i) => { | ||
return { | ||
binaryPayloadEvent: { | ||
bytes: Buffer.from(getRandomString(pieceSize)), | ||
}, | ||
} | ||
}) | ||
return { body } | ||
} | ||
|
||
async function setup(pieces: number, pieceSize: number): Promise<SetupResult> { | ||
// Force VSCode to find test workspace only to keep test contained and controlled. | ||
const workspace = await createTestWorkspace(1, {}) | ||
const exportCommandInput = {} as ExportResultArchiveCommandInput | ||
// Manutally stub the CodeWhispererStreaming to avoid constructor call. | ||
const cwStreaming = { exportResultArchive: () => generateCommandOutput(pieces, pieceSize) } | ||
|
||
const writeFileStub = sinon.stub(fs, 'writeFile') | ||
return { workspace, exportCommandInput, writeFileStub, cwStreaming } | ||
} | ||
|
||
function perfTest(pieces: number, pieceSize: number, label: string) { | ||
return performanceTest( | ||
{ | ||
testRuns: 10, | ||
linux: { | ||
userCpuUsage: 200, | ||
systemCpuUsage: 35, | ||
heapTotal: 4, | ||
}, | ||
darwin: { | ||
userCpuUsage: 200, | ||
systemCpuUsage: 35, | ||
heapTotal: 4, | ||
}, | ||
win32: { | ||
userCpuUsage: 200, | ||
systemCpuUsage: 35, | ||
heapTotal: 4, | ||
}, | ||
}, | ||
label, | ||
function () { | ||
return { | ||
setup: async () => await setup(pieces, pieceSize), | ||
execute: async ({ workspace, cwStreaming, exportCommandInput, writeFileStub }: SetupResult) => { | ||
await downloadExportResultArchive( | ||
cwStreaming, | ||
exportCommandInput, | ||
path.join(workspace.uri.fsPath, 'result') | ||
) | ||
}, | ||
verify: async (setup: SetupResult) => { | ||
assert.ok(setup.writeFileStub.calledOnce) | ||
assert.ok((setup.writeFileStub.firstCall.args[1] as Buffer).length === pieces * pieceSize) | ||
}, | ||
} | ||
} | ||
) | ||
} | ||
|
||
describe('downloadExportResultArchive', function () { | ||
describe('performanceTests', function () { | ||
afterEach(function () { | ||
sinon.restore() | ||
}) | ||
perfTest(1, 1000, '1x1KB') | ||
perfTest(10, 100, '10x100B') | ||
perfTest(100, 10, '100x10B') | ||
perfTest(1000, 1, '1000x1B') | ||
}) | ||
}) |