@@ -10,6 +10,8 @@ const os = require('os');
10
10
const { inspect } = require ( 'util' ) ;
11
11
const { Worker } = require ( 'worker_threads' ) ;
12
12
13
+ const workerPath = path . join ( __dirname , 'wpt/worker.js' ) ;
14
+
13
15
function getBrowserProperties ( ) {
14
16
const { node : version } = process . versions ; // e.g. 18.13.0, 20.0.0-nightly202302078e6e215481
15
17
const release = / ^ \d + \. \d + \. \d + $ / . test ( version ) ;
@@ -402,6 +404,29 @@ const kIncomplete = 'incomplete';
402
404
const kUncaught = 'uncaught' ;
403
405
const NODE_UNCAUGHT = 100 ;
404
406
407
+ const limit = ( concurrency ) => {
408
+ let running = 0 ;
409
+ const queue = [ ] ;
410
+
411
+ const execute = async ( fn ) => {
412
+ if ( running < concurrency ) {
413
+ running ++ ;
414
+ try {
415
+ await fn ( ) ;
416
+ } finally {
417
+ running -- ;
418
+ if ( queue . length > 0 ) {
419
+ execute ( queue . shift ( ) ) ;
420
+ }
421
+ }
422
+ } else {
423
+ queue . push ( fn ) ;
424
+ }
425
+ } ;
426
+
427
+ return execute ;
428
+ } ;
429
+
405
430
class WPTRunner {
406
431
constructor ( path ) {
407
432
this . path = path ;
@@ -543,6 +568,8 @@ class WPTRunner {
543
568
544
569
this . inProgress = new Set ( queue . map ( ( spec ) => spec . filename ) ) ;
545
570
571
+ const run = limit ( os . availableParallelism ( ) ) ;
572
+
546
573
for ( const spec of queue ) {
547
574
const testFileName = spec . filename ;
548
575
const content = spec . getContent ( ) ;
@@ -576,15 +603,7 @@ class WPTRunner {
576
603
this . scriptsModifier ?. ( obj ) ;
577
604
scriptsToRun . push ( obj ) ;
578
605
579
- /**
580
- * Example test with no META variant
581
- * https://github.com/nodejs/node/blob/03854f6/test/fixtures/wpt/WebCryptoAPI/sign_verify/hmac.https.any.js#L1-L4
582
- *
583
- * Example test with multiple META variants
584
- * https://github.com/nodejs/node/blob/03854f6/test/fixtures/wpt/WebCryptoAPI/generateKey/successes_RSASSA-PKCS1-v1_5.https.any.js#L1-L9
585
- */
586
- for ( const variant of meta . variant || [ '' ] ) {
587
- const workerPath = path . join ( __dirname , 'wpt/worker.js' ) ;
606
+ const runWorker = async ( variant ) => {
588
607
const worker = new Worker ( workerPath , {
589
608
execArgv : this . flags ,
590
609
workerData : {
@@ -635,6 +654,17 @@ class WPTRunner {
635
654
} ) ;
636
655
637
656
await events . once ( worker , 'exit' ) . catch ( ( ) => { } ) ;
657
+ } ;
658
+
659
+ /**
660
+ * Example test with no META variant
661
+ * https://github.com/nodejs/node/blob/03854f6/test/fixtures/wpt/WebCryptoAPI/sign_verify/hmac.https.any.js#L1-L4
662
+ *
663
+ * Example test with multiple META variants
664
+ * https://github.com/nodejs/node/blob/03854f6/test/fixtures/wpt/WebCryptoAPI/generateKey/successes_RSASSA-PKCS1-v1_5.https.any.js#L1-L9
665
+ */
666
+ for ( const variant of meta . variant || [ '' ] ) {
667
+ run ( ( ) => runWorker ( variant ) ) ;
638
668
}
639
669
}
640
670
0 commit comments