0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-http2-goaway-opaquedata.js
Trivikram Kamat d64e94ba5b test: http2 emitGoAway post shutdown pre destroy
This commit tests use case when emitGoAway is called when client is
shutting down but is not destroyed.

Refs: https://github.com/nodejs/node/issues/14985
PR-URL: https://github.com/nodejs/node/pull/16215
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2017-10-17 10:04:04 +02:00

42 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const http2 = require('http2');
const server = http2.createServer();
const data = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5]);
server.on('stream', common.mustCall((stream) => {
stream.session.shutdown({
errorCode: 1,
opaqueData: data
});
stream.end();
stream.on('error', common.mustCall(common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
type: Error,
message: 'Stream closed with error code 7'
})));
}));
server.listen(0, () => {
const client = http2.connect(`http://localhost:${server.address().port}`);
client.on('goaway', common.mustCall((code, lastStreamID, buf) => {
assert.deepStrictEqual(code, 1);
assert.deepStrictEqual(lastStreamID, 0);
assert.deepStrictEqual(data, buf);
// Call shutdown() here so that emitGoaway calls destroy()
client.shutdown();
server.close();
}));
const req = client.request({ ':path': '/' });
req.resume();
req.on('end', common.mustCall());
req.end();
});