node/test/parallel/test-http2-session-unref.js
Anatoli Papirovski b8f7f84fc2
test: fix flaky test-http2-session-unref
This test should exit naturally or will timeout on its own,
a separate unrefed timer is not necessary.

PR-URL: https://github.com/nodejs/node/pull/18589
Fixes: https://github.com/nodejs/node/issues/18587
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2018-02-07 14:58:35 +01:00

51 lines
1.3 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.destroy();
client.unref();
}
// unref destroyed client
{
const client = http2.connect(`http://localhost:${port}`, {
createConnection: common.mustCall(() => clientSide)
});
client.destroy();
client.unref();
}
}));
server.emit('connection', serverSide);
server.unref();