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
PR-URL: #18854
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
trivikr authored and targos committed Mar 30, 2018
1 parent 9a146c6 commit 6bc49f0
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 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.
req.close(8);
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 6bc49f0

Please sign in to comment.