Skip to content

Commit 8a172cb

Browse files
trivikrtargos
authored andcommitted
test: http2 client operations after destroy
PR-URL: #16094 Ref: #14985 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
1 parent 659dd8a commit 8a172cb

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

test/parallel/test-http2-client-destroy.js

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,40 @@ const h2 = require('http2');
7272
);
7373
}
7474

75-
// test destroy before connect
75+
// test destroy before client operations
7676
{
7777
const server = h2.createServer();
7878
server.listen(
7979
0,
8080
common.mustCall(() => {
8181
const client = h2.connect(`http://localhost:${server.address().port}`);
82-
83-
const req = client.request({ ':path': '/' });
82+
const req = client.request();
8483
client.destroy();
8584

8685
req.on('response', common.mustNotCall());
8786
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+
88109
req.on(
89110
'end',
90111
common.mustCall(() => {
@@ -96,28 +117,6 @@ const h2 = require('http2');
96117
);
97118
}
98119

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-
121120
// test destroy before goaway
122121
{
123122
const server = h2.createServer();

0 commit comments

Comments
 (0)