Skip to content

Commit 22089b7

Browse files
authored
add retries to hotswapping resources for sandbox tests (#2372)
* add retries to hotswapping resources for sandbox tests * add comment
1 parent 2e5562d commit 22089b7

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

.changeset/hungry-dogs-juggle.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/integration-tests/src/test-e2e/sandbox/sandbox.test.template.ts

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
amplifySharedSecretNameKey,
2222
createAmplifySharedSecretName,
2323
} from '../../shared_secret.js';
24+
import { runWithRetry } from '../../retry.js';
2425

2526
/**
2627
* Defines sandbox test
@@ -83,27 +84,34 @@ export const defineSandboxTest = (testProjectCreator: TestProjectCreator) => {
8384
void it(`[${testProjectCreator.name}] hot-swaps a change`, async () => {
8485
const updates = await testProject.getUpdates();
8586
if (updates.length > 0) {
86-
const processController = ampxCli(
87-
['sandbox', '--dirToWatch', 'amplify'],
88-
testProject.projectDirPath,
89-
{
90-
env: sharedSecretsEnv,
91-
}
92-
);
93-
94-
for (const update of updates) {
95-
processController
96-
.do(replaceFiles(update.replacements))
97-
.do(waitForSandboxToBeginHotswappingResources());
98-
if (update.deployThresholdSec) {
99-
processController.do(
100-
ensureDeploymentTimeLessThan(update.deployThresholdSec)
87+
// retry hotswapping resources if deployment time is higher than the threshold
88+
await runWithRetry(
89+
async () => {
90+
// keeping initial deployment in retry loop to reset app state for each hotswap to be a non no-op
91+
const processController = ampxCli(
92+
['sandbox', '--dirToWatch', 'amplify'],
93+
testProject.projectDirPath,
94+
{
95+
env: sharedSecretsEnv,
96+
}
10197
);
102-
}
103-
}
10498

105-
// Execute the process.
106-
await processController.do(interruptSandbox()).run();
99+
for (const update of updates) {
100+
processController
101+
.do(replaceFiles(update.replacements))
102+
.do(waitForSandboxToBeginHotswappingResources());
103+
if (update.deployThresholdSec) {
104+
processController.do(
105+
ensureDeploymentTimeLessThan(update.deployThresholdSec)
106+
);
107+
}
108+
}
109+
110+
// Execute the process.
111+
await processController.do(interruptSandbox()).run();
112+
},
113+
(error) => error.message.includes('Deployment time')
114+
);
107115

108116
await testProject.assertPostDeployment(sandboxBackendIdentifier);
109117
}

0 commit comments

Comments
 (0)