Skip to content

Commit

Permalink
ci: don't use me-south-1 region for e2e tests when using beta layer (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilch authored Jun 13, 2024
1 parent 227d1a7 commit 8887551
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 31 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"rm-dev-link": "rimraf -f \"$(yarn global bin)/amplify-dev\"",
"setup-dev-win": "(yarn && lerna run build) && yarn add-cli-no-save && (yarn hoist-cli-win && yarn rm-dev-link && yarn link-win)",
"setup-dev": "(yarn && lerna run build) && yarn add-cli-no-save && (yarn hoist-cli && yarn rm-dev-link && yarn link-dev)",
"split-e2e-tests": "yarn ts-node ./scripts/split-e2e-tests.ts && git add codebuild_specs/e2e_workflow.yml",
"split-e2e-tests": "yarn ts-node ./scripts/split-e2e-tests.ts prod && git add codebuild_specs/e2e_workflow.yml",
"split-e2e-tests-beta": "yarn ts-node ./scripts/split-e2e-tests.ts beta && git add codebuild_specs/e2e_workflow.yml",
"test-changed": "lerna run test --since main",
"test-ci": "lerna run test --concurrency 1 -- --ci -i",
"test-v2-transformers": "lerna run --scope '@aws-amplify/graphql-*-transformer' test",
Expand Down
38 changes: 19 additions & 19 deletions scripts/e2e-test-regions.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
[
{ "name": "ap-east-1", "optIn": true, "cognitoSupported": false },
{ "name": "ap-northeast-1", "optIn": false, "cognitoSupported": true },
{ "name": "ap-northeast-2", "optIn": false, "cognitoSupported": true },
{ "name": "ap-south-1", "optIn": false, "cognitoSupported": true },
{ "name": "ap-southeast-1", "optIn": false, "cognitoSupported": true },
{ "name": "ap-southeast-2", "optIn": false, "cognitoSupported": true },
{ "name": "ca-central-1", "optIn": false, "cognitoSupported": true },
{ "name": "eu-central-1", "optIn": false, "cognitoSupported": true },
{ "name": "eu-north-1", "optIn": false, "cognitoSupported": true },
{ "name": "eu-south-1", "optIn": true, "cognitoSupported": true },
{ "name": "eu-west-1", "optIn": false, "cognitoSupported": true },
{ "name": "eu-west-2", "optIn": false, "cognitoSupported": true },
{ "name": "eu-west-3", "optIn": false, "cognitoSupported": true },
{ "name": "me-south-1", "optIn": true, "cognitoSupported": true },
{ "name": "sa-east-1", "optIn": false, "cognitoSupported": true },
{ "name": "us-east-1", "optIn": false, "cognitoSupported": true },
{ "name": "us-east-2", "optIn": false, "cognitoSupported": true },
{ "name": "us-west-1", "optIn": false, "cognitoSupported": true },
{ "name": "us-west-2", "optIn": false, "cognitoSupported": true }
{ "name": "ap-east-1", "optIn": true, "cognitoSupported": false, "betaLayerDeployed": true },
{ "name": "ap-northeast-1", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true },
{ "name": "ap-northeast-2", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true },
{ "name": "ap-south-1", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true },
{ "name": "ap-southeast-1", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true },
{ "name": "ap-southeast-2", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true },
{ "name": "ca-central-1", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true },
{ "name": "eu-central-1", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true },
{ "name": "eu-north-1", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true },
{ "name": "eu-south-1", "optIn": true, "cognitoSupported": true, "betaLayerDeployed": true },
{ "name": "eu-west-1", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true },
{ "name": "eu-west-2", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true },
{ "name": "eu-west-3", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true },
{ "name": "me-south-1", "optIn": true, "cognitoSupported": true, "betaLayerDeployed": false },
{ "name": "sa-east-1", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true },
{ "name": "us-east-1", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true },
{ "name": "us-east-2", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true },
{ "name": "us-west-1", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true },
{ "name": "us-west-2", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true }
]
41 changes: 30 additions & 11 deletions scripts/split-e2e-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,23 @@ type TestRegion = {
name: string;
optIn: boolean;
cognitoSupported: boolean;
betaLayerDeployed: boolean; // is the beta layer deployed in this region
};

const REPO_ROOT = join(__dirname, '..');

const supportedRegionsPath = join(REPO_ROOT, 'scripts', 'e2e-test-regions.json');
const suportedRegions: TestRegion[] = JSON.parse(fs.readFileSync(supportedRegionsPath, 'utf-8'));
const testRegions = suportedRegions.map((region) => region.name);
const supportedRegionsByRegionName: Record<string, TestRegion> = suportedRegions.reduce(
const supportedRegions: TestRegion[] = JSON.parse(fs.readFileSync(supportedRegionsPath, 'utf-8'));
const testRegions = supportedRegions.map((region) => region.name);
const supportedRegionsByRegionName: Record<string, TestRegion> = supportedRegions.reduce(
(acc, region) => ({ ...acc, [region.name]: region }),
{},
);

// list of regions the beta layer is not deployed in
// the tests should not use these regions when using the beta layer
const BETA_LAYER_NOT_DEPLOYED = supportedRegions.filter((region) => !region.betaLayerDeployed).map((region) => region.name);

// https:/aws-amplify/amplify-cli/blob/d55917fd83140817a4447b3def1736f75142df44/packages/amplify-provider-awscloudformation/src/aws-regions.js#L4-L17
const v1TransformerSupportedRegionsPath = join(REPO_ROOT, 'scripts', 'v1-transformer-supported-regions.json');
const v1TransformerSupportedRegions = JSON.parse(fs.readFileSync(v1TransformerSupportedRegionsPath, 'utf-8')).map(
Expand Down Expand Up @@ -216,7 +221,12 @@ const getTestNameFromPath = (testSuitePath: string, region?: string): string =>
return testSuitePath.substring(startIndex, endIndex).split('.e2e').join('').split('.').join('-').concat(regionSuffix);
};

const splitTests = (baseJobLinux: any, testDirectory: string, pickTests?: (testSuites: string[]) => string[]): BatchBuildJob[] => {
const splitTests = (
baseJobLinux: any,
testDirectory: string,
useBetaLayer: boolean = false,
pickTests?: (testSuites: string[]) => string[],
): BatchBuildJob[] => {
const output: any[] = [];
let testSuites = getTestFiles(testDirectory);
if (pickTests && typeof pickTests === 'function') {
Expand Down Expand Up @@ -245,7 +255,8 @@ const splitTests = (baseJobLinux: any, testDirectory: string, pickTests?: (testS

if (RUN_SOLO.find((solo) => test === solo || test.match(solo))) {
if (RUN_IN_ALL_REGIONS.find((allRegionsTest) => test === allRegionsTest || test.match(allRegionsTest))) {
const candidateRegions = filterCandidateRegions(test, testRegions);
// always run these jobs in regions that do not have the beta layer deployed
const candidateRegions = filterCandidateRegions(test, testRegions, false);
candidateRegions.forEach((region) => {
const newSoloJob = createJob(os, jobIdx, true);
jobIdx++;
Expand All @@ -262,14 +273,14 @@ const splitTests = (baseJobLinux: any, testDirectory: string, pickTests?: (testS
if (USE_PARENT) {
newSoloJob.useParentAccount = true;
}
setJobRegion(test, newSoloJob, jobIdx);
setJobRegion(test, newSoloJob, jobIdx, useBetaLayer);
soloJobs.push(newSoloJob);
continue;
}

// add the test
currentJob.tests.push(test);
setJobRegion(test, currentJob, jobIdx);
setJobRegion(test, currentJob, jobIdx, useBetaLayer);
if (USE_PARENT) {
currentJob.useParentAccount = true;
}
Expand Down Expand Up @@ -308,7 +319,7 @@ const splitTests = (baseJobLinux: any, testDirectory: string, pickTests?: (testS
return result;
};

const setJobRegion = (test: string, job: CandidateJob, jobIdx: number): void => {
const setJobRegion = (test: string, job: CandidateJob, jobIdx: number, useBetaLayer: boolean): void => {
const FORCE_REGION = Object.keys(FORCE_REGION_MAP).find((key) => {
const testName = getTestNameFromPath(test);
return testName.startsWith(key);
Expand All @@ -325,7 +336,7 @@ const setJobRegion = (test: string, job: CandidateJob, jobIdx: number): void =>
return;
}

const candidateRegions = filterCandidateRegions(test, testRegions);
const candidateRegions = filterCandidateRegions(test, testRegions, useBetaLayer);

if (candidateRegions.length === 0) {
throw new Error(`No candidate regions found for test ${test}`);
Expand All @@ -334,7 +345,7 @@ const setJobRegion = (test: string, job: CandidateJob, jobIdx: number): void =>
job.region = candidateRegions[jobIdx % candidateRegions.length];
};

const filterCandidateRegions = (test: string, candidateRegions: string[]): string[] => {
const filterCandidateRegions = (test: string, candidateRegions: string[], useBetaLayer: boolean): string[] => {
let resolvedRegions = [...candidateRegions];

// Parent E2E account does not have opt-in regions. Choose non-opt-in region.
Expand All @@ -357,11 +368,16 @@ const filterCandidateRegions = (test: string, candidateRegions: string[]): strin
resolvedRegions = resolvedRegions.filter((region) => supportedRegionsByRegionName[region].cognitoSupported);
}

if (useBetaLayer) {
resolvedRegions = resolvedRegions.filter((region) => !BETA_LAYER_NOT_DEPLOYED.includes(region));
}

return resolvedRegions;
};

const main = (): void => {
const filteredTests = process.argv.slice(2);
const useBetaLayer = process.argv[2] === 'beta';
const filteredTests = process.argv.slice(3);
const configBase: ConfigBase = loadConfigBase();
const baseBuildGraph = configBase.batch['build-graph'];

Expand All @@ -376,6 +392,7 @@ const main = (): void => {
'depend-on': ['publish_to_local_registry'],
},
join(REPO_ROOT, 'packages', 'amplify-e2e-tests'),
useBetaLayer,
),
...splitTests(
{
Expand All @@ -387,6 +404,7 @@ const main = (): void => {
'depend-on': ['publish_to_local_registry'],
},
join(REPO_ROOT, 'packages', 'amplify-graphql-api-construct-tests'),
useBetaLayer,
),
...splitTests(
{
Expand All @@ -398,6 +416,7 @@ const main = (): void => {
'depend-on': ['publish_to_local_registry'],
},
join(REPO_ROOT, 'packages', 'graphql-transformers-e2e-tests'),
useBetaLayer,
),
];

Expand Down

0 comments on commit 8887551

Please sign in to comment.