@@ -17,6 +17,7 @@ import {
1717 getBuildFlags ,
1818 ParamsSource ,
1919 runBuild ,
20+ SamBuildResult ,
2021} from '../../../shared/sam/build'
2122import { TreeNode } from '../../../shared/treeview/resourceTreeDataProvider'
2223import { createWizardTester } from '../wizards/wizardTestUtils'
@@ -32,6 +33,7 @@ import { samconfigCompleteData, validTemplateData } from './samTestUtils'
3233import { CloudFormationTemplateRegistry } from '../../../shared/fs/templateRegistry'
3334import { getTestWindow } from '../vscode/window'
3435import { CancellationError } from '../../../shared/utilities/timeoutUtils'
36+ import { SamAppLocation } from '../../../awsService/appBuilder/explorer/samProject'
3537
3638describe ( 'SAM BuildWizard' , async function ( ) {
3739 const createTester = async ( params ?: Partial < BuildParams > , arg ?: TreeNode | undefined ) =>
@@ -388,22 +390,8 @@ describe('SAM runBuild', () => {
388390 verifyCorrectDependencyCall ( )
389391 } )
390392
391- it ( '[entry: appbuilder node] with default flags should instantiate correct process in terminal' , async ( ) => {
392- const prompterTester = PrompterTester . init ( )
393- . handleQuickPick ( 'Specify parameter source for build' , async ( quickPick ) => {
394- // Need sometime to wait for the template to search for template file
395- await quickPick . untilReady ( )
396-
397- assert . strictEqual ( quickPick . items . length , 2 )
398- const items = quickPick . items
399- assert . strictEqual ( quickPick . items . length , 2 )
400- assert . deepStrictEqual ( items [ 0 ] , { data : ParamsSource . Specify , label : 'Specify build flags' } )
401- assert . deepStrictEqual ( items [ 1 ] . label , 'Use default values' )
402- quickPick . acceptItem ( quickPick . items [ 1 ] )
403- } )
404- . build ( )
405-
406- // Invoke sync command from command palette
393+ it ( '[entry: appbuilder node] with default flags should instantiate correct process in terminal and show progress notification' , async ( ) => {
394+ const prompterTester = getPrompterTester ( )
407395 const expectedSamAppLocation = {
408396 workspaceFolder : workspaceFolder ,
409397 samTemplateUri : templateFile ,
@@ -412,6 +400,10 @@ describe('SAM runBuild', () => {
412400
413401 await runBuild ( new AppNode ( expectedSamAppLocation ) )
414402
403+ getTestWindow ( )
404+ . getFirstMessage ( )
405+ . assertProgress ( `Building SAM template at ${ expectedSamAppLocation . samTemplateUri . path } ` )
406+
415407 assert . deepEqual ( mockChildProcessClass . getCall ( 0 ) . args , [
416408 'sam-cli-path' ,
417409 [
@@ -437,6 +429,27 @@ describe('SAM runBuild', () => {
437429 prompterTester . assertCallAll ( )
438430 } )
439431
432+ it ( '[entry: appbuilder node] should throw an error when running two build processes in parallel for the same template' , async ( ) => {
433+ const prompterTester = getPrompterTester ( )
434+ const expectedSamAppLocation = {
435+ workspaceFolder : workspaceFolder ,
436+ samTemplateUri : templateFile ,
437+ projectRoot : projectRoot ,
438+ }
439+ await assert . rejects (
440+ async ( ) => {
441+ await runInParallel ( expectedSamAppLocation )
442+ } ,
443+ ( e : any ) => {
444+ assert . strictEqual ( e instanceof ToolkitError , true )
445+ assert . strictEqual ( e . message , 'Template is already being built' )
446+ assert . strictEqual ( e . code , 'BuildInProgress' )
447+ return true
448+ }
449+ )
450+ prompterTester . assertCallAll ( undefined , 2 )
451+ } )
452+
440453 it ( '[entry: command palette] use samconfig should instantiate correct process in terminal' , async ( ) => {
441454 const samconfigFile = vscode . Uri . file ( await testFolder . write ( 'samconfig.toml' , samconfigCompleteData ) )
442455
@@ -551,3 +564,23 @@ describe('SAM runBuild', () => {
551564 } )
552565 } )
553566} )
567+
568+ async function runInParallel ( samLocation : SamAppLocation ) : Promise < [ SamBuildResult , SamBuildResult ] > {
569+ return Promise . all ( [ runBuild ( new AppNode ( samLocation ) ) , runBuild ( new AppNode ( samLocation ) ) ] )
570+ }
571+
572+ function getPrompterTester ( ) {
573+ return PrompterTester . init ( )
574+ . handleQuickPick ( 'Specify parameter source for build' , async ( quickPick ) => {
575+ // Need sometime to wait for the template to search for template file
576+ await quickPick . untilReady ( )
577+
578+ assert . strictEqual ( quickPick . items . length , 2 )
579+ const items = quickPick . items
580+ assert . strictEqual ( quickPick . items . length , 2 )
581+ assert . deepStrictEqual ( items [ 0 ] , { data : ParamsSource . Specify , label : 'Specify build flags' } )
582+ assert . deepStrictEqual ( items [ 1 ] . label , 'Use default values' )
583+ quickPick . acceptItem ( quickPick . items [ 1 ] )
584+ } )
585+ . build ( )
586+ }
0 commit comments