3
3
// ```
4
4
// npm install browser-ui-test
5
5
// ```
6
+
6
7
const fs = require ( "fs" ) ;
7
8
const path = require ( "path" ) ;
8
9
const os = require ( 'os' ) ;
@@ -172,12 +173,14 @@ async function main(argv) {
172
173
files . sort ( ) ;
173
174
174
175
console . log ( `Running ${ files . length } rustdoc-gui tests...` ) ;
176
+
175
177
if ( opts [ "jobs" ] < 1 ) {
176
178
process . setMaxListeners ( files . length + 1 ) ;
177
179
} else {
178
- process . setMaxListeners ( opts [ "jobs" ] ) ;
180
+ process . setMaxListeners ( opts [ "jobs" ] + 1 ) ;
179
181
}
180
- let tests = [ ] ;
182
+
183
+ const tests_queue = [ ] ;
181
184
let results = {
182
185
successful : [ ] ,
183
186
failed : [ ] ,
@@ -187,19 +190,18 @@ async function main(argv) {
187
190
for ( let i = 0 ; i < files . length ; ++ i ) {
188
191
const file_name = files [ i ] ;
189
192
const testPath = path . join ( opts [ "tests_folder" ] , file_name ) ;
190
- tests . push (
191
- runTest ( testPath , options )
193
+ const callback = runTest ( testPath , options )
192
194
. then ( out => {
193
195
const [ output , nb_failures ] = out ;
194
196
results [ nb_failures === 0 ? "successful" : "failed" ] . push ( {
195
197
file_name : file_name ,
196
198
output : output ,
197
199
} ) ;
198
200
if ( nb_failures > 0 ) {
199
- status_bar . erroneous ( )
201
+ status_bar . erroneous ( ) ;
200
202
failed = true ;
201
203
} else {
202
- status_bar . successful ( )
204
+ status_bar . successful ( ) ;
203
205
}
204
206
} )
205
207
. catch ( err => {
@@ -210,13 +212,19 @@ async function main(argv) {
210
212
status_bar . erroneous ( ) ;
211
213
failed = true ;
212
214
} )
213
- ) ;
215
+ . finally ( ( ) => {
216
+ // We now remove the promise from the tests_queue.
217
+ tests_queue . splice ( tests_queue . indexOf ( callback ) , 1 ) ;
218
+ } ) ;
219
+ tests_queue . push ( callback ) ;
214
220
if ( no_headless ) {
215
- await tests [ i ] ;
221
+ await tests_queue [ i ] ;
222
+ } else if ( opts [ "jobs" ] > 0 && tests_queue . length >= opts [ "jobs" ] ) {
223
+ await Promise . race ( tests_queue ) ;
216
224
}
217
225
}
218
- if ( ! no_headless ) {
219
- await Promise . all ( tests ) ;
226
+ if ( ! no_headless && tests_queue . length > 0 ) {
227
+ await Promise . all ( tests_queue ) ;
220
228
}
221
229
status_bar . finish ( ) ;
222
230
0 commit comments