@@ -54,6 +54,35 @@ describe('oha command', () => {
5454} )
5555
5656describe ( 'autocannon load isolation' , ( ) => {
57+ it . each ( [
58+ [ 'transport failures only' , 0 , 20 , 0 , 0 , 20 , 20 ] ,
59+ [ 'mixed responses and failures' , 90 , 10 , 10 , 3 , 100 , 20 ] ,
60+ [ 'responses without failures' , 20 , undefined , undefined , undefined , 20 , 0 ] ,
61+ ] as const ) ( 'counts every completed or failed request: %s' , async ( name , completed , transportErrors , non2xx , timeouts , requests , errors ) => {
62+ const raw = JSON . stringify ( { requests : { total : completed } , errors : transportErrors , non2xx, timeouts } )
63+ const spawn = spyOn ( Bun , 'spawn' ) . mockReturnValue ( {
64+ stdout : new Response ( raw ) . body ,
65+ stderr : new Response ( '' ) . body ,
66+ exited : Promise . resolve ( 0 ) ,
67+ } as unknown as ReturnType < typeof Bun . spawn > )
68+ try {
69+ const result = await DRIVERS . find ( driver => driver . name === 'autocannon' ) ! . run ( {
70+ url : 'http://127.0.0.1:39400/bench/json' ,
71+ method : 'GET' ,
72+ headers : { } ,
73+ connections : 1 ,
74+ warmupSeconds : 0 ,
75+ durationSeconds : 1 ,
76+ } )
77+ expect ( result . requests , name ) . toBe ( requests )
78+ expect ( result . errors , name ) . toBe ( errors )
79+ expect ( result . raw ) . toBe ( raw )
80+ }
81+ finally {
82+ spawn . mockRestore ( )
83+ }
84+ } )
85+
5786 it . each ( [ 0 , 3 ] ) ( 'discards %s seconds of warmup with isolated load settings' , async ( warmupSeconds ) => {
5887 const output = ( requests : number ) => ( {
5988 stdout : new Response ( JSON . stringify ( { requests : { total : requests , average : requests } } ) ) . body ,
0 commit comments