@@ -30,11 +30,29 @@ describe('WorkGraph', () => {
30
30
31
31
actionedAssets . push ( x . id ) ;
32
32
} ,
33
- buildAsset : async ( { id } : AssetBuildNode ) => {
34
- actionedAssets . push ( id ) ;
33
+ buildAsset : async ( x : AssetBuildNode ) => {
34
+ const errorMessage = x . parentStack . displayName ;
35
+ const timeout = Number ( x . parentStack . stackName ) || 0 ;
36
+
37
+ await sleep ( timeout ) ;
38
+
39
+ if ( errorMessage ) {
40
+ throw Error ( errorMessage ) ;
41
+ }
42
+
43
+ actionedAssets . push ( x . id ) ;
35
44
} ,
36
- publishAsset : async ( { id } : AssetPublishNode ) => {
37
- actionedAssets . push ( id ) ;
45
+ publishAsset : async ( x : AssetPublishNode ) => {
46
+ const errorMessage = x . parentStack . displayName ;
47
+ const timeout = Number ( x . parentStack . stackName ) || 0 ;
48
+
49
+ await sleep ( timeout ) ;
50
+
51
+ if ( errorMessage ) {
52
+ throw Error ( errorMessage ) ;
53
+ }
54
+
55
+ actionedAssets . push ( x . id ) ;
38
56
} ,
39
57
} ;
40
58
@@ -252,11 +270,11 @@ describe('WorkGraph', () => {
252
270
// Failure Concurrency
253
271
test . each ( [
254
272
// Concurrency 1
255
- { scenario : 'A (error)' , concurrency : 1 , toDeploy : createArtifacts ( [ { id : 'A' , type : 'stack' , displayName : 'A' } ] ) , expectedError : 'A' , expectedStacks : [ ] } ,
256
- { scenario : 'A (error), B' , concurrency : 1 , toDeploy : createArtifacts ( [ { id : 'A' , type : 'stack' , displayName : 'A' } , { id : 'B' , type : 'stack' } ] ) , expectedError : 'A' , expectedStacks : [ ] } ,
257
- { scenario : 'A, B (error)' , concurrency : 1 , toDeploy : createArtifacts ( [ { id : 'A' , type : 'stack' } , { id : 'B' , type : 'stack' , displayName : 'B' } ] ) , expectedError : 'B' , expectedStacks : [ 'A' ] } ,
258
- { scenario : 'A (error) -> B' , concurrency : 1 , toDeploy : createArtifacts ( [ { id : 'A' , type : 'stack' , displayName : 'A' } , { id : 'B' , type : 'stack' , stackDependencies : [ 'A' ] } ] ) , expectedError : 'A' , expectedStacks : [ ] } ,
259
- { scenario : '[unsorted] A (error) -> B' , concurrency : 1 , toDeploy : createArtifacts ( [ { id : 'B' , type : 'stack' , stackDependencies : [ 'A' ] } , { id : 'A' , type : 'stack' , displayName : 'A' } ] ) , expectedError : 'A' , expectedStacks : [ ] } ,
273
+ { scenario : 'A (error)' , concurrency : 1 , toDeploy : createArtifacts ( [ { id : 'A' , type : 'stack' , displayName : 'A' } ] ) , expectedError : 'A' , expected : [ ] } ,
274
+ { scenario : 'A (error), B' , concurrency : 1 , toDeploy : createArtifacts ( [ { id : 'A' , type : 'stack' , displayName : 'A' } , { id : 'B' , type : 'stack' } ] ) , expectedError : 'A' , expected : [ ] } ,
275
+ { scenario : 'A, B (error)' , concurrency : 1 , toDeploy : createArtifacts ( [ { id : 'A' , type : 'stack' } , { id : 'B' , type : 'stack' , displayName : 'B' } ] ) , expectedError : 'B' , expected : [ 'A' ] } ,
276
+ { scenario : 'A (error) -> B' , concurrency : 1 , toDeploy : createArtifacts ( [ { id : 'A' , type : 'stack' , displayName : 'A' } , { id : 'B' , type : 'stack' , stackDependencies : [ 'A' ] } ] ) , expectedError : 'A' , expected : [ ] } ,
277
+ { scenario : '[unsorted] A (error) -> B' , concurrency : 1 , toDeploy : createArtifacts ( [ { id : 'B' , type : 'stack' , stackDependencies : [ 'A' ] } , { id : 'A' , type : 'stack' , displayName : 'A' } ] ) , expectedError : 'A' , expected : [ ] } ,
260
278
{
261
279
scenario : 'A (error) -> B, C -> D' ,
262
280
concurrency : 1 ,
@@ -267,7 +285,7 @@ describe('WorkGraph', () => {
267
285
{ id : 'D' , type : 'stack' , stackDependencies : [ 'C' ] } ,
268
286
] ) ,
269
287
expectedError : 'A' ,
270
- expectedStacks : [ ] ,
288
+ expected : [ ] ,
271
289
} ,
272
290
{
273
291
scenario : 'A -> B, C (error) -> D' ,
@@ -279,15 +297,36 @@ describe('WorkGraph', () => {
279
297
{ id : 'D' , type : 'stack' , stackDependencies : [ 'C' ] } ,
280
298
] ) ,
281
299
expectedError : 'C' ,
282
- expectedStacks : [ 'A' ] ,
300
+ expected : [ 'A' ] ,
301
+ } ,
302
+ // With assets
303
+ {
304
+ scenario : 'A -> b (asset build error)' ,
305
+ concurrency : 1 ,
306
+ toDeploy : createArtifacts ( [
307
+ { id : 'A' , type : 'stack' , assetDependencies : [ 'b' ] } ,
308
+ { id : 'b' , type : 'asset' , displayName : 'build-b' } ,
309
+ ] ) ,
310
+ expectedError : 'build-b' ,
311
+ expected : [ ] ,
312
+ } ,
313
+ {
314
+ scenario : 'A -> b (asset publish error)' ,
315
+ concurrency : 1 ,
316
+ toDeploy : createArtifacts ( [
317
+ { id : 'A' , type : 'stack' , assetDependencies : [ 'b' ] } ,
318
+ { id : 'b' , type : 'asset' , displayName : 'publish-b' } ,
319
+ ] ) ,
320
+ expectedError : 'publish-b' ,
321
+ expected : [ 'b-build' ] ,
283
322
} ,
284
323
285
324
// Concurrency 2
286
- { scenario : 'A (error)' , concurrency : 2 , toDeploy : createArtifacts ( [ { id : 'A' , type : 'stack' , displayName : 'A' } ] ) , expectedError : 'A' , expectedStacks : [ ] } ,
287
- { scenario : 'A (error), B' , concurrency : 2 , toDeploy : createArtifacts ( [ { id : 'A' , type : 'stack' , displayName : 'A' } , { id : 'B' , type : 'stack' } ] ) , expectedError : 'A' , expectedStacks : [ 'B' ] } ,
288
- { scenario : 'A, B (error)' , concurrency : 2 , toDeploy : createArtifacts ( [ { id : 'A' , type : 'stack' } , { id : 'B' , type : 'stack' , displayName : 'B' } ] ) , expectedError : 'B' , expectedStacks : [ 'A' ] } ,
289
- { scenario : 'A (error) -> B' , concurrency : 2 , toDeploy : createArtifacts ( [ { id : 'A' , type : 'stack' , displayName : 'A' } , { id : 'B' , type : 'stack' , stackDependencies : [ 'A' ] } ] ) , expectedError : 'A' , expectedStacks : [ ] } ,
290
- { scenario : '[unsorted] A (error) -> B' , concurrency : 2 , toDeploy : createArtifacts ( [ { id : 'B' , type : 'stack' , stackDependencies : [ 'A' ] } , { id : 'A' , type : 'stack' , displayName : 'A' } ] ) , expectedError : 'A' , expectedStacks : [ ] } ,
325
+ { scenario : 'A (error)' , concurrency : 2 , toDeploy : createArtifacts ( [ { id : 'A' , type : 'stack' , displayName : 'A' } ] ) , expectedError : 'A' , expected : [ ] } ,
326
+ { scenario : 'A (error), B' , concurrency : 2 , toDeploy : createArtifacts ( [ { id : 'A' , type : 'stack' , displayName : 'A' } , { id : 'B' , type : 'stack' } ] ) , expectedError : 'A' , expected : [ 'B' ] } ,
327
+ { scenario : 'A, B (error)' , concurrency : 2 , toDeploy : createArtifacts ( [ { id : 'A' , type : 'stack' } , { id : 'B' , type : 'stack' , displayName : 'B' } ] ) , expectedError : 'B' , expected : [ 'A' ] } ,
328
+ { scenario : 'A (error) -> B' , concurrency : 2 , toDeploy : createArtifacts ( [ { id : 'A' , type : 'stack' , displayName : 'A' } , { id : 'B' , type : 'stack' , stackDependencies : [ 'A' ] } ] ) , expectedError : 'A' , expected : [ ] } ,
329
+ { scenario : '[unsorted] A (error) -> B' , concurrency : 2 , toDeploy : createArtifacts ( [ { id : 'B' , type : 'stack' , stackDependencies : [ 'A' ] } , { id : 'A' , type : 'stack' , displayName : 'A' } ] ) , expectedError : 'A' , expected : [ ] } ,
291
330
{
292
331
scenario : 'A (error) -> B, C -> D' ,
293
332
concurrency : 2 ,
@@ -298,7 +337,7 @@ describe('WorkGraph', () => {
298
337
{ id : 'D' , type : 'stack' , stackDependencies : [ 'C' ] } ,
299
338
] ) ,
300
339
expectedError : 'A' ,
301
- expectedStacks : [ 'C' ] ,
340
+ expected : [ 'C' ] ,
302
341
} ,
303
342
{
304
343
scenario : 'A -> B, C (error) -> D' ,
@@ -310,15 +349,38 @@ describe('WorkGraph', () => {
310
349
{ id : 'D' , type : 'stack' , stackDependencies : [ 'C' ] } ,
311
350
] ) ,
312
351
expectedError : 'C' ,
313
- expectedStacks : [ 'A' , 'B' ] ,
352
+ expected : [ 'A' , 'B' ] ,
353
+ } ,
354
+ // With assets
355
+ {
356
+ scenario : 'A -> b (asset build error), C' ,
357
+ concurrency : 2 ,
358
+ toDeploy : createArtifacts ( [
359
+ { id : 'A' , type : 'stack' , assetDependencies : [ 'b' ] } ,
360
+ { id : 'b' , type : 'asset' , displayName : 'build-b' } ,
361
+ { id : 'C' , type : 'stack' } ,
362
+ ] ) ,
363
+ expectedError : 'build-b' ,
364
+ expected : [ 'C' ] ,
365
+ } ,
366
+ {
367
+ scenario : 'A -> b (asset publish error), C' ,
368
+ concurrency : 2 ,
369
+ toDeploy : createArtifacts ( [
370
+ { id : 'A' , type : 'stack' , assetDependencies : [ 'b' ] } ,
371
+ { id : 'b' , type : 'asset' , displayName : 'publish-b' } ,
372
+ { id : 'C' , type : 'stack' } ,
373
+ ] ) ,
374
+ expectedError : 'publish-b' ,
375
+ expected : [ 'b-build' , 'C' ] ,
314
376
} ,
315
- ] ) ( 'Failure - Concurrency: $concurrency - $scenario' , async ( { concurrency, expectedError, toDeploy, expectedStacks } ) => {
377
+ ] ) ( 'Failure - Concurrency: $concurrency - $scenario' , async ( { concurrency, expectedError, toDeploy, expected } ) => {
316
378
const graph = new WorkGraph ( ) ;
317
379
addTestArtifactsToGraph ( toDeploy , graph ) ;
318
380
319
381
await expect ( graph . doParallel ( concurrency , callbacks ) ) . rejects . toThrowError ( expectedError ) ;
320
382
321
- expect ( actionedAssets ) . toStrictEqual ( expectedStacks ) ;
383
+ expect ( actionedAssets ) . toStrictEqual ( expected ) ;
322
384
} ) ;
323
385
324
386
// Failure Graph Circular Dependencies
@@ -393,7 +455,11 @@ function addTestArtifactsToGraph(toDeploy: TestArtifact[], graph: WorkGraph) {
393
455
asset : DUMMY ,
394
456
assetManifest : DUMMY ,
395
457
assetManifestArtifact : DUMMY ,
396
- parentStack : DUMMY ,
458
+ parentStack : {
459
+ // We're smuggling information here so that the set of callbacks can do some appropriate action
460
+ stackName : node . name , // Used to smuggle sleep duration
461
+ displayName : node . displayName ?. includes ( 'build' ) ? node . displayName : undefined , // Used to smuggle exception triggers
462
+ } as any ,
397
463
dependencies : new Set ( [ ...node . stackDependencies ?? [ ] , ...( node . assetDependencies ?? [ ] ) . map ( x => `${ x } -publish` ) ] ) ,
398
464
} ) ;
399
465
graph . addNodes ( {
@@ -403,7 +469,11 @@ function addTestArtifactsToGraph(toDeploy: TestArtifact[], graph: WorkGraph) {
403
469
asset : DUMMY ,
404
470
assetManifest : DUMMY ,
405
471
assetManifestArtifact : DUMMY ,
406
- parentStack : DUMMY ,
472
+ parentStack : {
473
+ // We're smuggling information here so that the set of callbacks can do some appropriate action
474
+ stackName : node . name , // Used to smuggle sleep duration
475
+ displayName : node . displayName ?. includes ( 'publish' ) ? node . displayName : undefined , // Used to smuggle exception triggers
476
+ } as any ,
407
477
dependencies : new Set ( [ `${ node . id } -build` ] ) ,
408
478
} ) ;
409
479
break ;
0 commit comments