@@ -339,17 +339,29 @@ export class BenchmarkRunner {
339
339
if ( this . _client ?. willStartFirstIteration )
340
340
await this . _client . willStartFirstIteration ( iterationCount ) ;
341
341
342
+ try {
343
+ await this . _runMultipleIterations ( ) ;
344
+ } catch ( error ) {
345
+ console . error ( error ) ;
346
+ if ( this . _client ?. handleError ) {
347
+ await this . _client . handleError ( error ) ;
348
+ return ;
349
+ }
350
+ }
351
+
352
+ if ( this . _client ?. didFinishLastIteration )
353
+ await this . _client . didFinishLastIteration ( this . _metrics ) ;
354
+ }
355
+
356
+ async _runMultipleIterations ( ) {
342
357
const iterationStartLabel = "iteration-start" ;
343
358
const iterationEndLabel = "iteration-end" ;
344
- for ( let i = 0 ; i < iterationCount ; i ++ ) {
359
+ for ( let i = 0 ; i < this . _iterationCount ; i ++ ) {
345
360
performance . mark ( iterationStartLabel ) ;
346
361
await this . _runAllSuites ( ) ;
347
362
performance . mark ( iterationEndLabel ) ;
348
363
performance . measure ( `iteration-${ i } ` , iterationStartLabel , iterationEndLabel ) ;
349
364
}
350
-
351
- if ( this . _client ?. didFinishLastIteration )
352
- await this . _client . didFinishLastIteration ( this . _metrics ) ;
353
365
}
354
366
355
367
_removeFrame ( ) {
@@ -402,15 +414,21 @@ export class BenchmarkRunner {
402
414
suites [ j ] = tmp ;
403
415
}
404
416
}
405
-
406
417
performance . mark ( prepareEndLabel ) ;
407
418
performance . measure ( "runner-prepare" , prepareStartLabel , prepareEndLabel ) ;
408
419
409
- for ( const suite of suites ) {
410
- if ( ! suite . disabled )
411
- await this . _runSuite ( suite ) ;
420
+ try {
421
+ for ( const suite of suites ) {
422
+ if ( ! suite . disabled )
423
+ await this . _runSuite ( suite ) ;
424
+ }
425
+
426
+ } finally {
427
+ await this . _finishRunAllSuites ( ) ;
412
428
}
429
+ }
413
430
431
+ async _finishRunAllSuites ( ) {
414
432
const finalizeStartLabel = "runner-finalize-start" ;
415
433
const finalizeEndLabel = "runner-finalize-end" ;
416
434
@@ -423,10 +441,11 @@ export class BenchmarkRunner {
423
441
}
424
442
425
443
async _runSuite ( suite ) {
426
- const suitePrepareStartLabel = `suite-${ suite . name } -prepare-start` ;
427
- const suitePrepareEndLabel = `suite-${ suite . name } -prepare-end` ;
428
- const suiteStartLabel = `suite-${ suite . name } -start` ;
429
- const suiteEndLabel = `suite-${ suite . name } -end` ;
444
+ const suiteName = suite . name ;
445
+ const suitePrepareStartLabel = `suite-${ suiteName } -prepare-start` ;
446
+ const suitePrepareEndLabel = `suite-${ suiteName } -prepare-end` ;
447
+ const suiteStartLabel = `suite-${ suiteName } -start` ;
448
+ const suiteEndLabel = `suite-${ suiteName } -end` ;
430
449
431
450
performance . mark ( suitePrepareStartLabel ) ;
432
451
await this . _prepareSuite ( suite ) ;
@@ -437,8 +456,18 @@ export class BenchmarkRunner {
437
456
await this . _runTestAndRecordResults ( suite , test ) ;
438
457
performance . mark ( suiteEndLabel ) ;
439
458
440
- performance . measure ( `suite-${ suite . name } -prepare` , suitePrepareStartLabel , suitePrepareEndLabel ) ;
441
- performance . measure ( `suite-${ suite . name } ` , suiteStartLabel , suiteEndLabel ) ;
459
+ performance . measure ( `suite-${ suiteName } -prepare` , suitePrepareStartLabel , suitePrepareEndLabel ) ;
460
+ performance . measure ( `suite-${ suiteName } ` , suiteStartLabel , suiteEndLabel ) ;
461
+ this . _validateSuiteTotal ( suiteName ) ;
462
+ }
463
+
464
+ _validateSuiteTotal ( suiteName ) {
465
+ // When the test is fast and the precision is low (for example with Firefox'
466
+ // privacy.resistFingerprinting preference), it's possible that the measured
467
+ // total duration for an entire is 0.
468
+ const suiteTotal = this . _measuredValues . tests [ suiteName ] . total ;
469
+ if ( suiteTotal === 0 )
470
+ throw new Error ( `Got invalid 0-time total for suite ${ suiteName } : ${ suiteTotal } ` ) ;
442
471
}
443
472
444
473
async _prepareSuite ( suite ) {
0 commit comments