|
| 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 * as sinon from 'sinon' |
| 7 | +import { TransformByQState, ZipManifest } from '../codewhisperer' |
| 8 | +import { fs, getRandomString, globals } from '../shared' |
| 9 | +import { createTestWorkspace } from '../test/testUtil' |
| 10 | +import * as CodeWhispererConstants from '../codewhisperer/models/constants' |
| 11 | +import { performanceTest } from '../shared/performance/performance' |
| 12 | +import { zipCode } from '../codewhisperer/indexNode' |
| 13 | + |
| 14 | +interface SetupResult { |
| 15 | + tempDir: string |
| 16 | + tempFileName: string |
| 17 | + transformQManifest: ZipManifest |
| 18 | + writeSpy: sinon.SinonSpy |
| 19 | +} |
| 20 | + |
| 21 | +async function setup(numberOfFiles: number, fileSize: number): Promise<SetupResult> { |
| 22 | + const transformByQState: TransformByQState = new TransformByQState() |
| 23 | + const tempFileName = `testfile-${globals.clock.Date.now()}.zip` |
| 24 | + const tempDir = ( |
| 25 | + await createTestWorkspace(numberOfFiles, { |
| 26 | + fileNamePrefix: 'file', |
| 27 | + fileContent: getRandomString(fileSize), |
| 28 | + fileNameSuffix: '.md', |
| 29 | + }) |
| 30 | + ).uri.fsPath |
| 31 | + const writeSpy = sinon.spy(fs, 'writeFile') |
| 32 | + const transformQManifest = new ZipManifest() |
| 33 | + transformByQState.setProjectPath(tempDir) |
| 34 | + transformQManifest.customBuildCommand = CodeWhispererConstants.skipUnitTestsBuildCommand |
| 35 | + return { tempDir, tempFileName, transformQManifest, writeSpy } |
| 36 | +} |
| 37 | + |
| 38 | +function performanceTestWrapper(numberOfFiles: number, fileSize: number) { |
| 39 | + return performanceTest( |
| 40 | + { |
| 41 | + testRuns: 10, |
| 42 | + linux: { |
| 43 | + userCpuUsage: 120, |
| 44 | + systemCpuUsage: 50, |
| 45 | + heapTotal: 4, |
| 46 | + }, |
| 47 | + darwin: { |
| 48 | + userCpuUsage: 120, |
| 49 | + systemCpuUsage: 50, |
| 50 | + heapTotal: 4, |
| 51 | + }, |
| 52 | + win32: { |
| 53 | + userCpuUsage: 120, |
| 54 | + systemCpuUsage: 50, |
| 55 | + heapTotal: 4, |
| 56 | + }, |
| 57 | + }, |
| 58 | + 'zipCode', |
| 59 | + function () { |
| 60 | + return { |
| 61 | + setup: async () => await setup(numberOfFiles, fileSize), |
| 62 | + execute: async ({ tempDir, tempFileName, transformQManifest, writeSpy }: SetupResult) => { |
| 63 | + await zipCode({ |
| 64 | + dependenciesFolder: { |
| 65 | + path: tempDir, |
| 66 | + name: tempFileName, |
| 67 | + }, |
| 68 | + humanInTheLoopFlag: false, |
| 69 | + modulePath: tempDir, |
| 70 | + zipManifest: transformQManifest, |
| 71 | + }) |
| 72 | + }, |
| 73 | + verify: async (setup: SetupResult) => { |
| 74 | + assert.ok( |
| 75 | + setup.writeSpy.args.find((arg) => { |
| 76 | + return arg[0].endsWith('.zip') |
| 77 | + }) |
| 78 | + ) |
| 79 | + }, |
| 80 | + } |
| 81 | + } |
| 82 | + ) |
| 83 | +} |
| 84 | + |
| 85 | +describe('zipCode', function () { |
| 86 | + describe('performance tests', function () { |
| 87 | + afterEach(function () { |
| 88 | + sinon.restore() |
| 89 | + }) |
| 90 | + performanceTestWrapper(250, 10) |
| 91 | + performanceTestWrapper(10, 1000) |
| 92 | + }) |
| 93 | +}) |
0 commit comments