@@ -21,6 +21,7 @@ import {
21
21
amplifySharedSecretNameKey ,
22
22
createAmplifySharedSecretName ,
23
23
} from '../../shared_secret.js' ;
24
+ import { runWithRetry } from '../../retry.js' ;
24
25
25
26
/**
26
27
* Defines sandbox test
@@ -83,27 +84,34 @@ export const defineSandboxTest = (testProjectCreator: TestProjectCreator) => {
83
84
void it ( `[${ testProjectCreator . name } ] hot-swaps a change` , async ( ) => {
84
85
const updates = await testProject . getUpdates ( ) ;
85
86
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
+ }
101
97
) ;
102
- }
103
- }
104
98
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
+ ) ;
107
115
108
116
await testProject . assertPostDeployment ( sandboxBackendIdentifier ) ;
109
117
}
0 commit comments