@@ -12,11 +12,15 @@ const server = h2.createServer();
12
12
// depending on the OS. The determination is based largely on operating
13
13
// system specific timings
14
14
server . 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
+ } ) ;
20
24
stream . respond ( { } ) ;
21
25
stream . end ( ) ;
22
26
} ) ;
@@ -31,19 +35,18 @@ server.on('listening', common.mustCall(() => {
31
35
const err = new Error ( 'test' ) ;
32
36
req . destroy ( err ) ;
33
37
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' ?
36
40
common . expectsError ( {
37
41
code : 'ERR_HTTP2_STREAM_ERROR' ,
38
42
type : Error ,
39
43
message : 'Stream closed with error code 2'
40
- } ) ;
41
- } else {
44
+ } ) :
42
45
common . expectsError ( {
43
46
type : Error ,
44
47
message : 'test'
45
48
} ) ;
46
- }
49
+ fn ( err ) ;
47
50
} , 2 ) ) ;
48
51
49
52
req . on ( 'streamClosed' , common . mustCall ( ( code ) => {
0 commit comments