1- import { Testee } from './Testee' ;
1+ import { Testee , timeout } from './Testee' ;
22import { HybridScheduler , Scheduler } from './Scheduler' ;
33import { TestScenario } from './scenario/TestScenario' ;
44
55import { TestbedSpecification } from '../testbeds/TestbedSpecification' ;
6+ import { Reporter , SuiteResults } from './Reporter' ;
67
78export interface Suite {
89
@@ -30,12 +31,15 @@ export class Suite {
3031 public scenarios : TestScenario [ ] = [ ] ;
3132 public testees : Testee [ ] = [ ] ;
3233
33- public constructor ( title : string ) {
34+ public scheduler : Scheduler ;
35+
36+ public constructor ( title : string , scheduler : Scheduler = new HybridScheduler ( ) ) {
3437 this . title = title ;
38+ this . scheduler = scheduler ;
3539 }
3640
37- public testee ( name : string , specification : TestbedSpecification , scheduler : Scheduler = new HybridScheduler ( ) , options : TesteeOptions = { } ) {
38- const testee = new Testee ( name , specification , scheduler , options . timeout ?? 2000 , options . connectionTimout ?? 5000 ) ;
41+ public testee ( name : string , specification : TestbedSpecification , options : TesteeOptions = { } ) {
42+ const testee = new Testee ( name , specification , options . timeout ?? 2000 , options . connectionTimout ?? 5000 ) ;
3943 if ( options . disabled ) {
4044 testee . skipall ( ) ;
4145 }
@@ -61,11 +65,13 @@ export class Framework {
6165
6266 private scheduled : Suite [ ] = [ ] ;
6367
68+ public readonly reporter : Reporter = new Reporter ( ) ;
69+
6470 private constructor ( ) {
6571 }
6672
67- public suite ( title : string ) : Suite {
68- return new Suite ( title ) ;
73+ public suite ( title : string , scheduler : Scheduler = new HybridScheduler ( ) ) : Suite {
74+ return new Suite ( title , scheduler ) ;
6975 }
7076
7177 public suites ( ) : Suite [ ] {
@@ -80,45 +86,84 @@ export class Framework {
8086 return this . outputStyle ;
8187 }
8288
83- public run ( suites : Suite [ ] , cores : number = 1 ) { // todo remove cores
89+ public async sequential ( suites : Suite [ ] ) {
90+ this . scheduled . concat ( suites ) ;
91+ this . reporter . general ( ) ;
92+ const t0 = performance . now ( ) ;
93+ for ( const suite of suites ) {
94+ for ( const testee of suite . testees ) {
95+ const order : TestScenario [ ] = suite . scheduler . sequential ( suite ) ;
96+ const result : SuiteResults = new SuiteResults ( suite , testee ) ;
97+
98+ const first : TestScenario = order [ 0 ] ;
99+ await timeout < Object | void > ( 'Initialize testbed' , testee . connector . timeout , testee . initialize ( first . program , first . args ?? [ ] ) . catch ( ( e : Error ) => result . error = e ) ) ;
100+
101+ await this . runSuite ( result , testee , order ) ;
102+ this . reporter . report ( result ) ;
103+ }
104+ }
105+ const t1 = performance . now ( ) ;
106+ this . reporter . results ( t1 - t0 ) ;
107+ }
108+
109+ public async run ( suites : Suite [ ] ) {
84110 this . scheduled . concat ( suites ) ;
85- suites . forEach ( ( suite : Suite ) => {
86- suite . testees . forEach ( ( testee : Testee ) => {
87- const order : TestScenario [ ] = testee . scheduler . schedule ( suite ) ;
111+ this . reporter . general ( ) ;
112+ const t0 = performance . now ( ) ;
113+ await Promise . all ( suites . map ( async ( suite : Suite ) => {
114+ await Promise . all ( suite . testees . map ( async ( testee : Testee ) => {
115+ const order : TestScenario [ ] = suite . scheduler . sequential ( suite ) ;
116+ const result : SuiteResults = new SuiteResults ( suite , testee ) ;
117+
88118 const first : TestScenario = order [ 0 ] ;
89- before ( 'Initialize testbed' , async function ( ) {
90- this . timeout ( testee . connector . timeout ) ;
91- await testee . initialize ( first . program , first . args ?? [ ] ) . catch ( ( e ) => Promise . reject ( e ) ) ;
92- } ) ;
93-
94- describe ( `${ testee . name } : ${ suite . title } ` , ( ) => {
95- // todo add parallelism
96-
97- // if (!bed.disabled) { // TODO necessary? isn't this done in de test itself?
98- //
99- // after('Shutdown debugger', async function () {
100- // if (bed.describer.instance) {
101- // await bed.connection.kill();
102- // }
103- // });
104- // }
105-
106- order . forEach ( ( test : TestScenario ) => {
107- testee . describe ( test , this . runs ) ;
108- } ) ;
109- } ) ;
110-
111- after ( 'Shutdown testbed' , async function ( ) {
112- await testee . shutdown ( ) ;
113- } ) ;
114- } ) ;
115- } ) ;
119+ await timeout < Object | void > ( 'Initialize testbed' , testee . connector . timeout , testee . initialize ( first . program , first . args ?? [ ] ) . catch ( ( e : Error ) => result . error = e ) ) ;
120+
121+ await this . runSuite ( result , testee , order ) ;
122+ this . reporter . report ( result ) ;
123+ } ) )
124+ } ) )
125+ const t1 = performance . now ( ) ;
126+ this . reporter . results ( t1 - t0 ) ;
127+ }
128+
129+ public async parallel ( suites : Suite [ ] ) {
130+ this . scheduled . concat ( suites ) ;
131+ this . reporter . general ( ) ;
132+ const t0 = performance . now ( ) ;
133+ await Promise . all ( suites . map ( async ( suite : Suite ) => {
134+ const order : TestScenario [ ] [ ] = suite . scheduler . parallel ( suite , suite . testees . length ) ;
135+ await Promise . all ( suite . testees . map ( async ( testee : Testee , i : number ) => {
136+ // console.log(`scheduling on ${testee.name}`)
137+ const result : SuiteResults = new SuiteResults ( suite , testee ) ;
138+
139+ const first : TestScenario = order [ i ] [ 0 ] ;
140+ await timeout < Object | void > ( 'Initialize testbed' , testee . connector . timeout , testee . initialize ( first . program , first . args ?? [ ] ) . catch ( ( e : Error ) => result . error = e ) ) ;
141+
142+ for ( let j = i ; j < order . length ; j += suite . testees . length ) {
143+ await this . runSuite ( result , testee , order [ j ] ) ;
144+ }
145+ this . reporter . report ( result ) ;
146+ } ) )
147+
148+ await Promise . all ( suite . testees . map ( async ( testee : Testee ) => {
149+ await timeout < Object | void > ( 'Shutdown testbed' , testee . timeout , testee . shutdown ( ) ) ;
150+ } ) )
151+ } ) )
152+
153+ const t1 = performance . now ( ) ;
154+ this . reporter . results ( t1 - t0 ) ;
155+ }
156+
157+ private async runSuite ( result : SuiteResults , testee : Testee , order : TestScenario [ ] ) {
158+ for ( const test of order ) {
159+ await testee . describe ( test , result , this . runs ) ;
160+ }
116161 }
117162
118163 // Analyse flakiness
119- public analyse ( suite : Suite [ ] , runs : number = 3 , cores : number = 1 ) {
164+ public analyse ( suite : Suite [ ] , runs : number = 3 ) {
120165 this . runs = runs ;
121- this . run ( suite , cores ) ;
166+ this . run ( suite ) ;
122167 }
123168
124169 public static getImplementation ( ) {
0 commit comments