@@ -12,11 +12,15 @@ const server = h2.createServer();
1212// depending on the OS. The determination is based largely on operating
1313// system specific timings
1414server . on ( 'stream' , ( stream ) => {
15- stream . on ( 'error' , common . expectsError ( {
16- code : 'ERR_HTTP2_STREAM_ERROR' ,
17- type : Error ,
18- message : 'Stream closed with error code 2'
19- } ) ) ;
15+ // Do not wrap in a must call or use common.expectsError (which now uses
16+ // must call). The error may or may not be reported depending on operating
17+ // system specific timings.
18+ stream . on ( 'error' , ( err ) => {
19+ if ( err ) {
20+ assert . strictEqual ( err . code , 'ERR_HTTP2_STREAM_ERROR' ) ;
21+ assert . strictEqual ( err . message , 'Stream closed with error code 2' ) ;
22+ }
23+ } ) ;
2024 stream . respond ( { } ) ;
2125 stream . end ( ) ;
2226} ) ;
@@ -31,19 +35,18 @@ server.on('listening', common.mustCall(() => {
3135 const err = new Error ( 'test' ) ;
3236 req . destroy ( err ) ;
3337
34- req . on ( 'error' , common . mustCall ( ( e ) => {
35- if ( e . code === 'ERR_HTTP2_STREAM_ERROR' ) {
38+ req . on ( 'error' , common . mustCall ( ( err ) => {
39+ const fn = err . code === 'ERR_HTTP2_STREAM_ERROR' ?
3640 common . expectsError ( {
3741 code : 'ERR_HTTP2_STREAM_ERROR' ,
3842 type : Error ,
3943 message : 'Stream closed with error code 2'
40- } ) ;
41- } else {
44+ } ) :
4245 common . expectsError ( {
4346 type : Error ,
4447 message : 'test'
4548 } ) ;
46- }
49+ fn ( err ) ;
4750 } , 2 ) ) ;
4851
4952 req . on ( 'streamClosed' , common . mustCall ( ( code ) => {
0 commit comments