From 22089b7a7321b8fc99e178a8dc777ccd77690e12 Mon Sep 17 00:00:00 2001 From: Roshane Pascual Date: Mon, 30 Dec 2024 09:46:05 -0800 Subject: [PATCH] add retries to hotswapping resources for sandbox tests (#2372) * add retries to hotswapping resources for sandbox tests * add comment --- .changeset/hungry-dogs-juggle.md | 2 + .../test-e2e/sandbox/sandbox.test.template.ts | 46 +++++++++++-------- 2 files changed, 29 insertions(+), 19 deletions(-) create mode 100644 .changeset/hungry-dogs-juggle.md diff --git a/.changeset/hungry-dogs-juggle.md b/.changeset/hungry-dogs-juggle.md new file mode 100644 index 0000000000..a845151cc8 --- /dev/null +++ b/.changeset/hungry-dogs-juggle.md @@ -0,0 +1,2 @@ +--- +--- 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 599cb4dae8..716c783510 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 @@ -21,6 +21,7 @@ import { amplifySharedSecretNameKey, createAmplifySharedSecretName, } from '../../shared_secret.js'; +import { runWithRetry } from '../../retry.js'; /** * Defines sandbox test @@ -83,27 +84,34 @@ export const defineSandboxTest = (testProjectCreator: TestProjectCreator) => { void it(`[${testProjectCreator.name}] hot-swaps a change`, async () => { const updates = await testProject.getUpdates(); if (updates.length > 0) { - const processController = ampxCli( - ['sandbox', '--dirToWatch', 'amplify'], - testProject.projectDirPath, - { - env: sharedSecretsEnv, - } - ); - - for (const update of updates) { - processController - .do(replaceFiles(update.replacements)) - .do(waitForSandboxToBeginHotswappingResources()); - if (update.deployThresholdSec) { - processController.do( - ensureDeploymentTimeLessThan(update.deployThresholdSec) + // retry hotswapping resources if deployment time is higher than the threshold + await runWithRetry( + async () => { + // keeping initial deployment in retry loop to reset app state for each hotswap to be a non no-op + const processController = ampxCli( + ['sandbox', '--dirToWatch', 'amplify'], + testProject.projectDirPath, + { + env: sharedSecretsEnv, + } ); - } - } - // Execute the process. - await processController.do(interruptSandbox()).run(); + for (const update of updates) { + processController + .do(replaceFiles(update.replacements)) + .do(waitForSandboxToBeginHotswappingResources()); + if (update.deployThresholdSec) { + processController.do( + ensureDeploymentTimeLessThan(update.deployThresholdSec) + ); + } + } + + // Execute the process. + await processController.do(interruptSandbox()).run(); + }, + (error) => error.message.includes('Deployment time') + ); await testProject.assertPostDeployment(sandboxBackendIdentifier); }