mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
d64e94ba5b
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>
42 lines
1.1 KiB
JavaScript
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();
|
|
|
|
});
|