Skip to content

Commit efe25af

Browse files
committed
add filesystem spy
1 parent b8ed1f4 commit efe25af

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

packages/core/src/testInteg/perf/tryInstallLsp.test.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { LspController } from '../../amazonq'
1111
import { fs, getRandomString, globals } from '../../shared'
1212
import { createTestWorkspace } from '../../test/testUtil'
1313
import { performanceTest } from '../../shared/performance/performance'
14+
import { getFsCallsUpperBound } from './utilities'
15+
import { FileSystem } from '../../shared/fs/fs'
1416

1517
// fakeFileContent is matched to fakeQServerContent based on hash.
1618
const fakeHash = '4eb2865c8f40a322aa04e17d8d83bdaa605d6f1cb363af615240a5442a010e0aef66e21bcf4c88f20fabff06efe8a214'
@@ -31,7 +33,7 @@ const fakeNodeContent = {
3133
serverVersion: '1.1.1',
3234
}
3335

34-
function createStubs(numberOfFiles: number, fileSize: number) {
36+
function createStubs(numberOfFiles: number, fileSize: number): sinon.SinonSpiedInstance<FileSystem> {
3537
// Avoid making HTTP request or mocking giant manifest, stub what we need directly from request.
3638
sinon.stub(LspController.prototype, 'fetchManifest')
3739
// Directly feed the runtime specifications.
@@ -41,8 +43,11 @@ function createStubs(numberOfFiles: number, fileSize: number) {
4143
sinon.stub(LspController.prototype, '_download').callsFake(getFakeDownload(numberOfFiles, fileSize))
4244
// Hard code the hash since we are creating files on the spot, whose hashes can't be predicted.
4345
sinon.stub(LspController.prototype, 'getFileSha384').resolves(fakeHash)
44-
// Don't allow tryInstallLsp to move runtimes out of temporary folder.
45-
sinon.stub(fs, 'rename')
46+
const fsSpy = sinon.spy(fs)
47+
fsSpy.rename.restore()
48+
// Don't allow tryInstallLsp to move runtimes out of temporary folder
49+
sinon.stub(fsSpy, 'rename')
50+
return fsSpy
4651
}
4752

4853
/**
@@ -66,7 +71,7 @@ const getFakeDownload = function (numberOfFiles: number, fileSize: number) {
6671
}
6772
}
6873

69-
function performanceTestWrapper(numFiles: number, fileSize: number) {
74+
function performanceTestWrapper(numFiles: number, fileSize: number, message: string) {
7075
return performanceTest(
7176
{
7277
testRuns: 10,
@@ -89,17 +94,18 @@ function performanceTestWrapper(numFiles: number, fileSize: number) {
8994
duration: 15,
9095
},
9196
},
92-
'many small files in zip',
97+
message,
9398
function () {
9499
return {
95100
setup: async () => {
96-
createStubs(numFiles, fileSize)
101+
return createStubs(numFiles, fileSize)
97102
},
98103
execute: async () => {
99104
return await LspController.instance.tryInstallLsp(globals.context)
100105
},
101-
verify: async (_setup: any, result: boolean) => {
106+
verify: async (fsSpy: sinon.SinonSpiedInstance<FileSystem>, result: boolean) => {
102107
assert.ok(result)
108+
assert.ok(getFsCallsUpperBound(fsSpy) <= 6 * numFiles)
103109
},
104110
}
105111
}
@@ -111,7 +117,7 @@ describe('tryInstallLsp', function () {
111117
sinon.restore()
112118
})
113119
describe('performance tests', function () {
114-
performanceTestWrapper(250, 10)
115-
performanceTestWrapper(10, 1000)
120+
performanceTestWrapper(250, 10, '250x10')
121+
performanceTestWrapper(10, 1000, '10x1000')
116122
})
117123
})

0 commit comments

Comments
 (0)