0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-http2-session-unref.js
Mathias Buus b60b18379d
http2: destroy the socket properly and add tests
Fix a bug where the socket wasn't being correctly destroyed and
adjust existing tests, as well as add additional tests.

PR-URL: https://github.com/nodejs/node/pull/19852
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>

Co-authored-by: Matteo Collina <matteo.collina@gmail.com>
2018-05-13 19:47:40 +02:00

58 lines
1.4 KiB
JavaScript

'use strict';
// Flags: --expose-internals
// Tests that calling unref() on Http2Session:
// (1) Prevents it from keeping the process alive
// (2) Doesn't crash
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const http2 = require('http2');
const makeDuplexPair = require('../common/duplexpair');
const server = http2.createServer();
const { clientSide, serverSide } = makeDuplexPair();
// 'session' event should be emitted 3 times:
// - the vanilla client
// - the destroyed client
// - manual 'connection' event emission with generic Duplex stream
server.on('session', common.mustCallAtLeast((session) => {
session.unref();
}, 3));
server.listen(0, common.mustCall(() => {
const port = server.address().port;
// unref new client
{
const client = http2.connect(`http://localhost:${port}`);
client.unref();
}
// unref destroyed client
{
const client = http2.connect(`http://localhost:${port}`);
client.on('connect', common.mustCall(() => {
client.destroy();
client.unref();
}));
}
// unref destroyed client
{
const client = http2.connect(`http://localhost:${port}`, {
createConnection: common.mustCall(() => clientSide)
});
client.on('connect', common.mustCall(() => {
client.destroy();
client.unref();
}));
}
}));
server.emit('connection', serverSide);
server.unref();