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 ( / I N F O \[ [ ^ \] ] + \] : \d + p r o j e c t s o p e n e d i n \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
+ } ) ;
0 commit comments