summaryrefslogtreecommitdiff
path: root/test/parallel/test-http2-session-unref.js
diff options
context:
space:
mode:
authorKelvin Jin <kelvinjin@google.com>2017-12-11 15:05:18 -0800
committerJames M Snell <jasnell@gmail.com>2017-12-28 09:32:54 -0800
commit120ea9b5c480c985dc77846a150008f6092c08d0 (patch)
tree30b44834b7bf1e323e4243151b47d1277e18d731 /test/parallel/test-http2-session-unref.js
parenta3535f3f6f976a430df20953ae2d634ee3e05408 (diff)
downloadandroid-node-v8-120ea9b5c480c985dc77846a150008f6092c08d0.tar.gz
android-node-v8-120ea9b5c480c985dc77846a150008f6092c08d0.tar.bz2
android-node-v8-120ea9b5c480c985dc77846a150008f6092c08d0.zip
http2: implement ref() and unref() on client sessions
PR-URL: https://github.com/nodejs/node/pull/17620 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'test/parallel/test-http2-session-unref.js')
-rw-r--r--test/parallel/test-http2-session-unref.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/parallel/test-http2-session-unref.js b/test/parallel/test-http2-session-unref.js
new file mode 100644
index 0000000000..e765352cdc
--- /dev/null
+++ b/test/parallel/test-http2-session-unref.js
@@ -0,0 +1,53 @@
+'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();
+
+setTimeout(common.mustNotCall(() => {}), 1000).unref();