Skip to content

Commit

Permalink
test: http2 errors on req.close()
Browse files Browse the repository at this point in the history
Backport-PR-URL: #19579
Backport-PR-URL: #20456
PR-URL: #18854
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
trivikr authored and MylesBorins committed May 15, 2018
1 parent 1ff3544 commit 4dbdb8a
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions test/parallel/test-http2-client-rststream-before-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,38 @@ server.on('stream', (stream) => {
server.listen(0, common.mustCall(() => {
const client = h2.connect(`http://localhost:${server.address().port}`);
const req = client.request();
req.close(1);
const closeCode = 1;

common.expectsError(
() => req.close(2 ** 32),
{
type: RangeError,
code: 'ERR_OUT_OF_RANGE',
message: 'The "code" argument is out of range'
}
);
assert.strictEqual(req.closed, false);

req.close(closeCode, common.mustCall());
assert.strictEqual(req.closed, true);

// make sure that destroy is called
req._destroy = common.mustCall(req._destroy.bind(req));

// second call doesn't do anything
assert.doesNotThrow(() => req.close(8));
// Second call doesn't do anything.
req.close(closeCode + 1);

req.on('close', common.mustCall((code) => {
assert.strictEqual(req.destroyed, true);
assert.strictEqual(code, 1);
assert.strictEqual(code, closeCode);
server.close();
client.close();
}));

req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
type: Error,
message: 'Stream closed with error code 1'
message: `Stream closed with error code ${closeCode}`
}));

req.on('response', common.mustCall());
Expand Down

0 comments on commit 4dbdb8a

Please sign in to comment.