@@ -6,6 +6,7 @@ import { JsHeapUsage, JsHeapUsageSampler, JsHeapUsageSerialized } from './perf/m
66import { PerfMetricsSampler } from './perf/sampler.js' ;
77import { Result } from './results/result.js' ;
88import { Scenario , TestCase } from './scenarios.js' ;
9+ import { consoleGroup } from './util/console.js' ;
910import { WebVitals , WebVitalsCollector } from './vitals/index.js' ;
1011
1112const cpuThrottling = 4 ;
@@ -55,37 +56,38 @@ export class MetricsCollector {
5556
5657 public async execute ( testCase : TestCase ) : Promise < Result > {
5758 console . log ( `Executing test case ${ testCase . name } ` ) ;
58- console . group ( ) ;
59- for ( let i = 1 ; i <= testCase . tries ; i ++ ) {
60- const aResults = await this . _collect ( 'A' , testCase . a , testCase . runs ) ;
61- const bResults = await this . _collect ( 'B' , testCase . b , testCase . runs ) ;
62- if ( await testCase . test ( aResults , bResults ) ) {
63- console . groupEnd ( ) ;
64- console . log ( `Test case ${ testCase . name } passed on try ${ i } /${ testCase . tries } ` ) ;
65- return new Result ( testCase . name , cpuThrottling , networkConditions , aResults , bResults ) ;
66- } else if ( i != testCase . tries ) {
67- console . log ( `Test case ${ testCase . name } failed on try ${ i } /${ testCase . tries } ` ) ;
68- } else {
69- console . groupEnd ( ) ;
70- console . error ( `Test case ${ testCase . name } failed` ) ;
71- }
72- }
73- throw `Test case execution ${ testCase . name } failed after ${ testCase . tries } tries.` ;
59+ return consoleGroup ( async ( ) => {
60+ const aResults = await this . _collect ( testCase , 'A' , testCase . a ) ;
61+ const bResults = await this . _collect ( testCase , 'B' , testCase . b ) ;
62+ return new Result ( testCase . name , cpuThrottling , networkConditions , aResults , bResults ) ;
63+ } ) ;
7464 }
7565
76- private async _collect ( name : string , scenario : Scenario , runs : number ) : Promise < Metrics [ ] > {
77- const label = `Scenario ${ name } data collection (total ${ runs } runs)` ;
78- console . time ( label ) ;
79- const results : Metrics [ ] = [ ] ;
80- for ( let run = 0 ; run < runs ; run ++ ) {
81- const innerLabel = `Scenario ${ name } data collection, run ${ run } /${ runs } ` ;
82- console . time ( innerLabel ) ;
83- results . push ( await this . _run ( scenario ) ) ;
84- console . timeEnd ( innerLabel ) ;
66+ private async _collect ( testCase : TestCase , name : string , scenario : Scenario ) : Promise < Metrics [ ] > {
67+ const label = `Scenario ${ name } data collection (total ${ testCase . runs } runs)` ;
68+ for ( let try_ = 1 ; try_ <= testCase . tries ; try_ ++ ) {
69+ console . time ( label ) ;
70+ const results : Metrics [ ] = [ ] ;
71+ for ( let run = 1 ; run <= testCase . runs ; run ++ ) {
72+ const innerLabel = `Scenario ${ name } data collection, run ${ run } /${ testCase . runs } ` ;
73+ console . time ( innerLabel ) ;
74+ results . push ( await this . _run ( scenario ) ) ;
75+ console . timeEnd ( innerLabel ) ;
76+ }
77+ console . timeEnd ( label ) ;
78+ assert . strictEqual ( results . length , testCase . runs ) ;
79+ if ( await testCase . shouldAccept ( results ) ) {
80+ console . log ( `Test case ${ testCase . name } , scenario ${ name } passed on try ${ try_ } /${ testCase . tries } ` ) ;
81+ return results ;
82+ } else if ( try_ != testCase . tries ) {
83+ console . log ( `Test case ${ testCase . name } failed on try ${ try_ } /${ testCase . tries } , retrying` ) ;
84+ } else {
85+ throw `Test case ${ testCase . name } , scenario ${ name } failed after ${ testCase . tries } tries.` ;
86+ }
8587 }
86- console . timeEnd ( label ) ;
87- assert . strictEqual ( results . length , runs ) ;
88- return results ;
88+ // Unreachable code, if configured properly:
89+ console . assert ( testCase . tries >= 1 ) ;
90+ return [ ] ;
8991 }
9092
9193 private async _run ( scenario : Scenario ) : Promise < Metrics > {
0 commit comments