@@ -72,19 +72,40 @@ const h2 = require('http2');
72
72
) ;
73
73
}
74
74
75
- // test destroy before connect
75
+ // test destroy before client operations
76
76
{
77
77
const server = h2 . createServer ( ) ;
78
78
server . listen (
79
79
0 ,
80
80
common . mustCall ( ( ) => {
81
81
const client = h2 . connect ( `http://localhost:${ server . address ( ) . port } ` ) ;
82
-
83
- const req = client . request ( { ':path' : '/' } ) ;
82
+ const req = client . request ( ) ;
84
83
client . destroy ( ) ;
85
84
86
85
req . on ( 'response' , common . mustNotCall ( ) ) ;
87
86
req . resume ( ) ;
87
+
88
+ const sessionError = {
89
+ type : Error ,
90
+ code : 'ERR_HTTP2_INVALID_SESSION' ,
91
+ message : 'The session has been destroyed'
92
+ } ;
93
+
94
+ common . expectsError ( ( ) => client . request ( ) , sessionError ) ;
95
+ common . expectsError ( ( ) => client . settings ( { } ) , sessionError ) ;
96
+ common . expectsError ( ( ) => client . priority ( req , { } ) , sessionError ) ;
97
+ common . expectsError ( ( ) => client . shutdown ( ) , sessionError ) ;
98
+
99
+ // Wait for setImmediate call from destroy() to complete
100
+ // so that state.destroyed is set to true
101
+ setImmediate ( ( ) => {
102
+ common . expectsError ( ( ) => client . request ( ) , sessionError ) ;
103
+ common . expectsError ( ( ) => client . settings ( { } ) , sessionError ) ;
104
+ common . expectsError ( ( ) => client . priority ( req , { } ) , sessionError ) ;
105
+ common . expectsError ( ( ) => client . shutdown ( ) , sessionError ) ;
106
+ common . expectsError ( ( ) => client . rstStream ( req ) , sessionError ) ;
107
+ } ) ;
108
+
88
109
req . on (
89
110
'end' ,
90
111
common . mustCall ( ( ) => {
@@ -96,28 +117,6 @@ const h2 = require('http2');
96
117
) ;
97
118
}
98
119
99
- // test destroy before request
100
- {
101
- const server = h2 . createServer ( ) ;
102
- server . listen (
103
- 0 ,
104
- common . mustCall ( ( ) => {
105
- const client = h2 . connect ( `http://localhost:${ server . address ( ) . port } ` ) ;
106
- client . destroy ( ) ;
107
-
108
- assert . throws (
109
- ( ) => client . request ( { ':path' : '/' } ) ,
110
- common . expectsError ( {
111
- code : 'ERR_HTTP2_INVALID_SESSION' ,
112
- message : 'The session has been destroyed'
113
- } )
114
- ) ;
115
-
116
- server . close ( ) ;
117
- } )
118
- ) ;
119
- }
120
-
121
120
// test destroy before goaway
122
121
{
123
122
const server = h2 . createServer ( ) ;
0 commit comments