mirror of
https://github.com/nodejs/node.git
synced 2025-05-01 08:42:45 +00:00

PR-URL: https://github.com/nodejs/node/pull/29886 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
59 lines
1.5 KiB
JavaScript
59 lines
1.5 KiB
JavaScript
'use strict';
|
|
// 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 Countdown = require('../common/countdown');
|
|
const makeDuplexPair = require('../common/duplexpair');
|
|
|
|
const server = http2.createServer();
|
|
const { clientSide, serverSide } = makeDuplexPair();
|
|
|
|
const counter = new Countdown(3, () => server.unref());
|
|
|
|
// '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) => {
|
|
counter.dec();
|
|
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);
|