Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolk committed Dec 3, 2024
1 parent 867fed7 commit 01441c5
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 104 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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`).
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
},
},
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/**
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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`).
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { defineBackend } from '@aws-amplify/backend';
import { nodeFunc } from './function.js';

defineBackend({ nodeFunc });

0 comments on commit 01441c5

Please sign in to comment.