|
| 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 vscode from 'vscode' |
| 7 | +import { NewFileInfo, NewFileZipContents, registerNewFiles } from '../../amazonqFeatureDev' |
| 8 | +import { performanceTest } from '../../shared/performance/performance' |
| 9 | +import { getTestWorkspaceFolder } from '../integrationTestsUtilities' |
| 10 | +import { VirtualFileSystem } from '../../shared' |
| 11 | + |
| 12 | +interface SetupResult { |
| 13 | + workspace: vscode.WorkspaceFolder |
| 14 | + fileContents: NewFileZipContents[] |
| 15 | +} |
| 16 | + |
| 17 | +function getFileContents(numFiles: number, fileSize: number): NewFileZipContents[] { |
| 18 | + return Array.from({ length: numFiles }, (_, i) => { |
| 19 | + return { |
| 20 | + zipFilePath: `test-path-${i}`, |
| 21 | + fileContent: 'x'.repeat(fileSize), |
| 22 | + } |
| 23 | + }) |
| 24 | +} |
| 25 | + |
| 26 | +function performanceTestWrapper(label: string, numFiles: number, fileSize: number) { |
| 27 | + const conversationId = 'test-conversation' |
| 28 | + return performanceTest( |
| 29 | + { |
| 30 | + testRuns: 10, |
| 31 | + linux: { |
| 32 | + userCpuUsage: 200, |
| 33 | + systemCpuUsage: 35, |
| 34 | + heapTotal: 8, |
| 35 | + }, |
| 36 | + darwin: { |
| 37 | + userCpuUsage: 200, |
| 38 | + systemCpuUsage: 35, |
| 39 | + heapTotal: 8, |
| 40 | + }, |
| 41 | + win32: { |
| 42 | + userCpuUsage: 200, |
| 43 | + systemCpuUsage: 35, |
| 44 | + heapTotal: 8, |
| 45 | + }, |
| 46 | + }, |
| 47 | + label, |
| 48 | + function () { |
| 49 | + return { |
| 50 | + setup: async () => { |
| 51 | + const testWorkspaceUri = vscode.Uri.file(getTestWorkspaceFolder()) |
| 52 | + const fileContents = getFileContents(numFiles, fileSize) |
| 53 | + return { |
| 54 | + workspace: { |
| 55 | + uri: testWorkspaceUri, |
| 56 | + name: 'test-workspace', |
| 57 | + index: 0, |
| 58 | + }, |
| 59 | + fileContents: fileContents, |
| 60 | + } |
| 61 | + }, |
| 62 | + execute: async (setup: SetupResult) => { |
| 63 | + return registerNewFiles( |
| 64 | + new VirtualFileSystem(), |
| 65 | + setup.fileContents, |
| 66 | + 'test-upload-id', |
| 67 | + [setup.workspace], |
| 68 | + conversationId |
| 69 | + ) |
| 70 | + }, |
| 71 | + verify: async (_setup: SetupResult, result: NewFileInfo[]) => { |
| 72 | + assert.strictEqual(result.length, numFiles) |
| 73 | + }, |
| 74 | + } |
| 75 | + } |
| 76 | + ) |
| 77 | +} |
| 78 | + |
| 79 | +describe('registerNewFiles', function () { |
| 80 | + describe('performance tests', function () { |
| 81 | + performanceTestWrapper('1x10MB', 1, 10000) |
| 82 | + performanceTestWrapper('10x1000B', 10, 1000) |
| 83 | + performanceTestWrapper('100x100B', 100, 100) |
| 84 | + performanceTestWrapper('1000x10B', 1000, 10) |
| 85 | + performanceTestWrapper('10000x1B', 10000, 1) |
| 86 | + }) |
| 87 | +}) |
0 commit comments