Skip to content

Commit

Permalink
test: http2 client operations after destroy
Browse files Browse the repository at this point in the history
PR-URL: #16094
Ref: #14985
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
  • Loading branch information
trivikr authored and targos committed Oct 18, 2017
1 parent 659dd8a commit 8a172cb
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions test/parallel/test-http2-client-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,40 @@ const h2 = require('http2');
);
}

// test destroy before connect
// test destroy before client operations
{
const server = h2.createServer();
server.listen(
0,
common.mustCall(() => {
const client = h2.connect(`http://localhost:${server.address().port}`);

const req = client.request({ ':path': '/' });
const req = client.request();
client.destroy();

req.on('response', common.mustNotCall());
req.resume();

const sessionError = {
type: Error,
code: 'ERR_HTTP2_INVALID_SESSION',
message: 'The session has been destroyed'
};

common.expectsError(() => client.request(), sessionError);
common.expectsError(() => client.settings({}), sessionError);
common.expectsError(() => client.priority(req, {}), sessionError);
common.expectsError(() => client.shutdown(), sessionError);

// Wait for setImmediate call from destroy() to complete
// so that state.destroyed is set to true
setImmediate(() => {
common.expectsError(() => client.request(), sessionError);
common.expectsError(() => client.settings({}), sessionError);
common.expectsError(() => client.priority(req, {}), sessionError);
common.expectsError(() => client.shutdown(), sessionError);
common.expectsError(() => client.rstStream(req), sessionError);
});

req.on(
'end',
common.mustCall(() => {
Expand All @@ -96,28 +117,6 @@ const h2 = require('http2');
);
}

// test destroy before request
{
const server = h2.createServer();
server.listen(
0,
common.mustCall(() => {
const client = h2.connect(`http://localhost:${server.address().port}`);
client.destroy();

assert.throws(
() => client.request({ ':path': '/' }),
common.expectsError({
code: 'ERR_HTTP2_INVALID_SESSION',
message: 'The session has been destroyed'
})
);

server.close();
})
);
}

// test destroy before goaway
{
const server = h2.createServer();
Expand Down

0 comments on commit 8a172cb

Please sign in to comment.