Skip to content

Commit

Permalink
[Code] Reenable lsp_indexer mocha tests and incooporate language filt…
Browse files Browse the repository at this point in the history
…er test cases (elastic#37266) (elastic#37296)
  • Loading branch information
mw-ding authored May 29, 2019
1 parent 11cdfa1 commit 5a66d9b
Showing 1 changed file with 41 additions and 21 deletions.
62 changes: 41 additions & 21 deletions x-pack/plugins/code/server/__tests__/lsp_indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function prepareProject(url: string, p: string) {
});
}

const repoUri = 'github.com/Microsoft/TypeScript-Node-Starter';
const repoUri = 'github.com/elastic/TypeScript-Node-Starter';

const serverOptions = createTestServerOption();

Expand All @@ -73,7 +73,7 @@ function setupEsClientSpy() {
Promise.resolve({
_source: {
[RepositoryGitStatusReservedField]: {
uri: 'github.com/Microsoft/TypeScript-Node-Starter',
uri: repoUri,
progress: WorkerReservedProgress.COMPLETED,
timestamp: new Date(),
cloneProgress: {
Expand Down Expand Up @@ -125,8 +125,7 @@ function setupLsServiceSendRequestSpy(): sinon.SinonSpy {
);
}

// FAILING https://github.com/elastic/kibana/issues/36478
describe.skip('lsp_indexer unit tests', function(this: any) {
describe('lsp_indexer unit tests', function(this: any) {
this.timeout(20000);

// @ts-ignore
Expand All @@ -140,7 +139,7 @@ describe.skip('lsp_indexer unit tests', function(this: any) {
// @ts-ignore
this.timeout(200000);
return await prepareProject(
'https://github.com/Microsoft/TypeScript-Node-Starter.git',
`https://${repoUri}.git`,
path.join(serverOptions.repoPath, repoUri)
);
});
Expand Down Expand Up @@ -172,10 +171,18 @@ describe.skip('lsp_indexer unit tests', function(this: any) {
new RepositoryConfigController(esClient as EsClient)
);

lspservice.sendRequest = setupLsServiceSendRequestSpy();
const lspSendRequestSpy = setupLsServiceSendRequestSpy();
lspservice.sendRequest = lspSendRequestSpy;
const supportLanguageSpy = sinon.stub();

// Setup supported languages, so that unsupported source files won't be
// sent for lsp requests.
supportLanguageSpy.withArgs('javascript').returns(true);
supportLanguageSpy.withArgs('typescript').returns(true);
lspservice.supportLanguage = supportLanguageSpy;

const indexer = new LspIndexer(
'github.com/Microsoft/TypeScript-Node-Starter',
repoUri,
'master',
lspservice,
serverOptions,
Expand All @@ -193,11 +200,13 @@ describe.skip('lsp_indexer unit tests', function(this: any) {
assert.strictEqual(createSpy.callCount, 3);
assert.strictEqual(putAliasSpy.callCount, 3);

// There are 22 files in the repo. 1 file + 1 symbol + 1 reference = 3 objects to
// index for each file. Total doc indexed should be 3 * 22 = 66, which can be
// fitted into a single batch index.
// There are 22 files which are written in supported languages in the repo. 1 file + 1 symbol + 1 reference = 3 objects to
// index for each file. Total doc indexed for these files should be 3 * 22 = 66.
// The rest 158 files will only be indexed for document. So the total number of index
// requests will be 66 + 158 = 224.
assert.ok(bulkSpy.calledOnce);
assert.strictEqual(bulkSpy.getCall(0).args[0].body.length, 66 * 2);
assert.strictEqual(lspSendRequestSpy.callCount, 22);
assert.strictEqual(bulkSpy.getCall(0).args[0].body.length, 224 * 2);
// @ts-ignore
}).timeout(20000);

Expand All @@ -223,7 +232,7 @@ describe.skip('lsp_indexer unit tests', function(this: any) {
lspservice.sendRequest = setupLsServiceSendRequestSpy();

const indexer = new LspIndexer(
'github.com/Microsoft/TypeScript-Node-Starter',
repoUri,
'master',
lspservice,
serverOptions,
Expand Down Expand Up @@ -267,11 +276,19 @@ describe.skip('lsp_indexer unit tests', function(this: any) {
new RepositoryConfigController(esClient as EsClient)
);

lspservice.sendRequest = setupLsServiceSendRequestSpy();
const lspSendRequestSpy = setupLsServiceSendRequestSpy();
lspservice.sendRequest = lspSendRequestSpy;
const supportLanguageSpy = sinon.stub();

// Setup supported languages, so that unsupported source files won't be
// sent for lsp requests.
supportLanguageSpy.withArgs('javascript').returns(true);
supportLanguageSpy.withArgs('typescript').returns(true);
lspservice.supportLanguage = supportLanguageSpy;

const indexer = new LspIndexer(
'github.com/Microsoft/TypeScript-Node-Starter',
'46971a8',
repoUri,
'261557d',
lspservice,
serverOptions,
esClient as EsClient,
Expand All @@ -282,7 +299,7 @@ describe.skip('lsp_indexer unit tests', function(this: any) {
await indexer.start(undefined, {
repoUri: '',
filePath: 'src/public/js/main.ts',
revision: '46971a8',
revision: '261557d',
localRepoPath: '',
});

Expand All @@ -295,12 +312,15 @@ describe.skip('lsp_indexer unit tests', function(this: any) {
assert.strictEqual(createSpy.callCount, 0);
assert.strictEqual(putAliasSpy.callCount, 0);

// There are 22 files in the repo, but only 11 files after the checkpoint.
// 1 file + 1 symbol + 1 reference = 3 objects to index for each file.
// Total doc indexed should be 3 * 11 = 33, which can be fitted into a
// single batch index.
// There are 22 files with supported language in the repo, but only 11
// files after the checkpoint. 1 file + 1 symbol + 1 reference = 3 objects
// to index for each file. Total doc indexed for these files should be
// 3 * 11 = 33. Also there are 15 files without supported language. Only one
// document will be index for these files. So total index requests would be
// 33 + 15 = 48.
assert.ok(bulkSpy.calledOnce);
assert.strictEqual(bulkSpy.getCall(0).args[0].body.length, 33 * 2);
assert.strictEqual(lspSendRequestSpy.callCount, 11);
assert.strictEqual(bulkSpy.getCall(0).args[0].body.length, 48 * 2);
// @ts-ignore
}).timeout(20000);
});

0 comments on commit 5a66d9b

Please sign in to comment.