Skip to content

Commit 130bd92

Browse files
Merge master into feature/falcon
2 parents 58bea2e + b097fbf commit 130bd92

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

packages/core/src/test/shared/sam/build.test.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,6 @@ describe('SAM runBuild', () => {
280280
let mockChildProcessClass: sinon.SinonStub
281281
let mockSamBuildChildProcess: sinon.SinonStub
282282

283-
let spyRunInterminal: sinon.SinonSpy
284-
285283
let registry: CloudFormationTemplateRegistry
286284

287285
// Dependency clients
@@ -296,8 +294,6 @@ describe('SAM runBuild', () => {
296294
templateFile = vscode.Uri.file(await testFolder.write('template.yaml', validTemplateData))
297295
await registry.addItem(templateFile)
298296

299-
spyRunInterminal = sandbox.spy(ProcessTerminalUtils, 'runInTerminal')
300-
301297
mockGetSpawnEnv = sandbox.stub(ResolveEnvModule, 'getSpawnEnv').callsFake(
302298
sandbox.stub().resolves({
303299
AWS_TOOLING_USER_AGENT: 'AWS-Toolkit-For-VSCode/testPluginVersion',
@@ -312,6 +308,8 @@ describe('SAM runBuild', () => {
312308
})
313309

314310
describe(':) path', () => {
311+
let spyRunInterminal: sinon.SinonSpy
312+
315313
beforeEach(() => {
316314
mockGetSamCliPath = sandbox
317315
.stub(SamUtilsModule, 'getSamCliPathAndVersion')
@@ -329,6 +327,7 @@ describe('SAM runBuild', () => {
329327
}),
330328
},
331329
})
330+
spyRunInterminal = sandbox.spy(ProcessTerminalUtils, 'runInTerminal')
332331
mockChildProcessClass = sandbox.stub(ProcessUtilsModule, 'ChildProcess').returns(mockSamBuildChildProcess)
333332
})
334333

@@ -337,10 +336,11 @@ describe('SAM runBuild', () => {
337336
})
338337

339338
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)
344344
assert.deepEqual(spyRunInterminal.getCall(0).args, [mockSamBuildChildProcess, 'build'])
345345
}
346346

@@ -398,7 +398,8 @@ describe('SAM runBuild', () => {
398398
.build()
399399

400400
// 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()
402403

403404
assert.deepEqual(mockChildProcessClass.getCall(0).args, [
404405
'sam-cli-path',
@@ -433,7 +434,8 @@ describe('SAM runBuild', () => {
433434
projectRoot: projectRoot,
434435
}
435436

436-
await runBuild(new AppNode(expectedSamAppLocation))
437+
// Instead of await runBuild(), prefer this to avoid flakiness due to race condition
438+
await delayedRunBuild(expectedSamAppLocation)
437439

438440
getTestWindow()
439441
.getFirstMessage()
@@ -509,7 +511,8 @@ describe('SAM runBuild', () => {
509511
})
510512
.build()
511513

512-
await runBuild()
514+
// Instead of await runBuild(), prefer this to avoid flakiness due to race condition
515+
await delayedRunBuild()
513516

514517
assert.deepEqual(mockChildProcessClass.getCall(0).args, [
515518
'sam-cli-path',
@@ -605,14 +608,14 @@ async function runInParallel(samLocation: SamAppLocation): Promise<[SamBuildResu
605608
}
606609

607610
// 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> {
609612
return new Promise(async (resolve, reject) => {
610613
// Add a small delay before returning the build promise
611614
setTimeout(() => {
612615
// Do nothing, just let the delay pass
613616
}, 20)
614617

615-
const buildPromise = runBuild(new AppNode(samLocation))
618+
const buildPromise = samLocation ? runBuild(new AppNode(samLocation)) : runBuild()
616619
buildPromise.then(resolve).catch(reject)
617620
})
618621
}

0 commit comments

Comments
 (0)