Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add retries to hotswapping resources for sandbox tests #2372

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}
Comment on lines +91 to +96
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add a code comment explaining that it's important to keep initial deployment in retry loop ?

I.e. the app state must be reset in each retry for updates (hotswaps) to be non no-op.

);
}
}

// 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
Loading