Skip to content

Commit caee6e5

Browse files
committed
performance tests updated
1 parent 8eaa42c commit caee6e5

File tree

5 files changed

+189
-2
lines changed

5 files changed

+189
-2
lines changed

vscode/src/extension.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ let nbProcess : ChildProcess | null = null;
7878
let debugPort: number = -1;
7979
let debugHash: string | undefined;
8080
let consoleLog: boolean = !!process.env['ENABLE_CONSOLE_LOG'];
81+
export let extensionContext: ExtensionContext | undefined;
8182

8283
export class NbLanguageClient extends LanguageClient {
8384
private _treeViewService: TreeViewService;
@@ -328,7 +329,7 @@ class InitialPromise extends Promise<NbLanguageClient> {
328329

329330
export function activate(context: ExtensionContext): VSNetBeansAPI {
330331
let log = vscode.window.createOutputChannel(SERVER_NAME);
331-
332+
extensionContext = context;
332333
var clientResolve : (x : NbLanguageClient) => void;
333334
var clientReject : (err : any) => void;
334335

vscode/src/test/constants.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,8 @@ public class App {
195195
System.out.println("Hello, yourProject!");
196196
}
197197
}
198-
`
198+
`
199+
200+
export const OPENJDK_CHECK_FILES_RESOLVES: string[] = [
201+
"src/jdk.javadoc/share/classes/jdk/javadoc/doclet/StandardDoclet.java"
202+
]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
/*
3+
* Copyright (c) 2023, Oracle and/or its affiliates.
4+
*
5+
* Licensed to the Apache Software Foundation (ASF) under one
6+
* or more contributor license agreements. See the NOTICE file
7+
* distributed with this work for additional information
8+
* regarding copyright ownership. The ASF licenses this file
9+
* to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance
11+
* with the License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing,
16+
* software distributed under the License is distributed on an
17+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18+
* KIND, either express or implied. See the License for the
19+
* specific language governing permissions and limitations
20+
* under the License.
21+
*/
22+
import { runTestSuite } from '../../testutils';
23+
24+
export function run(): Promise<void> {
25+
return runTestSuite(__dirname);
26+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import * as assert from 'assert';
2+
import * as fs from 'fs';
3+
import * as path from 'path';
4+
import * as myExtension from '../../../extension';
5+
import { extensions, languages, Uri, window, workspace } from 'vscode';
6+
import { assertWorkspace, openFile, runShellCommand, waitCommandsReady } from '../../testutils';
7+
import { OPENJDK_CHECK_FILES_RESOLVES } from '../../constants';
8+
9+
let lastFileSize = 0;
10+
let count = 0;
11+
const checkSymbolsResolved = (path: string): boolean => {
12+
let d = languages.getDiagnostics(Uri.file(path));
13+
const filterErrorsList = d.filter(el => el.severity == 0);
14+
console.log("Filtered Errors List Length: " + filterErrorsList.length);
15+
return filterErrorsList.length == 0;
16+
}
17+
18+
const checkExtensionLoaded = (path: string): boolean => {
19+
let d = languages.getDiagnostics(Uri.file(path));
20+
return d.length != 0;
21+
}
22+
23+
const pollLogFile = (logFilePath: string) => {
24+
fs.stat(logFilePath, async (err, stats) => {
25+
if (err) {
26+
console.error(`Error reading file stats: ${err.message}`);
27+
return;
28+
}
29+
30+
if (stats.size > lastFileSize) {
31+
fs.createReadStream(logFilePath, {
32+
start: lastFileSize,
33+
end: stats.size
34+
}).on('data', chunk => {
35+
const matches = chunk.toString().match(/INFO \[[^\]]+\]: \d+ projects opened in \d+/g);
36+
count += matches?.length || 0;
37+
});
38+
lastFileSize = stats.size;
39+
}
40+
});
41+
}
42+
43+
const checkIfSymbolsResolved = (path: string, isExtensionLoaded: boolean = false) => {
44+
return new Promise((resolve, reject) => {
45+
let isTaskCompleted = false;
46+
const checkInterval = setInterval(() => {
47+
if (!isExtensionLoaded && checkExtensionLoaded(path)) {
48+
isExtensionLoaded = true;
49+
}
50+
if (isExtensionLoaded && checkSymbolsResolved(path)) {
51+
clearInterval(checkInterval);
52+
if (!isTaskCompleted) {
53+
isTaskCompleted = true;
54+
resolve('Symbols resolved');
55+
}
56+
}
57+
}, 100);
58+
59+
setTimeout(() => {
60+
if (!isTaskCompleted) {
61+
isTaskCompleted = true;
62+
reject(new Error('Symbols did not resolved within the timeout period'));
63+
}
64+
}, 10 * 60 * 1000);
65+
});
66+
}
67+
68+
const checkIfIndexingCompleted = () => {
69+
return new Promise((resolve, reject) => {
70+
let isTaskCompleted = false;
71+
const checkInterval = setInterval(() => {
72+
console.log("Number of times opened projects appeared in log file: " + count);
73+
if (count >= 2) {
74+
clearInterval(checkInterval);
75+
if (!isTaskCompleted) {
76+
isTaskCompleted = true;
77+
resolve('Symbols resolved');
78+
}
79+
}
80+
}, 100);
81+
82+
setTimeout(() => {
83+
if (!isTaskCompleted) {
84+
isTaskCompleted = true;
85+
reject(new Error(`Indexing didn't complete within the timeout period`));
86+
}
87+
}, 10 * 60 * 1000);
88+
});
89+
}
90+
91+
suite('Perfomance Test Suite', function () {
92+
window.showInformationMessage('Start performance tests.');
93+
let folder: string = '';
94+
95+
this.beforeAll(async () => {
96+
window.showInformationMessage('Cleaning up workspace.');
97+
folder = assertWorkspace();
98+
await fs.promises.rmdir(folder, { recursive: true });
99+
await fs.promises.mkdir(folder, { recursive: true });
100+
}).timeout(10000);
101+
102+
test("Performance test on OpenJDK repository", async () => {
103+
const args = ["--depth", 1, "--branch", "jdk-23+25"];
104+
const gitCmd = `git clone ${args.join(' ')} https://github.com/openjdk/jdk.git .`;
105+
await runShellCommand(gitCmd, folder);
106+
107+
await waitCommandsReady();
108+
console.log("Extension Loaded");
109+
try {
110+
assert(myExtension.extensionContext?.storageUri, "extension context is undefined");
111+
const logPath = path.join(myExtension.extensionContext.storageUri.fsPath, 'userdir', 'var', 'log', 'messages.log');
112+
setInterval(() => pollLogFile(logPath), 1000);
113+
const startTime = Date.now();
114+
for await (const [idx, f] of OPENJDK_CHECK_FILES_RESOLVES.entries()) {
115+
const p = path.join(...[folder, ...f.split('/')]);
116+
assert(fs.existsSync(p), "file doesn't exists");
117+
console.log(f);
118+
await openFile(p);
119+
idx == 0 ? await checkIfSymbolsResolved(p) : await checkIfSymbolsResolved(p, true);
120+
}
121+
122+
await checkIfIndexingCompleted();
123+
const endTime = Date.now() - startTime;
124+
console.log("END_TIME: " + endTime);
125+
const extension = extensions.getExtension('oracle.oracle-java');
126+
await workspace.fs.writeFile(
127+
Uri.file(path.join(__dirname,'..',extension?.packageJSON.version)),
128+
new TextEncoder().encode(endTime.toString()));
129+
130+
} catch (err: any) {
131+
throw new Error("Symbols not resolved");
132+
}
133+
}).timeout(3600 * 1000);
134+
135+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
/*
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
*/
20+
export function empty(): any {
21+
}

0 commit comments

Comments
 (0)