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

chore(core): verify stack artifacts are written in topological order #8515

Merged
merged 3 commits into from
Jun 16, 2020
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
26 changes: 26 additions & 0 deletions packages/@aws-cdk/core/test/test.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,32 @@ export = {

test.done();
},

'stacks are written to the assembly file in a topological order'(test: Test) {
// WHEN
const assembly = withApp({}, (app) => {
const stackC = new Stack(app, 'StackC');
const stackD = new Stack(app, 'StackD');
const stackA = new Stack(app, 'StackA');
const stackB = new Stack(app, 'StackB');

// Create the following dependency order:
// A ->
// C -> D
// B ->
stackC.addDependency(stackA);
stackC.addDependency(stackB);
stackD.addDependency(stackC);
});

// THEN
const artifactsIds = assembly.artifacts.map(a => a.id);
test.ok(artifactsIds.indexOf('StackA') < artifactsIds.indexOf('StackC'));
test.ok(artifactsIds.indexOf('StackB') < artifactsIds.indexOf('StackC'));
test.ok(artifactsIds.indexOf('StackC') < artifactsIds.indexOf('StackD'));

test.done();
},
};

class MyConstruct extends Construct {
Expand Down
58 changes: 58 additions & 0 deletions packages/@aws-cdk/cx-api/test/cloud-assembly-builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,62 @@ test('write and read nested cloud assembly artifact', () => {

const nested = art?.nestedAssembly;
expect(nested?.artifacts.length).toEqual(0);
});

test('artifcats are written in topological order', () => {
// GIVEN
const outdir = fs.mkdtempSync(path.join(os.tmpdir(), 'cloud-assembly-builder-tests'));
const session = new cxapi.CloudAssemblyBuilder(outdir);
const templateFile = 'foo.template.json';

const innerAsmDir = path.join(outdir, 'hello');
new cxapi.CloudAssemblyBuilder(innerAsmDir).buildAssembly();

// WHEN

// Create the following dependency order:
// A ->
// C -> D
// B ->
session.addArtifact('artifact-D', {
type: cxschema.ArtifactType.AWS_CLOUDFORMATION_STACK,
environment: 'aws://1222344/us-east-1',
dependencies: ['artifact-C'],
properties: {
templateFile,
},
});

session.addArtifact('artifact-C', {
type: cxschema.ArtifactType.AWS_CLOUDFORMATION_STACK,
environment: 'aws://1222344/us-east-1',
dependencies: ['artifact-B', 'artifact-A'],
properties: {
templateFile,
},
});

session.addArtifact('artifact-B', {
type: cxschema.ArtifactType.AWS_CLOUDFORMATION_STACK,
environment: 'aws://1222344/us-east-1',
properties: {
templateFile,
},
});

session.addArtifact('artifact-A', {
type: cxschema.ArtifactType.AWS_CLOUDFORMATION_STACK,
environment: 'aws://1222344/us-east-1',
properties: {
templateFile,
},
});

const asm = session.buildAssembly();
const artifactsIds = asm.artifacts.map(a => a.id);

// THEN
expect(artifactsIds.indexOf('artifact-A')).toBeLessThan(artifactsIds.indexOf('artifact-C'));
expect(artifactsIds.indexOf('artifact-B')).toBeLessThan(artifactsIds.indexOf('artifact-C'));
expect(artifactsIds.indexOf('artifact-C')).toBeLessThan(artifactsIds.indexOf('artifact-D'));
});
2 changes: 1 addition & 1 deletion packages/@aws-cdk/cx-api/test/cloud-assembly.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ test('assets', () => {
test('can-read-0.36.0', () => {
// WHEN
new CloudAssembly(path.join(FIXTURES, 'single-stack-0.36'));
// THEN: no eexception
// THEN: no exception
expect(true).toBeTruthy();
});

Expand Down