@@ -16,9 +16,10 @@ const logStart = (n) => {
1616 if ( Object . keys ( ready ) . every ( ( k ) => ready [ k ] ) ) bench ( )
1717}
1818const results = [ ]
19+ const benchId = 301
1920
2021const urlTemplate = ( port , string ) => {
21- let url = { host : 'localhost' , port, path : '/hello' }
22+ let url = { host : 'localhost' , port, path : `/bench/ ${ benchId } ` }
2223 return string ? `http://${ url . host } :${ url . port } ${ url . path } ` : url
2324}
2425
@@ -44,27 +45,27 @@ const formatBytes = (bytes) => {
4445// HTTP
4546http . createServer ( ( req , res ) => {
4647 res . setHeader ( 'Content-Type' , 'application/json' )
47- res . end ( JSON . stringify ( { data : 'world' , error : null } ) )
48+ res . end ( JSON . stringify ( { data : ` ${ benchId } ` , error : null } ) )
4849} ) . listen ( ports . http , ( ) => logStart ( 'http' ) )
4950
5051// FASTIFY
51- fastify . get ( '/hello ' , function ( req , reply ) {
52- reply . send ( { data : 'world' , error : null } )
52+ fastify . get ( '/bench/:id ' , function ( req , reply ) {
53+ reply . send ( { data : ` ${ req . params . id } ` , error : null } )
5354} )
5455fastify . listen ( ports . fastify , ( ) => logStart ( 'fastify' ) )
5556
5657// POLKA
57- polka ( ) . get ( '/hello ' , ( req , res ) => {
58- res . end ( JSON . stringify ( { data : 'world' , error : null } ) )
58+ polka ( ) . get ( '/bench/:id ' , ( req , res ) => {
59+ res . end ( JSON . stringify ( { data : ` ${ req . params . id } ` , error : null } ) )
5960} ) . listen ( ports . polka ) . then ( ( ) => logStart ( 'polka' ) )
6061
6162// SCRUD
62- scrud . register ( 'hello ' , { search : ( req , res ) => scrud . sendData ( res , 'world' ) } )
63+ scrud . register ( 'bench ' , { read : ( req , res ) => scrud . sendData ( res , ` ${ req . id } ` ) } )
6364scrud . start ( { port : ports . scrud } ) . then ( ( ) => logStart ( 'scrud' ) )
6465
6566// EXPRESS
66- express ( ) . get ( '/hello ' , ( req , res ) => {
67- res . end ( JSON . stringify ( { data : 'world' , error : null } ) )
67+ express ( ) . get ( '/bench/:id ' , ( req , res ) => {
68+ res . end ( JSON . stringify ( { data : ` ${ req . params . id } ` , error : null } ) )
6869} ) . listen ( ports . express , ( ) => logStart ( 'express' ) )
6970
7071// benchamrks
@@ -82,15 +83,17 @@ const bencher = (title) => new Promise((resolve, reject) => {
8283 } )
8384} )
8485
85- let lastResult
86+ let last = { }
8687const checkConsistency = async ( name ) => {
8788 let port = ports [ name ]
88- let { search } = getScrud ( urlTemplate ( port ) )
89- let tmpRes = await search ( 'hello' , { } )
90- if ( ! tmpRes || ( lastResult && lastResult !== tmpRes ) ) {
91- throw new Error ( `Got inconsistent results from libraries` )
89+ let { read } = getScrud ( urlTemplate ( port ) )
90+ let tmpRes = await read ( 'bench' , benchId )
91+ if ( ! tmpRes || ( last . lib && last . result !== tmpRes ) ) {
92+ let err = new Error ( `Got inconsistent results from libraries` )
93+ err . meta = [ `${ last . lib } - ${ last . result } ` , `${ name } - ${ tmpRes } ` ]
94+ throw err
9295 }
93- lastResult = tmpRes
96+ last = { lib : name , result : tmpRes }
9497}
9598
9699async function bench ( ) {
@@ -100,7 +103,7 @@ async function bench () {
100103 try {
101104 await checkConsistency ( name )
102105 } catch ( ex ) {
103- console . log ( ex )
106+ console . log ( ex , name )
104107 process . exit ( )
105108 }
106109 }
0 commit comments