From 0905fa9ebd4c3a8dfecd971d9f7c9f5902a8d6c9 Mon Sep 17 00:00:00 2001 From: hkobew Date: Thu, 26 Sep 2024 14:15:22 -0400 Subject: [PATCH 01/13] implement test, remove fs-extra --- .../core/src/amazonq/lsp/lspController.ts | 28 +++---- .../test/amazonq/common/tryInstallLsp.test.ts | 81 +++++++++++++++++++ 2 files changed, 95 insertions(+), 14 deletions(-) create mode 100644 packages/core/src/test/amazonq/common/tryInstallLsp.test.ts diff --git a/packages/core/src/amazonq/lsp/lspController.ts b/packages/core/src/amazonq/lsp/lspController.ts index 966eee8190e..411dbe6057b 100644 --- a/packages/core/src/amazonq/lsp/lspController.ts +++ b/packages/core/src/amazonq/lsp/lspController.ts @@ -5,8 +5,8 @@ import * as vscode from 'vscode' import * as path from 'path' -import * as fs from 'fs-extra' import * as crypto from 'crypto' +import { chmodSync, createWriteStream } from 'fs' import { getLogger } from '../../shared/logger/logger' import { CurrentWsFolders, collectFilesForIndex } from '../../shared/utilities/workspaceUtils' import fetch from 'node-fetch' @@ -19,7 +19,7 @@ import { CodeWhispererSettings } from '../../codewhisperer/util/codewhispererSet import { activate as activateLsp } from './lspClient' import { telemetry } from '../../shared/telemetry' import { isCloud9 } from '../../shared/extensionUtilities' -import { globals, ToolkitError } from '../../shared' +import { fs, globals, ToolkitError } from '../../shared' import { AuthUtil } from '../../codewhisperer' import { isWeb } from '../../shared/extensionGlobals' import { getUserAgent } from '../../shared/telemetry/util' @@ -105,7 +105,7 @@ export class LspController { throw new ToolkitError(`Failed to download. Error: ${JSON.stringify(res)}`) } return new Promise((resolve, reject) => { - const file = fs.createWriteStream(localFile) + const file = createWriteStream(localFile) res.body.pipe(file) res.body.on('error', (err) => { reject(err) @@ -133,16 +133,16 @@ export class LspController { } async getFileSha384(filePath: string): Promise { - const fileBuffer = await fs.promises.readFile(filePath) + const fileBuffer = await fs.readFile(filePath) const hash = crypto.createHash('sha384') hash.update(fileBuffer) return hash.digest('hex') } - isLspInstalled(context: vscode.ExtensionContext) { + async isLspInstalled(context: vscode.ExtensionContext) { const localQServer = context.asAbsolutePath(path.join('resources', 'qserver')) const localNodeRuntime = context.asAbsolutePath(path.join('resources', nodeBinName)) - return fs.existsSync(localQServer) && fs.existsSync(localNodeRuntime) + return (await fs.exists(localQServer)) && (await fs.exists(localNodeRuntime)) } getQserverFromManifest(manifest: Manifest): Content | undefined { @@ -207,7 +207,7 @@ export class LspController { getLogger().error( `LspController: Downloaded file sha ${sha384} does not match manifest ${content.hashes[0]}.` ) - fs.removeSync(filePath) + await fs.delete(filePath) return false } return true @@ -225,19 +225,19 @@ export class LspController { async tryInstallLsp(context: vscode.ExtensionContext): Promise { let tempFolder = undefined try { - if (this.isLspInstalled(context)) { + if (await this.isLspInstalled(context)) { getLogger().info(`LspController: LSP already installed`) return true } // clean up previous downloaded LSP const qserverPath = context.asAbsolutePath(path.join('resources', 'qserver')) - if (fs.existsSync(qserverPath)) { + if (await fs.exists(qserverPath)) { await tryRemoveFolder(qserverPath) } // clean up previous downloaded node runtime const nodeRuntimePath = context.asAbsolutePath(path.join('resources', nodeBinName)) - if (fs.existsSync(nodeRuntimePath)) { - fs.rmSync(nodeRuntimePath) + if (await fs.exists(nodeRuntimePath)) { + await fs.delete(nodeRuntimePath) } // fetch download url for qserver and node runtime const manifest: Manifest = (await this.fetchManifest()) as Manifest @@ -258,7 +258,7 @@ export class LspController { } const zip = new AdmZip(qserverZipTempPath) zip.extractAllTo(tempFolder) - fs.moveSync(path.join(tempFolder, 'qserver'), qserverPath) + await fs.rename(path.join(tempFolder, 'qserver'), qserverPath) // download node runtime to temp folder const nodeRuntimeTempPath = path.join(tempFolder, nodeBinName) @@ -266,8 +266,8 @@ export class LspController { if (!downloadNodeOk) { return false } - fs.chmodSync(nodeRuntimeTempPath, 0o755) - fs.moveSync(nodeRuntimeTempPath, nodeRuntimePath) + chmodSync(nodeRuntimeTempPath, 0o755) + await fs.rename(nodeRuntimeTempPath, nodeRuntimePath) return true } catch (e) { getLogger().error(`LspController: Failed to setup LSP server ${e}`) diff --git a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts new file mode 100644 index 00000000000..ef524595301 --- /dev/null +++ b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts @@ -0,0 +1,81 @@ +/*! + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +import assert from 'assert' +import { performanceTest } from '../../../shared/performance/performance' +import { LspController } from '../../../amazonq' +import { fs, globals } from '../../../shared' +import sinon from 'sinon' +import { Content } from 'aws-sdk/clients/codecommit' +import { createTestWorkspace } from '../../testUtil' +import AdmZip from 'adm-zip' +import path from 'path' + +// fakeFileContent is matched to fakeQServerContent based on hash. +const fakeHash = '4eb2865c8f40a322aa04e17d8d83bdaa605d6f1cb363af615240a5442a010e0aef66e21bcf4c88f20fabff06efe8a214' + +const fakeQServerContent = { + filename: 'qserver-fake.zip', + url: 'https://aws-language-servers/fake.zip', + hashes: [`sha384:${fakeHash}`], + bytes: 93610849, + serverVersion: '1.1.1', +} + +const fakeNodeContent = { + filename: 'fake-file', + url: 'https://aws-language-servers.fake-file', + hashes: [`sha384:${fakeHash}`], + bytes: 94144448, + serverVersion: '1.1.1', +} + +/** + * Creates a fake zip with some files in it. + * @param filepath where to write the zip to. + * @param _content unused parameter, for compatability with real function. + */ +const fakeDownload = async (filepath: string, _content: Content) => { + const dummyFilesPath = ( + await createTestWorkspace(100, { + fileNamePrefix: 'fakeFile', + fileContent: 'emptyContent', + workspaceName: 'workspace', + }) + ).uri.fsPath + await fs.writeFile(path.join(dummyFilesPath, 'qserver'), 'this value shouldnt matter') + const zip = new AdmZip() + zip.addLocalFolder(dummyFilesPath) + zip.writeZip(filepath) +} + +describe('tryInstallLsp performance test', function () { + afterEach(function () { + sinon.restore() + }) + + performanceTest({}, 'sets up', function () { + return { + setup: async () => { + // Avoid making HTTP request or mocking giant manifest, stub what we need directly from request. + sinon.stub(LspController.prototype, 'fetchManifest') + // Directly feed the runtime specifications. + sinon.stub(LspController.prototype, 'getQserverFromManifest').returns(fakeQServerContent) + sinon.stub(LspController.prototype, 'getNodeRuntimeFromManifest').returns(fakeNodeContent) + // avoid fetch call. + sinon.stub(LspController.prototype, '_download').callsFake(fakeDownload) + // Hard code the hash since we are creating files on the spot, whose hashes can't be predicted. + sinon.stub(LspController.prototype, 'getFileSha384').resolves(fakeHash) + // Don't allow tryInstallLsp to move runtimes out of temporary folder. + sinon.stub(fs, 'rename') + }, + execute: async () => { + return await LspController.instance.tryInstallLsp(globals.context) + }, + verify: async (setup: any, result: boolean) => { + assert.ok(result) + }, + } + }) +}) From f52947b8e345cffe62df0dcc89b621c6c51ed52b Mon Sep 17 00:00:00 2001 From: hkobew Date: Thu, 26 Sep 2024 14:23:24 -0400 Subject: [PATCH 02/13] add another test case --- .../test/amazonq/common/tryInstallLsp.test.ts | 126 +++++++++++++----- 1 file changed, 94 insertions(+), 32 deletions(-) diff --git a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts index ef524595301..f036ed11a82 100644 --- a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts +++ b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts @@ -5,7 +5,7 @@ import assert from 'assert' import { performanceTest } from '../../../shared/performance/performance' import { LspController } from '../../../amazonq' -import { fs, globals } from '../../../shared' +import { fs, getRandomString, globals } from '../../../shared' import sinon from 'sinon' import { Content } from 'aws-sdk/clients/codecommit' import { createTestWorkspace } from '../../testUtil' @@ -31,23 +31,39 @@ const fakeNodeContent = { serverVersion: '1.1.1', } +function createStubs(numberOfFiles: number, fileSize: number) { + // Avoid making HTTP request or mocking giant manifest, stub what we need directly from request. + sinon.stub(LspController.prototype, 'fetchManifest') + // Directly feed the runtime specifications. + sinon.stub(LspController.prototype, 'getQserverFromManifest').returns(fakeQServerContent) + sinon.stub(LspController.prototype, 'getNodeRuntimeFromManifest').returns(fakeNodeContent) + // avoid fetch call. + sinon.stub(LspController.prototype, '_download').callsFake(getFakeDownload(numberOfFiles, fileSize)) + // Hard code the hash since we are creating files on the spot, whose hashes can't be predicted. + sinon.stub(LspController.prototype, 'getFileSha384').resolves(fakeHash) + // Don't allow tryInstallLsp to move runtimes out of temporary folder. + sinon.stub(fs, 'rename') +} + /** * Creates a fake zip with some files in it. * @param filepath where to write the zip to. * @param _content unused parameter, for compatability with real function. */ -const fakeDownload = async (filepath: string, _content: Content) => { - const dummyFilesPath = ( - await createTestWorkspace(100, { - fileNamePrefix: 'fakeFile', - fileContent: 'emptyContent', - workspaceName: 'workspace', - }) - ).uri.fsPath - await fs.writeFile(path.join(dummyFilesPath, 'qserver'), 'this value shouldnt matter') - const zip = new AdmZip() - zip.addLocalFolder(dummyFilesPath) - zip.writeZip(filepath) +const getFakeDownload = function (numberOfFiles: number, fileSize: number) { + return async function (filepath: string, _content: Content) { + const dummyFilesPath = ( + await createTestWorkspace(numberOfFiles, { + fileNamePrefix: 'fakeFile', + fileContent: getRandomString(fileSize), + workspaceName: 'workspace', + }) + ).uri.fsPath + await fs.writeFile(path.join(dummyFilesPath, 'qserver'), 'this value shouldnt matter') + const zip = new AdmZip() + zip.addLocalFolder(dummyFilesPath) + zip.writeZip(filepath) + } } describe('tryInstallLsp performance test', function () { @@ -55,27 +71,73 @@ describe('tryInstallLsp performance test', function () { sinon.restore() }) - performanceTest({}, 'sets up', function () { - return { - setup: async () => { - // Avoid making HTTP request or mocking giant manifest, stub what we need directly from request. - sinon.stub(LspController.prototype, 'fetchManifest') - // Directly feed the runtime specifications. - sinon.stub(LspController.prototype, 'getQserverFromManifest').returns(fakeQServerContent) - sinon.stub(LspController.prototype, 'getNodeRuntimeFromManifest').returns(fakeNodeContent) - // avoid fetch call. - sinon.stub(LspController.prototype, '_download').callsFake(fakeDownload) - // Hard code the hash since we are creating files on the spot, whose hashes can't be predicted. - sinon.stub(LspController.prototype, 'getFileSha384').resolves(fakeHash) - // Don't allow tryInstallLsp to move runtimes out of temporary folder. - sinon.stub(fs, 'rename') + performanceTest( + { + testRuns: 10, + linux: { + userCpuUsage: 90, + systemCpuUsage: 35, + heapTotal: 6, }, - execute: async () => { - return await LspController.instance.tryInstallLsp(globals.context) + darwin: { + userCpuUsage: 90, + systemCpuUsage: 35, + heapTotal: 6, }, - verify: async (setup: any, result: boolean) => { - assert.ok(result) + win32: { + userCpuUsage: 90, + systemCpuUsage: 35, + heapTotal: 6, }, + }, + 'many small files in zip', + function () { + return { + setup: async () => { + createStubs(250, 10) + }, + execute: async () => { + return await LspController.instance.tryInstallLsp(globals.context) + }, + verify: async (_setup: any, result: boolean) => { + assert.ok(result) + }, + } } - }) + ) + + performanceTest( + { + testRuns: 10, + linux: { + userCpuUsage: 90, + systemCpuUsage: 35, + heapTotal: 4, + }, + darwin: { + userCpuUsage: 90, + systemCpuUsage: 35, + heapTotal: 4, + }, + win32: { + userCpuUsage: 90, + systemCpuUsage: 35, + heapTotal: 4, + }, + }, + 'few large files in zip', + function () { + return { + setup: async () => { + createStubs(10, 1000) + }, + execute: async () => { + return await LspController.instance.tryInstallLsp(globals.context) + }, + verify: async (_setup: any, result: boolean) => { + assert.ok(result) + }, + } + } + ) }) From 60faa0cd7ca6452fa8ee5a18ac464dbe20a3e4f9 Mon Sep 17 00:00:00 2001 From: hkobew Date: Thu, 26 Sep 2024 14:24:47 -0400 Subject: [PATCH 03/13] add comments explaining the inputs --- .../core/src/test/amazonq/common/tryInstallLsp.test.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts index f036ed11a82..3df110cf7fa 100644 --- a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts +++ b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts @@ -70,7 +70,9 @@ describe('tryInstallLsp performance test', function () { afterEach(function () { sinon.restore() }) - + /** + * Test setting up LSP when fetched zip is many (250) small (10B) files. + */ performanceTest( { testRuns: 10, @@ -105,7 +107,9 @@ describe('tryInstallLsp performance test', function () { } } ) - + /** + * Test setting up LSP when fetched zip is few (10) large (1000B) files. + */ performanceTest( { testRuns: 10, From 4276229eeb5d3afbb80adc4387d1782e01529952 Mon Sep 17 00:00:00 2001 From: hkobew Date: Thu, 26 Sep 2024 14:51:10 -0400 Subject: [PATCH 04/13] update threshold --- packages/core/src/test/amazonq/common/tryInstallLsp.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts index 3df110cf7fa..4277d233af1 100644 --- a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts +++ b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts @@ -77,7 +77,7 @@ describe('tryInstallLsp performance test', function () { { testRuns: 10, linux: { - userCpuUsage: 90, + userCpuUsage: 110, systemCpuUsage: 35, heapTotal: 6, }, From 91a87d1291439361191255d7242dd8cc48b95b2a Mon Sep 17 00:00:00 2001 From: hkobew Date: Thu, 26 Sep 2024 15:56:24 -0400 Subject: [PATCH 05/13] adjust thresholds --- packages/core/src/test/amazonq/common/tryInstallLsp.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts index 4277d233af1..a604d74b5ca 100644 --- a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts +++ b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts @@ -85,6 +85,7 @@ describe('tryInstallLsp performance test', function () { userCpuUsage: 90, systemCpuUsage: 35, heapTotal: 6, + duration: 7, }, win32: { userCpuUsage: 90, From 4e1e9511eeba088f264b4134af1e5ee9ec0c0544 Mon Sep 17 00:00:00 2001 From: hkobew Date: Fri, 27 Sep 2024 11:14:04 -0400 Subject: [PATCH 06/13] add more breathing room for linux tests --- packages/core/src/test/amazonq/common/tryInstallLsp.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts index a604d74b5ca..a9fafa2fe36 100644 --- a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts +++ b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts @@ -80,6 +80,7 @@ describe('tryInstallLsp performance test', function () { userCpuUsage: 110, systemCpuUsage: 35, heapTotal: 6, + duration: 15, }, darwin: { userCpuUsage: 90, From 6840095535f7941aabf32731034be53deafb0941 Mon Sep 17 00:00:00 2001 From: hkobew Date: Fri, 27 Sep 2024 12:25:39 -0400 Subject: [PATCH 07/13] adjust thresholds --- packages/core/src/test/amazonq/common/tryInstallLsp.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts index a9fafa2fe36..858b702f930 100644 --- a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts +++ b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts @@ -86,12 +86,13 @@ describe('tryInstallLsp performance test', function () { userCpuUsage: 90, systemCpuUsage: 35, heapTotal: 6, - duration: 7, + duration: 15, }, win32: { userCpuUsage: 90, systemCpuUsage: 35, heapTotal: 6, + duration: 15, }, }, 'many small files in zip', From 6c1af557b4075188d3321e38074d9c45250b64f7 Mon Sep 17 00:00:00 2001 From: hkobew Date: Tue, 1 Oct 2024 15:55:06 -0400 Subject: [PATCH 08/13] nerf threshold --- packages/core/src/test/amazonq/common/tryInstallLsp.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts index 858b702f930..255435aec26 100644 --- a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts +++ b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts @@ -117,7 +117,7 @@ describe('tryInstallLsp performance test', function () { { testRuns: 10, linux: { - userCpuUsage: 90, + userCpuUsage: 95, systemCpuUsage: 35, heapTotal: 4, }, From 72d213754680e87f893bf4b506b17fe51babd4a5 Mon Sep 17 00:00:00 2001 From: hkobew Date: Wed, 2 Oct 2024 09:38:59 -0400 Subject: [PATCH 09/13] make thresholds more lenient --- .../test/amazonq/common/tryInstallLsp.test.ts | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts index 255435aec26..589fc8b0f49 100644 --- a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts +++ b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts @@ -77,21 +77,21 @@ describe('tryInstallLsp performance test', function () { { testRuns: 10, linux: { - userCpuUsage: 110, + userCpuUsage: 100, systemCpuUsage: 35, - heapTotal: 6, + heapTotal: 4, duration: 15, }, darwin: { - userCpuUsage: 90, + userCpuUsage: 100, systemCpuUsage: 35, - heapTotal: 6, + heapTotal: 4, duration: 15, }, win32: { - userCpuUsage: 90, + userCpuUsage: 100, systemCpuUsage: 35, - heapTotal: 6, + heapTotal: 4, duration: 15, }, }, @@ -117,18 +117,18 @@ describe('tryInstallLsp performance test', function () { { testRuns: 10, linux: { - userCpuUsage: 95, - systemCpuUsage: 35, + userCpuUsage: 100, + systemCpuUsage: 50, heapTotal: 4, }, darwin: { - userCpuUsage: 90, - systemCpuUsage: 35, + userCpuUsage: 100, + systemCpuUsage: 50, heapTotal: 4, }, win32: { - userCpuUsage: 90, - systemCpuUsage: 35, + userCpuUsage: 100, + systemCpuUsage: 50, heapTotal: 4, }, }, From f610941f7498527d6e208091602e45c90843c1ea Mon Sep 17 00:00:00 2001 From: hkobew Date: Wed, 2 Oct 2024 09:59:39 -0400 Subject: [PATCH 10/13] make thresholds more lenient --- .../src/test/amazonq/common/tryInstallLsp.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts index 589fc8b0f49..4dd94caa4c5 100644 --- a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts +++ b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts @@ -79,19 +79,19 @@ describe('tryInstallLsp performance test', function () { linux: { userCpuUsage: 100, systemCpuUsage: 35, - heapTotal: 4, + heapTotal: 6, duration: 15, }, darwin: { userCpuUsage: 100, systemCpuUsage: 35, - heapTotal: 4, + heapTotal: 6, duration: 15, }, win32: { userCpuUsage: 100, systemCpuUsage: 35, - heapTotal: 4, + heapTotal: 6, duration: 15, }, }, @@ -119,17 +119,17 @@ describe('tryInstallLsp performance test', function () { linux: { userCpuUsage: 100, systemCpuUsage: 50, - heapTotal: 4, + heapTotal: 6, }, darwin: { userCpuUsage: 100, systemCpuUsage: 50, - heapTotal: 4, + heapTotal: 6, }, win32: { userCpuUsage: 100, systemCpuUsage: 50, - heapTotal: 4, + heapTotal: 6, }, }, 'few large files in zip', From dc24f30b5fc19f2735a838db9ee45dceddacb76d Mon Sep 17 00:00:00 2001 From: hkobew Date: Wed, 2 Oct 2024 12:05:49 -0400 Subject: [PATCH 11/13] remove some code dupe --- .../test/amazonq/common/tryInstallLsp.test.ts | 59 ++++--------------- 1 file changed, 13 insertions(+), 46 deletions(-) diff --git a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts index 4dd94caa4c5..7ff3f558472 100644 --- a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts +++ b/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts @@ -66,14 +66,8 @@ const getFakeDownload = function (numberOfFiles: number, fileSize: number) { } } -describe('tryInstallLsp performance test', function () { - afterEach(function () { - sinon.restore() - }) - /** - * Test setting up LSP when fetched zip is many (250) small (10B) files. - */ - performanceTest( +function performanceTestWrapper(numFiles: number, fileSize: number) { + return performanceTest( { testRuns: 10, linux: { @@ -99,44 +93,7 @@ describe('tryInstallLsp performance test', function () { function () { return { setup: async () => { - createStubs(250, 10) - }, - execute: async () => { - return await LspController.instance.tryInstallLsp(globals.context) - }, - verify: async (_setup: any, result: boolean) => { - assert.ok(result) - }, - } - } - ) - /** - * Test setting up LSP when fetched zip is few (10) large (1000B) files. - */ - performanceTest( - { - testRuns: 10, - linux: { - userCpuUsage: 100, - systemCpuUsage: 50, - heapTotal: 6, - }, - darwin: { - userCpuUsage: 100, - systemCpuUsage: 50, - heapTotal: 6, - }, - win32: { - userCpuUsage: 100, - systemCpuUsage: 50, - heapTotal: 6, - }, - }, - 'few large files in zip', - function () { - return { - setup: async () => { - createStubs(10, 1000) + createStubs(numFiles, fileSize) }, execute: async () => { return await LspController.instance.tryInstallLsp(globals.context) @@ -147,4 +104,14 @@ describe('tryInstallLsp performance test', function () { } } ) +} + +describe('tryInstallLsp', function () { + afterEach(function () { + sinon.restore() + }) + describe('performance tests', function () { + performanceTestWrapper(250, 10) + performanceTestWrapper(10, 1000) + }) }) From 07c65a6fe453c8b485fa1b7a3c08b1e99c74da52 Mon Sep 17 00:00:00 2001 From: hkobew Date: Fri, 4 Oct 2024 13:06:08 -0400 Subject: [PATCH 12/13] move to integ --- .../src/{test/amazonq/common => testInteg}/tryInstallLsp.test.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/core/src/{test/amazonq/common => testInteg}/tryInstallLsp.test.ts (100%) diff --git a/packages/core/src/test/amazonq/common/tryInstallLsp.test.ts b/packages/core/src/testInteg/tryInstallLsp.test.ts similarity index 100% rename from packages/core/src/test/amazonq/common/tryInstallLsp.test.ts rename to packages/core/src/testInteg/tryInstallLsp.test.ts From eaa6da76937ee6ef98316d83a3c13c9217f23bf6 Mon Sep 17 00:00:00 2001 From: hkobew Date: Fri, 4 Oct 2024 13:16:21 -0400 Subject: [PATCH 13/13] fix imports --- packages/core/src/testInteg/tryInstallLsp.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/core/src/testInteg/tryInstallLsp.test.ts b/packages/core/src/testInteg/tryInstallLsp.test.ts index 7ff3f558472..9a5f8b808db 100644 --- a/packages/core/src/testInteg/tryInstallLsp.test.ts +++ b/packages/core/src/testInteg/tryInstallLsp.test.ts @@ -3,14 +3,14 @@ * SPDX-License-Identifier: Apache-2.0 */ import assert from 'assert' -import { performanceTest } from '../../../shared/performance/performance' -import { LspController } from '../../../amazonq' -import { fs, getRandomString, globals } from '../../../shared' import sinon from 'sinon' import { Content } from 'aws-sdk/clients/codecommit' -import { createTestWorkspace } from '../../testUtil' import AdmZip from 'adm-zip' import path from 'path' +import { LspController } from '../amazonq' +import { fs, getRandomString, globals } from '../shared' +import { createTestWorkspace } from '../test/testUtil' +import { performanceTest } from '../shared/performance/performance' // fakeFileContent is matched to fakeQServerContent based on hash. const fakeHash = '4eb2865c8f40a322aa04e17d8d83bdaa605d6f1cb363af615240a5442a010e0aef66e21bcf4c88f20fabff06efe8a214'