|
1 | 1 | import { StackParameters } from '../../lib/actions/deploy'; |
2 | 2 | import type { DeployStackOptions, DeployStackResult } from '../../lib/api/deployments'; |
3 | 3 | import * as deployments from '../../lib/api/deployments'; |
| 4 | +import { WorkGraphBuilder } from '../../lib/api/work-graph'; |
4 | 5 | import { Toolkit } from '../../lib/toolkit'; |
5 | 6 | import { builderFixture, cdkOutFixture, disposableCloudAssemblySource, TestIoHost } from '../_helpers'; |
6 | 7 |
|
@@ -161,6 +162,83 @@ IAM Statement Changes |
161 | 162 | forcePublish: true, |
162 | 163 | })); |
163 | 164 | }); |
| 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 | + }); |
164 | 242 | }); |
165 | 243 |
|
166 | 244 | describe('deployment results', () => { |
|
0 commit comments