@@ -280,8 +280,6 @@ describe('SAM runBuild', () => {
280
280
let mockChildProcessClass : sinon . SinonStub
281
281
let mockSamBuildChildProcess : sinon . SinonStub
282
282
283
- let spyRunInterminal : sinon . SinonSpy
284
-
285
283
let registry : CloudFormationTemplateRegistry
286
284
287
285
// Dependency clients
@@ -296,8 +294,6 @@ describe('SAM runBuild', () => {
296
294
templateFile = vscode . Uri . file ( await testFolder . write ( 'template.yaml' , validTemplateData ) )
297
295
await registry . addItem ( templateFile )
298
296
299
- spyRunInterminal = sandbox . spy ( ProcessTerminalUtils , 'runInTerminal' )
300
-
301
297
mockGetSpawnEnv = sandbox . stub ( ResolveEnvModule , 'getSpawnEnv' ) . callsFake (
302
298
sandbox . stub ( ) . resolves ( {
303
299
AWS_TOOLING_USER_AGENT : 'AWS-Toolkit-For-VSCode/testPluginVersion' ,
@@ -312,6 +308,8 @@ describe('SAM runBuild', () => {
312
308
} )
313
309
314
310
describe ( ':) path' , ( ) => {
311
+ let spyRunInterminal : sinon . SinonSpy
312
+
315
313
beforeEach ( ( ) => {
316
314
mockGetSamCliPath = sandbox
317
315
. stub ( SamUtilsModule , 'getSamCliPathAndVersion' )
@@ -329,6 +327,7 @@ describe('SAM runBuild', () => {
329
327
} ) ,
330
328
} ,
331
329
} )
330
+ spyRunInterminal = sandbox . spy ( ProcessTerminalUtils , 'runInTerminal' )
332
331
mockChildProcessClass = sandbox . stub ( ProcessUtilsModule , 'ChildProcess' ) . returns ( mockSamBuildChildProcess )
333
332
} )
334
333
@@ -337,10 +336,11 @@ describe('SAM runBuild', () => {
337
336
} )
338
337
339
338
const verifyCorrectDependencyCall = ( ) => {
340
- assert ( mockGetSamCliPath . calledOnce )
341
- assert ( mockChildProcessClass . calledOnce )
342
- assert ( mockGetSpawnEnv . calledOnce )
343
- assert ( spyRunInterminal . calledOnce )
339
+ // Prefer count comparison for debugging flakiness
340
+ assert . strictEqual ( mockGetSamCliPath . callCount , 1 )
341
+ assert . strictEqual ( mockChildProcessClass . callCount , 1 )
342
+ assert . strictEqual ( mockGetSpawnEnv . callCount , 1 )
343
+ assert . strictEqual ( spyRunInterminal . callCount , 1 )
344
344
assert . deepEqual ( spyRunInterminal . getCall ( 0 ) . args , [ mockSamBuildChildProcess , 'build' ] )
345
345
}
346
346
@@ -398,7 +398,8 @@ describe('SAM runBuild', () => {
398
398
. build ( )
399
399
400
400
// Invoke sync command from command palette
401
- await runBuild ( )
401
+ // Instead of await runBuild(), prefer this to avoid flakiness due to race condition
402
+ await delayedRunBuild ( )
402
403
403
404
assert . deepEqual ( mockChildProcessClass . getCall ( 0 ) . args , [
404
405
'sam-cli-path' ,
@@ -433,7 +434,8 @@ describe('SAM runBuild', () => {
433
434
projectRoot : projectRoot ,
434
435
}
435
436
436
- await runBuild ( new AppNode ( expectedSamAppLocation ) )
437
+ // Instead of await runBuild(), prefer this to avoid flakiness due to race condition
438
+ await delayedRunBuild ( expectedSamAppLocation )
437
439
438
440
getTestWindow ( )
439
441
. getFirstMessage ( )
@@ -509,7 +511,8 @@ describe('SAM runBuild', () => {
509
511
} )
510
512
. build ( )
511
513
512
- await runBuild ( )
514
+ // Instead of await runBuild(), prefer this to avoid flakiness due to race condition
515
+ await delayedRunBuild ( )
513
516
514
517
assert . deepEqual ( mockChildProcessClass . getCall ( 0 ) . args , [
515
518
'sam-cli-path' ,
@@ -605,14 +608,14 @@ async function runInParallel(samLocation: SamAppLocation): Promise<[SamBuildResu
605
608
}
606
609
607
610
// We add a small delay to avoid the unlikely but possible race condition.
608
- async function delayedRunBuild ( samLocation : SamAppLocation ) : Promise < SamBuildResult > {
611
+ async function delayedRunBuild ( samLocation ? : SamAppLocation ) : Promise < SamBuildResult > {
609
612
return new Promise ( async ( resolve , reject ) => {
610
613
// Add a small delay before returning the build promise
611
614
setTimeout ( ( ) => {
612
615
// Do nothing, just let the delay pass
613
616
} , 20 )
614
617
615
- const buildPromise = runBuild ( new AppNode ( samLocation ) )
618
+ const buildPromise = samLocation ? runBuild ( new AppNode ( samLocation ) ) : runBuild ( )
616
619
buildPromise . then ( resolve ) . catch ( reject )
617
620
} )
618
621
}
0 commit comments