From a7e092a65e8172c80a65ddd67560e492194ca3dc Mon Sep 17 00:00:00 2001 From: hkobew Date: Fri, 8 Nov 2024 15:58:02 -0500 Subject: [PATCH] increase timeout when on windows --- .../src/shared/sam/cli/samCliLocalInvoke.ts | 5 -- .../core/src/shared/sam/cli/samCliLocator.ts | 2 - .../core/src/shared/sam/cli/samCliSettings.ts | 3 - .../shared/sam/cli/samCliLocalInvoke.test.ts | 67 +++++++++++-------- 4 files changed, 38 insertions(+), 39 deletions(-) diff --git a/packages/core/src/shared/sam/cli/samCliLocalInvoke.ts b/packages/core/src/shared/sam/cli/samCliLocalInvoke.ts index af1f20e7e1d..1f7c975025d 100644 --- a/packages/core/src/shared/sam/cli/samCliLocalInvoke.ts +++ b/packages/core/src/shared/sam/cli/samCliLocalInvoke.ts @@ -232,12 +232,7 @@ export class SamCliLocalInvokeInvocation { public async execute(timeout?: Timeout): Promise { await this.validate() - const start = Date.now() const sam = await this.config.getOrDetectSamCli() - // eslint-disable-next-line aws-toolkits/no-console-log - console.log('getOrDetect took %O seconds', (Date.now() - start) / 1000) - // eslint-disable-next-line aws-toolkits/no-console-log - console.log('autodetect is %O', sam.autoDetected) if (!sam.path) { getLogger().warn('SAM CLI not found and not configured') } else if (sam.autoDetected) { diff --git a/packages/core/src/shared/sam/cli/samCliLocator.ts b/packages/core/src/shared/sam/cli/samCliLocator.ts index 7e09fc89d05..7db6c163db4 100644 --- a/packages/core/src/shared/sam/cli/samCliLocator.ts +++ b/packages/core/src/shared/sam/cli/samCliLocator.ts @@ -29,8 +29,6 @@ export class SamCliLocationProvider { public async getLocation(forceSearch?: boolean): Promise<{ path: string; version: string } | undefined> { const perflog = new PerfLog('samCliLocator: getLocation') const cachedLoc = forceSearch ? undefined : SamCliLocationProvider.cachedSamLocation - // eslint-disable-next-line aws-toolkits/no-console-log - console.log('cachedLoc is: %O', cachedLoc) // Avoid searching the system for `sam` (especially slow on Windows). if (cachedLoc && (await SamCliLocationProvider.isValidSamLocation(cachedLoc.path))) { diff --git a/packages/core/src/shared/sam/cli/samCliSettings.ts b/packages/core/src/shared/sam/cli/samCliSettings.ts index 66b587549a8..6978b8e8695 100644 --- a/packages/core/src/shared/sam/cli/samCliSettings.ts +++ b/packages/core/src/shared/sam/cli/samCliSettings.ts @@ -83,10 +83,7 @@ export class SamCliSettings extends fromExtensionManifest('aws.samcli', descript SamCliSettings.logIfChanged(`SAM CLI location (from settings): ${fromConfig}`) return { path: fromConfig, autoDetected: false } } - const start = Date.now() const fromSearch = await this.locationProvider.getLocation(forceSearch) - // eslint-disable-next-line aws-toolkits/no-console-log - console.log('getOrDetect took %O seconds', (Date.now() - start) / 1000) SamCliSettings.logIfChanged(`SAM CLI location (version: ${fromSearch?.version}): ${fromSearch?.path}`) return { path: fromSearch?.path, autoDetected: true } diff --git a/packages/core/src/test/shared/sam/cli/samCliLocalInvoke.test.ts b/packages/core/src/test/shared/sam/cli/samCliLocalInvoke.test.ts index c9379fbb15e..19d31ac60a4 100644 --- a/packages/core/src/test/shared/sam/cli/samCliLocalInvoke.test.ts +++ b/packages/core/src/test/shared/sam/cli/samCliLocalInvoke.test.ts @@ -14,8 +14,11 @@ import { import { ChildProcess } from '../../../../shared/utilities/processUtils' import { assertArgIsPresent, assertArgNotPresent, assertArgsContainArgument } from './samCliTestUtils' import { fs } from '../../../../shared' - -describe('SamCliLocalInvokeInvocation', async function () { +import { isWin } from '../../../../shared/vscode/env' +import Sinon from 'sinon' +import { SamCliLocationProvider } from '../../../../shared/sam/cli/samCliLocator' +// eslint-disable-next-line aws-toolkits/no-only-in-tests +describe.only('SamCliLocalInvokeInvocation', async function () { class TestSamLocalInvokeCommand implements SamLocalInvokeCommand { public constructor(private readonly onInvoke: ({ ...params }: SamLocalInvokeCommandArgs) => void) {} @@ -41,34 +44,40 @@ describe('SamCliLocalInvokeInvocation', async function () { afterEach(async function () { await fs.delete(tempFolder, { recursive: true }) }) - - it('invokes `sam local` with args', async function () { - const taskInvoker: SamLocalInvokeCommand = new TestSamLocalInvokeCommand( - (invokeArgs: SamLocalInvokeCommandArgs) => { - assert.ok(invokeArgs.args.length >= 2, 'Expected args to be present') - assert.strictEqual(invokeArgs.args[0], 'local') - assert.strictEqual(invokeArgs.args[1], 'invoke') - // --debug is present because tests run with "debug" log-level. #1403 - assert.strictEqual(invokeArgs.args[2], '--debug') - assert.strictEqual(invokeArgs.args[4], '--template') - assert.strictEqual(invokeArgs.args[6], '--event') - assert.strictEqual(invokeArgs.args[8], '--env-vars') - - // `extraArgs` are appended to the end. - assert.strictEqual(invokeArgs.args[10], '--build-dir') - assert.strictEqual(invokeArgs.args[11], 'my/build/dir/') + for (const _ of Array.from({ length: 1000 }, (i) => i)) { + // eslint-disable-next-line aws-toolkits/no-only-in-tests + it.only('invokes `sam local` with args', async function () { + if (isWin()) { + // TODO: insert 'C:\\Program Files\\Amazon\\AWSSAMCLI\\bin\\sam.cmd' into the cache. + this.timeout(45000) } - ) - - await new SamCliLocalInvokeInvocation({ - templateResourceName: nonRelevantArg, - templatePath: placeholderTemplateFile, - eventPath: placeholderEventFile, - environmentVariablePath: nonRelevantArg, - invoker: taskInvoker, - extraArgs: ['--build-dir', 'my/build/dir/'], - }).execute() - }) + const taskInvoker: SamLocalInvokeCommand = new TestSamLocalInvokeCommand( + (invokeArgs: SamLocalInvokeCommandArgs) => { + assert.ok(invokeArgs.args.length >= 2, 'Expected args to be present') + assert.strictEqual(invokeArgs.args[0], 'local') + assert.strictEqual(invokeArgs.args[1], 'invoke') + // --debug is present because tests run with "debug" log-level. #1403 + assert.strictEqual(invokeArgs.args[2], '--debug') + assert.strictEqual(invokeArgs.args[4], '--template') + assert.strictEqual(invokeArgs.args[6], '--event') + assert.strictEqual(invokeArgs.args[8], '--env-vars') + + // `extraArgs` are appended to the end. + assert.strictEqual(invokeArgs.args[10], '--build-dir') + assert.strictEqual(invokeArgs.args[11], 'my/build/dir/') + } + ) + + await new SamCliLocalInvokeInvocation({ + templateResourceName: nonRelevantArg, + templatePath: placeholderTemplateFile, + eventPath: placeholderEventFile, + environmentVariablePath: nonRelevantArg, + invoker: taskInvoker, + extraArgs: ['--build-dir', 'my/build/dir/'], + }).execute() + }) + } it('Passes template resource name to sam cli', async function () { const expectedResourceName = 'HelloWorldResource'