Skip to content

Commit 2d4170a

Browse files
committed
tests for toolkit-lib
1 parent f0976b3 commit 2d4170a

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

packages/@aws-cdk/toolkit-lib/test/actions/deploy.test.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { StackParameters } from '../../lib/actions/deploy';
22
import type { DeployStackOptions, DeployStackResult } from '../../lib/api/deployments';
33
import * as deployments from '../../lib/api/deployments';
4+
import { WorkGraphBuilder } from '../../lib/api/work-graph';
45
import { Toolkit } from '../../lib/toolkit';
56
import { builderFixture, cdkOutFixture, disposableCloudAssemblySource, TestIoHost } from '../_helpers';
67

@@ -161,6 +162,83 @@ IAM Statement Changes
161162
forcePublish: true,
162163
}));
163164
});
165+
166+
describe('assetBuildConcurrency', () => {
167+
let buildSpy: jest.SpyInstance;
168+
169+
afterEach(() => {
170+
buildSpy?.mockRestore();
171+
});
172+
173+
test('is passed when assetParallelism is true', async () => {
174+
const mockWorkGraph = {
175+
doParallel: jest.fn().mockResolvedValue(undefined),
176+
removeUnnecessaryAssets: jest.fn().mockResolvedValue(undefined),
177+
};
178+
buildSpy = jest.spyOn(WorkGraphBuilder.prototype, 'build').mockReturnValue(mockWorkGraph as any);
179+
180+
const cx = await builderFixture(toolkit, 'stack-with-asset');
181+
182+
await toolkit.deploy(cx, {
183+
assetParallelism: true,
184+
assetBuildConcurrency: 4,
185+
});
186+
187+
expect(mockWorkGraph.doParallel).toHaveBeenCalledWith(
188+
expect.objectContaining({
189+
'asset-build': 4,
190+
}),
191+
expect.anything(),
192+
);
193+
});
194+
195+
test('is ignored when assetParallelism is false', async () => {
196+
const mockWorkGraph = {
197+
doParallel: jest.fn().mockResolvedValue(undefined),
198+
removeUnnecessaryAssets: jest.fn().mockResolvedValue(undefined),
199+
};
200+
buildSpy = jest.spyOn(WorkGraphBuilder.prototype, 'build').mockReturnValue(mockWorkGraph as any);
201+
202+
const cx = await builderFixture(toolkit, 'stack-with-asset');
203+
204+
await toolkit.deploy(cx, {
205+
assetParallelism: false,
206+
assetBuildConcurrency: 4,
207+
});
208+
209+
expect(mockWorkGraph.doParallel).toHaveBeenCalledWith(
210+
expect.objectContaining({
211+
'asset-build': 1,
212+
}),
213+
expect.anything(),
214+
);
215+
});
216+
217+
test.each([
218+
true,
219+
false,
220+
undefined,
221+
])('defaults to 1 when assetParallelism=%s and assetBuildConcurrency is not specified', async (assetParallelism) => {
222+
const mockWorkGraph = {
223+
doParallel: jest.fn().mockResolvedValue(undefined),
224+
removeUnnecessaryAssets: jest.fn().mockResolvedValue(undefined),
225+
};
226+
buildSpy = jest.spyOn(WorkGraphBuilder.prototype, 'build').mockReturnValue(mockWorkGraph as any);
227+
228+
const cx = await builderFixture(toolkit, 'stack-with-asset');
229+
230+
await toolkit.deploy(cx, {
231+
assetParallelism,
232+
});
233+
234+
expect(mockWorkGraph.doParallel).toHaveBeenCalledWith(
235+
expect.objectContaining({
236+
'asset-build': 1,
237+
}),
238+
expect.anything(),
239+
);
240+
});
241+
});
164242
});
165243

166244
describe('deployment results', () => {

0 commit comments

Comments
 (0)