From 01441c57ba62748b18cb1f539ddc3933ab74accb Mon Sep 17 00:00:00 2001 From: Kamil Sobol Date: Tue, 3 Dec 2024 09:42:04 -0800 Subject: [PATCH] pr feedback --- .../hotswappable_resources.sandbox.test.ts | 4 -- .../test-e2e/sandbox/sandbox.test.template.ts | 8 ++- .../health_checks.test.ts | 26 ++------- .../README.md | 5 ++ .../function_code_hotswap.ts} | 53 +++++++++++-------- .../test-project-setup/test_project_base.ts | 2 +- .../hotswappable-resources/amplify/backend.ts | 4 -- .../amplify/data/resource.ts | 21 -------- .../amplify/test_factories.ts | 7 --- .../hotswap-update-files/data/resource.ts | 21 -------- .../README.md | 5 ++ .../function-code-hotswap/amplify/backend.ts | 4 ++ .../amplify/func-src/handler.ts | 0 .../amplify/function.ts | 0 .../hotswap-update-files/func-src/handler.ts | 0 15 files changed, 56 insertions(+), 104 deletions(-) delete mode 100644 packages/integration-tests/src/test-e2e/sandbox/hotswappable_resources.sandbox.test.ts create mode 100644 packages/integration-tests/src/test-project-setup/live-dependency-health-checks-projects/README.md rename packages/integration-tests/src/test-project-setup/{hotswappable_resources.ts => live-dependency-health-checks-projects/function_code_hotswap.ts} (69%) delete mode 100644 packages/integration-tests/src/test-projects/hotswappable-resources/amplify/backend.ts delete mode 100644 packages/integration-tests/src/test-projects/hotswappable-resources/amplify/data/resource.ts delete mode 100644 packages/integration-tests/src/test-projects/hotswappable-resources/amplify/test_factories.ts delete mode 100644 packages/integration-tests/src/test-projects/hotswappable-resources/hotswap-update-files/data/resource.ts create mode 100644 packages/integration-tests/src/test-projects/live-dependency-health-checks-projects/README.md create mode 100644 packages/integration-tests/src/test-projects/live-dependency-health-checks-projects/function-code-hotswap/amplify/backend.ts rename packages/integration-tests/src/test-projects/{hotswappable-resources => live-dependency-health-checks-projects/function-code-hotswap}/amplify/func-src/handler.ts (100%) rename packages/integration-tests/src/test-projects/{hotswappable-resources => live-dependency-health-checks-projects/function-code-hotswap}/amplify/function.ts (100%) rename packages/integration-tests/src/test-projects/{hotswappable-resources => live-dependency-health-checks-projects/function-code-hotswap}/hotswap-update-files/func-src/handler.ts (100%) diff --git a/packages/integration-tests/src/test-e2e/sandbox/hotswappable_resources.sandbox.test.ts b/packages/integration-tests/src/test-e2e/sandbox/hotswappable_resources.sandbox.test.ts deleted file mode 100644 index 24bfacb9d0..0000000000 --- a/packages/integration-tests/src/test-e2e/sandbox/hotswappable_resources.sandbox.test.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { HotswappableResourcesTestProjectCreator } from '../../test-project-setup/hotswappable_resources.js'; -import { defineSandboxTest } from './sandbox.test.template.js'; - -defineSandboxTest(new HotswappableResourcesTestProjectCreator()); diff --git a/packages/integration-tests/src/test-e2e/sandbox/sandbox.test.template.ts b/packages/integration-tests/src/test-e2e/sandbox/sandbox.test.template.ts index 6ebe01d113..2b348a068b 100644 --- a/packages/integration-tests/src/test-e2e/sandbox/sandbox.test.template.ts +++ b/packages/integration-tests/src/test-e2e/sandbox/sandbox.test.template.ts @@ -94,8 +94,12 @@ export const defineSandboxTest = (testProjectCreator: TestProjectCreator) => { for (const update of updates) { processController .do(replaceFiles(update.replacements)) - .do(waitForSandboxToHotswapResources()) - .do(ensureDeploymentTimeLessThan(update.deployThresholdSec)); + .do(waitForSandboxToHotswapResources()); + if (update.deployThresholdSec) { + processController.do( + ensureDeploymentTimeLessThan(update.deployThresholdSec) + ); + } } // Execute the process. diff --git a/packages/integration-tests/src/test-live-dependency-health-checks/health_checks.test.ts b/packages/integration-tests/src/test-live-dependency-health-checks/health_checks.test.ts index e778729a86..a902702971 100644 --- a/packages/integration-tests/src/test-live-dependency-health-checks/health_checks.test.ts +++ b/packages/integration-tests/src/test-live-dependency-health-checks/health_checks.test.ts @@ -21,7 +21,7 @@ import { import { BackendIdentifierConversions } from '@aws-amplify/platform-core'; import { e2eToolingClientConfig } from '../e2e_tooling_client_config.js'; import { amplifyAtTag } from '../constants.js'; -import { HotswappableResourcesTestProjectCreator } from '../test-project-setup/hotswappable_resources.js'; +import { FunctionCodeHotswapTestProjectCreator } from '../test-project-setup/live-dependency-health-checks-projects/function_code_hotswap.js'; import { BackendIdentifier } from '@aws-amplify/plugin-types'; const cfnClient = new CloudFormationClient(e2eToolingClientConfig); @@ -150,30 +150,10 @@ void describe('Live dependency health checks', { concurrency: true }, () => { await fs.rm(tempDir, { recursive: true }); }); - void it('can hotswap resources', async () => { - const projectCreator = new HotswappableResourcesTestProjectCreator(); + void it('can hotswap function code', async () => { + const projectCreator = new FunctionCodeHotswapTestProjectCreator(); const testProject = await projectCreator.createProject(tempDir); - // we're not starting from create flow. install latest versions of dependencies. - await execa( - 'npm', - [ - 'install', - '@aws-amplify/backend', - '@aws-amplify/backend-cli', - 'aws-cdk@^2', - 'aws-cdk-lib@^2', - 'constructs@^10.0.0', - 'typescript@^5.0.0', - 'tsx', - 'esbuild', - ], - { - cwd: tempDir, - stdio: 'inherit', - } - ); - const sandboxBackendIdentifier: BackendIdentifier = { type: 'sandbox', namespace: testProject.name, diff --git a/packages/integration-tests/src/test-project-setup/live-dependency-health-checks-projects/README.md b/packages/integration-tests/src/test-project-setup/live-dependency-health-checks-projects/README.md new file mode 100644 index 0000000000..03e8063453 --- /dev/null +++ b/packages/integration-tests/src/test-project-setup/live-dependency-health-checks-projects/README.md @@ -0,0 +1,5 @@ +Projects in this directory are meant for `live-dependency-health-checks` (aka canaries). + +1. These projects must not be used in e2e tests to provide deep functional coverage. +2. These projects must be lightweight to provide fast runtime and stability. +3. These projects must cover only P0 scenarios we care most. (That are not covered by "getting started" flow, aka `create-amplify`). diff --git a/packages/integration-tests/src/test-project-setup/hotswappable_resources.ts b/packages/integration-tests/src/test-project-setup/live-dependency-health-checks-projects/function_code_hotswap.ts similarity index 69% rename from packages/integration-tests/src/test-project-setup/hotswappable_resources.ts rename to packages/integration-tests/src/test-project-setup/live-dependency-health-checks-projects/function_code_hotswap.ts index bb2fe03223..7da4b3ffae 100644 --- a/packages/integration-tests/src/test-project-setup/hotswappable_resources.ts +++ b/packages/integration-tests/src/test-project-setup/live-dependency-health-checks-projects/function_code_hotswap.ts @@ -1,25 +1,21 @@ import fs from 'fs/promises'; -import { createEmptyAmplifyProject } from './create_empty_amplify_project.js'; +import { createEmptyAmplifyProject } from '../create_empty_amplify_project.js'; import { CloudFormationClient } from '@aws-sdk/client-cloudformation'; -import { TestProjectBase, TestProjectUpdate } from './test_project_base.js'; +import { TestProjectBase, TestProjectUpdate } from '../test_project_base.js'; import { fileURLToPath, pathToFileURL } from 'node:url'; import path from 'path'; -import { TestProjectCreator } from './test_project_creator.js'; +import { TestProjectCreator } from '../test_project_creator.js'; import { AmplifyClient } from '@aws-sdk/client-amplify'; -import { e2eToolingClientConfig } from '../e2e_tooling_client_config.js'; +import { e2eToolingClientConfig } from '../../e2e_tooling_client_config.js'; +import { execa } from 'execa'; /** - * Creates test projects with hotswappable resources. - * - * This project is used by canary tests. Its goal is to ensure that resources - * are hotswapped successfully. The priority of this test project is fast runtime. - * Therefore, assertions and resource mix is kept minimal and complex expansions - * to provide functional coverage should be avoided. + * Creates test projects with function hotswap. */ -export class HotswappableResourcesTestProjectCreator +export class FunctionCodeHotswapTestProjectCreator implements TestProjectCreator { - readonly name = 'hotswappable-resources'; + readonly name = 'function-code-hotswap'; /** * Creates project creator. @@ -37,7 +33,7 @@ export class HotswappableResourcesTestProjectCreator const { projectName, projectRoot, projectAmplifyDir } = await createEmptyAmplifyProject(this.name, e2eProjectDir); - const project = new HotswappableResourcesTestProject( + const project = new FunctionCodeHotswapTestTestProject( projectName, projectRoot, projectAmplifyDir, @@ -52,18 +48,38 @@ export class HotswappableResourcesTestProjectCreator } ); + // we're not starting from create flow. install latest versions of dependencies. + await execa( + 'npm', + [ + 'install', + '@aws-amplify/backend', + '@aws-amplify/backend-cli', + 'aws-cdk@^2', + 'aws-cdk-lib@^2', + 'constructs@^10.0.0', + 'typescript@^5.0.0', + 'tsx', + 'esbuild', + ], + { + cwd: projectRoot, + stdio: 'inherit', + } + ); + return project; }; } /** - * Test project with hotswappable resources. + * Test project with function hotswap. */ -class HotswappableResourcesTestProject extends TestProjectBase { +class FunctionCodeHotswapTestTestProject extends TestProjectBase { // Note that this is pointing to the non-compiled project directory // This allows us to test that we are able to deploy js, cjs, ts, etc. without compiling with tsc first readonly sourceProjectRootPath = - '../../src/test-projects/hotswappable-resources'; + '../../../src/test-projects/live-dependency-health-checks-projects/function-code-hotswap'; readonly sourceProjectRootURL: URL = new URL( this.sourceProjectRootPath, @@ -106,13 +122,8 @@ class HotswappableResourcesTestProject extends TestProjectBase { return [ { replacements: [ - this.getUpdateReplacementDefinition('data/resource.ts'), this.getUpdateReplacementDefinition('func-src/handler.ts'), ], - deployThresholdSec: { - onWindows: 50, - onOther: 40, - }, }, ]; } diff --git a/packages/integration-tests/src/test-project-setup/test_project_base.ts b/packages/integration-tests/src/test-project-setup/test_project_base.ts index 706d68114c..d1de5df76a 100644 --- a/packages/integration-tests/src/test-project-setup/test_project_base.ts +++ b/packages/integration-tests/src/test-project-setup/test_project_base.ts @@ -45,7 +45,7 @@ export type TestProjectUpdate = { * Windows has a separate threshold because it is consistently slower than other platforms * https://github.com/microsoft/Windows-Dev-Performance/issues/17 */ - deployThresholdSec: PlatformDeploymentThresholds; + deployThresholdSec?: PlatformDeploymentThresholds; }; /** diff --git a/packages/integration-tests/src/test-projects/hotswappable-resources/amplify/backend.ts b/packages/integration-tests/src/test-projects/hotswappable-resources/amplify/backend.ts deleted file mode 100644 index 51c63d6b1a..0000000000 --- a/packages/integration-tests/src/test-projects/hotswappable-resources/amplify/backend.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { defineBackend } from '@aws-amplify/backend'; -import { hotswappableResources } from './test_factories.js'; - -defineBackend(hotswappableResources); diff --git a/packages/integration-tests/src/test-projects/hotswappable-resources/amplify/data/resource.ts b/packages/integration-tests/src/test-projects/hotswappable-resources/amplify/data/resource.ts deleted file mode 100644 index 69d8d7e1b2..0000000000 --- a/packages/integration-tests/src/test-projects/hotswappable-resources/amplify/data/resource.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { a, defineData } from '@aws-amplify/backend'; - -const schema = a.schema({ - Todo: a - .model({ - content: a.string(), - fieldToUpdate: a.string(), - fieldToRemove: a.string(), - }) - .authorization((allow) => [allow.publicApiKey().to(['read'])]), -}); - -export const data = defineData({ - schema, - authorizationModes: { - // API Key is used for allow.publicApiKey() rules - apiKeyAuthorizationMode: { - expiresInDays: 30, - }, - }, -}); diff --git a/packages/integration-tests/src/test-projects/hotswappable-resources/amplify/test_factories.ts b/packages/integration-tests/src/test-projects/hotswappable-resources/amplify/test_factories.ts deleted file mode 100644 index a5c2b5ca29..0000000000 --- a/packages/integration-tests/src/test-projects/hotswappable-resources/amplify/test_factories.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { data } from './data/resource.js'; -import { nodeFunc } from './function.js'; - -export const hotswappableResources = { - data, - nodeFunc, -}; diff --git a/packages/integration-tests/src/test-projects/hotswappable-resources/hotswap-update-files/data/resource.ts b/packages/integration-tests/src/test-projects/hotswappable-resources/hotswap-update-files/data/resource.ts deleted file mode 100644 index 1689d12f77..0000000000 --- a/packages/integration-tests/src/test-projects/hotswappable-resources/hotswap-update-files/data/resource.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { a, defineData } from '@aws-amplify/backend'; - -const schema = a.schema({ - Todo: a - .model({ - content: a.string(), - fieldToUpdate: a.integer(), // field changed - newFieldAdded: a.string(), // new field added - }) - .authorization((allow) => [allow.publicApiKey().to(['read'])]), -}); - -export const data = defineData({ - schema, - authorizationModes: { - // API Key is used for allow.publicApiKey() rules - apiKeyAuthorizationMode: { - expiresInDays: 30, - }, - }, -}); diff --git a/packages/integration-tests/src/test-projects/live-dependency-health-checks-projects/README.md b/packages/integration-tests/src/test-projects/live-dependency-health-checks-projects/README.md new file mode 100644 index 0000000000..03e8063453 --- /dev/null +++ b/packages/integration-tests/src/test-projects/live-dependency-health-checks-projects/README.md @@ -0,0 +1,5 @@ +Projects in this directory are meant for `live-dependency-health-checks` (aka canaries). + +1. These projects must not be used in e2e tests to provide deep functional coverage. +2. These projects must be lightweight to provide fast runtime and stability. +3. These projects must cover only P0 scenarios we care most. (That are not covered by "getting started" flow, aka `create-amplify`). diff --git a/packages/integration-tests/src/test-projects/live-dependency-health-checks-projects/function-code-hotswap/amplify/backend.ts b/packages/integration-tests/src/test-projects/live-dependency-health-checks-projects/function-code-hotswap/amplify/backend.ts new file mode 100644 index 0000000000..f4e88845be --- /dev/null +++ b/packages/integration-tests/src/test-projects/live-dependency-health-checks-projects/function-code-hotswap/amplify/backend.ts @@ -0,0 +1,4 @@ +import { defineBackend } from '@aws-amplify/backend'; +import { nodeFunc } from './function.js'; + +defineBackend({ nodeFunc }); diff --git a/packages/integration-tests/src/test-projects/hotswappable-resources/amplify/func-src/handler.ts b/packages/integration-tests/src/test-projects/live-dependency-health-checks-projects/function-code-hotswap/amplify/func-src/handler.ts similarity index 100% rename from packages/integration-tests/src/test-projects/hotswappable-resources/amplify/func-src/handler.ts rename to packages/integration-tests/src/test-projects/live-dependency-health-checks-projects/function-code-hotswap/amplify/func-src/handler.ts diff --git a/packages/integration-tests/src/test-projects/hotswappable-resources/amplify/function.ts b/packages/integration-tests/src/test-projects/live-dependency-health-checks-projects/function-code-hotswap/amplify/function.ts similarity index 100% rename from packages/integration-tests/src/test-projects/hotswappable-resources/amplify/function.ts rename to packages/integration-tests/src/test-projects/live-dependency-health-checks-projects/function-code-hotswap/amplify/function.ts diff --git a/packages/integration-tests/src/test-projects/hotswappable-resources/hotswap-update-files/func-src/handler.ts b/packages/integration-tests/src/test-projects/live-dependency-health-checks-projects/function-code-hotswap/hotswap-update-files/func-src/handler.ts similarity index 100% rename from packages/integration-tests/src/test-projects/hotswappable-resources/hotswap-update-files/func-src/handler.ts rename to packages/integration-tests/src/test-projects/live-dependency-health-checks-projects/function-code-hotswap/hotswap-update-files/func-src/handler.ts