Skip to content

Commit 146b3f8

Browse files
committed
Merge remote-tracking branch 'upstream/main' into stocaaro/client-schema/function-runtime-config
2 parents f2fb514 + 9fd0642 commit 146b3f8

File tree

4 files changed

+55
-37
lines changed

4 files changed

+55
-37
lines changed

.changeset/serious-spoons-fetch.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/package_manager_sanity_checks.test.ts

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
runWithPackageManager,
2727
} from './process-controller/process_controller.js';
2828
import { amplifyAtTag } from './constants.js';
29-
import { runWithRetry } from './retry.js';
29+
import { RetryPredicates, runWithRetry } from './retry.js';
3030

3131
void describe('getting started happy path', async () => {
3232
let branchBackendIdentifier: BackendIdentifier;
@@ -83,34 +83,21 @@ void describe('getting started happy path', async () => {
8383
return;
8484
}
8585

86-
await runWithRetry(
87-
async () => {
88-
if (packageManager === 'yarn-classic') {
89-
await execa('yarn', ['add', 'create-amplify'], { cwd: tempDir });
90-
await execaCommand(
91-
'./node_modules/.bin/create-amplify --yes --debug',
92-
{
93-
cwd: tempDir,
94-
env: { npm_config_user_agent: 'yarn/1.22.21' },
95-
}
96-
);
97-
} else {
98-
await runPackageManager(
99-
packageManager,
100-
['create', amplifyAtTag, '--yes'],
101-
tempDir
102-
).run();
103-
}
104-
},
105-
(error) => {
106-
// Retry on network-related errors or command failures
107-
return (
108-
error.message.includes('exit code 1') &&
109-
(error.message.includes('aws-amplify') ||
110-
error.message.includes('Command failed with exit code 1: yarn add'))
111-
);
86+
await runWithRetry(async () => {
87+
if (packageManager === 'yarn-classic') {
88+
await execa('yarn', ['add', 'create-amplify'], { cwd: tempDir });
89+
await execaCommand('./node_modules/.bin/create-amplify --yes --debug', {
90+
cwd: tempDir,
91+
env: { npm_config_user_agent: 'yarn/1.22.21' },
92+
});
93+
} else {
94+
await runPackageManager(
95+
packageManager,
96+
['create', amplifyAtTag, '--yes'],
97+
tempDir
98+
).run();
11299
}
113-
);
100+
}, RetryPredicates.createAmplifyRetryPredicate);
114101

115102
const pathPrefix = path.join(tempDir, 'amplify');
116103

packages/integration-tests/src/retry.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export type RetryPredicate = (error: Error) => boolean;
2+
13
/**
24
* Executes an asynchronous operation with retry logic.
35
* This function attempts to execute the provided callable function multiple times
@@ -6,7 +8,7 @@
68
*/
79
export const runWithRetry = async <T>(
810
callable: () => Promise<T>,
9-
retryPredicate: (error: Error) => boolean,
11+
retryPredicate: RetryPredicate,
1012
maxAttempts = 3
1113
): Promise<T> => {
1214
const collectedErrors: Error[] = [];
@@ -21,6 +23,10 @@ export const runWithRetry = async <T>(
2123
if (!retryPredicate(error)) {
2224
throw error;
2325
}
26+
} else {
27+
// re-throw non-Error.
28+
// This should never happen, but we should be aware if it does.
29+
throw error;
2430
}
2531
}
2632
}
@@ -30,3 +36,23 @@ export const runWithRetry = async <T>(
3036
`All ${maxAttempts} attempts failed`
3137
);
3238
};
39+
40+
/**
41+
* Known retry predicates that repeat in multiple places.
42+
*/
43+
export class RetryPredicates {
44+
static createAmplifyRetryPredicate: RetryPredicate = (
45+
error: Error
46+
): boolean => {
47+
const message = error.message.toLowerCase();
48+
// Note: we can't assert on whole stdout or stderr because
49+
// they're not always captured in the error due to settings we need for
50+
// ProcessController to work.
51+
const didProcessExitWithError = message.includes('exit code 1');
52+
const isKnownProcess =
53+
(message.includes('yarn add') && message.includes('aws-amplify')) ||
54+
message.includes('npm create amplify') ||
55+
message.includes('pnpm create amplify');
56+
return didProcessExitWithError && isKnownProcess;
57+
};
58+
}

packages/integration-tests/src/test-e2e/create_amplify.test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { testConcurrencyLevel } from './test_concurrency.js';
99
import { findBaselineCdkVersion } from '../cdk_version_finder.js';
1010
import { amplifyAtTag } from '../constants.js';
1111
import { NpmProxyController } from '../npm_proxy_controller.js';
12+
import { RetryPredicates, runWithRetry } from '../retry.js';
1213

1314
void describe(
1415
'create-amplify script',
@@ -78,14 +79,16 @@ void describe(
7879
);
7980
}
8081

81-
await execa(
82-
'npm',
83-
['create', amplifyAtTag, '--yes', '--', '--debug'],
84-
{
85-
cwd: tempDir,
86-
stdio: 'inherit',
87-
}
88-
);
82+
await runWithRetry(async () => {
83+
await execa(
84+
'npm',
85+
['create', amplifyAtTag, '--yes', '--', '--debug'],
86+
{
87+
cwd: tempDir,
88+
stdio: 'inherit',
89+
}
90+
);
91+
}, RetryPredicates.createAmplifyRetryPredicate);
8992

9093
// Override CDK installation with baseline version
9194
await execa(

0 commit comments

Comments
 (0)