http2: add test case for goaway

PR-URL: https://github.com/nodejs/node/pull/24054
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Anto Aravinth 2018-11-03 22:13:33 +05:30
parent 27dc74fdd0
commit 7f913293c1

View File

@ -137,3 +137,30 @@ const Countdown = require('../common/countdown');
req.destroy();
}));
}
// test close before connect
{
const server = h2.createServer();
server.on('stream', common.mustNotCall());
server.listen(0, common.mustCall(() => {
const client = h2.connect(`http://localhost:${server.address().port}`);
const socket = client[kSocket];
socket.on('close', common.mustCall(() => {
assert(socket.destroyed);
}));
const req = client.request();
// should throw goaway error
req.on('error', common.expectsError({
code: 'ERR_HTTP2_GOAWAY_SESSION',
type: Error,
message: 'New streams cannot be created after receiving a GOAWAY'
}));
client.close();
req.resume();
req.on('end', common.mustCall());
req.on('close', common.mustCall(() => server.close()));
}));
}