From b3d25136150e8ad3073ef1a9e0cfdd0ccff82b51 Mon Sep 17 00:00:00 2001 From: Kelvin Jin Date: Thu, 21 Dec 2017 12:44:07 -0800 Subject: [PATCH] redo test to use duplex pair instead of PassThrough --- test/parallel/test-http2-session-unref.js | 35 ++++++++++++++--------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/test/parallel/test-http2-session-unref.js b/test/parallel/test-http2-session-unref.js index a069eae75dcf71..e765352cdc615d 100644 --- a/test/parallel/test-http2-session-unref.js +++ b/test/parallel/test-http2-session-unref.js @@ -9,9 +9,10 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); const http2 = require('http2'); -const { PassThrough } = require('stream'); +const makeDuplexPair = require('../common/duplexpair'); const server = http2.createServer(); +const { clientSide, serverSide } = makeDuplexPair(); // 'session' event should be emitted 3 times: // - the vanilla client @@ -25,22 +26,28 @@ server.listen(0, common.mustCall(() => { const port = server.address().port; // unref new client - let client = http2.connect(`http://localhost:${port}`); - client.unref(); + { + const client = http2.connect(`http://localhost:${port}`); + client.unref(); + } // unref destroyed client - client = http2.connect(`http://localhost:${port}`); - client.destroy(); - client.unref(); - - // unref client with generic Duplex stream - client = http2.connect(`http://localhost:${port}`, { - createConnection: common.mustCall(() => PassThrough()) - }); - client.unref(); + { + 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(); -server.emit('connection', PassThrough()); - setTimeout(common.mustNotCall(() => {}), 1000).unref();