Skip to content

Commit

Permalink
add retries to hotswapping resources for sandbox tests (#2372)
Browse files Browse the repository at this point in the history
* add retries to hotswapping resources for sandbox tests

* add comment
  • Loading branch information
rtpascual authored Dec 30, 2024
1 parent 2e5562d commit 22089b7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .changeset/hungry-dogs-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
amplifySharedSecretNameKey,
createAmplifySharedSecretName,
} from '../../shared_secret.js';
import { runWithRetry } from '../../retry.js';

/**
* Defines sandbox test
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 22089b7

Please sign in to comment.