summaryrefslogtreecommitdiff
path: root/test/pseudo-tty/ref_keeps_node_running.js
diff options
context:
space:
mode:
authorBen Schmidt <insightfuls@users.noreply.github.com>2016-07-19 13:50:27 +1000
committerAnna Henningsen <anna@addaleax.net>2017-02-28 18:44:05 +0100
commit3c92200d8b5b40c86e69b07d87551c55070c96a5 (patch)
treea34723079c807e2c73692ce09ff84c681b7326ce /test/pseudo-tty/ref_keeps_node_running.js
parentd08836003c579b7321284e8256829ff17a8b4afe (diff)
downloadandroid-node-v8-3c92200d8b5b40c86e69b07d87551c55070c96a5.tar.gz
android-node-v8-3c92200d8b5b40c86e69b07d87551c55070c96a5.tar.bz2
android-node-v8-3c92200d8b5b40c86e69b07d87551c55070c96a5.zip
tty: add ref() so process.stdin.ref() etc. work
Also squashed from: * test: move tty-wrap isrefed test to pseudo-tty/ * test: test tty-wrap handle isrefed properly * test: improve failure messages in isrefed tests PR-URL: https://github.com/nodejs/node/pull/7360 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: James M Snell <jasnell.gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'test/pseudo-tty/ref_keeps_node_running.js')
-rw-r--r--test/pseudo-tty/ref_keeps_node_running.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/pseudo-tty/ref_keeps_node_running.js b/test/pseudo-tty/ref_keeps_node_running.js
new file mode 100644
index 0000000000..de3c6531ef
--- /dev/null
+++ b/test/pseudo-tty/ref_keeps_node_running.js
@@ -0,0 +1,27 @@
+'use strict';
+require('../common');
+
+const { TTY, isTTY } = process.binding('tty_wrap');
+const strictEqual = require('assert').strictEqual;
+
+strictEqual(isTTY(0), true, 'fd 0 is not a TTY');
+
+const handle = new TTY(0);
+handle.readStart();
+handle.onread = () => {};
+
+function isHandleActive(handle) {
+ return process._getActiveHandles().some((active) => active === handle);
+}
+
+strictEqual(isHandleActive(handle), true, 'TTY handle not initially active');
+
+handle.unref();
+
+strictEqual(isHandleActive(handle), false, 'TTY handle active after unref()');
+
+handle.ref();
+
+strictEqual(isHandleActive(handle), true, 'TTY handle inactive after ref()');
+
+handle.unref();