diff options
author | Ben Schmidt <insightfuls@users.noreply.github.com> | 2016-07-19 13:50:27 +1000 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-02-28 18:44:05 +0100 |
commit | 3c92200d8b5b40c86e69b07d87551c55070c96a5 (patch) | |
tree | a34723079c807e2c73692ce09ff84c681b7326ce /test/pseudo-tty | |
parent | d08836003c579b7321284e8256829ff17a8b4afe (diff) | |
download | node-new-3c92200d8b5b40c86e69b07d87551c55070c96a5.tar.gz |
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')
-rw-r--r-- | test/pseudo-tty/ref_keeps_node_running.js | 27 | ||||
-rw-r--r-- | test/pseudo-tty/ref_keeps_node_running.out | 0 | ||||
-rw-r--r-- | test/pseudo-tty/test-handle-wrap-isrefed-tty.js | 23 | ||||
-rw-r--r-- | test/pseudo-tty/test-handle-wrap-isrefed-tty.out | 0 |
4 files changed, 50 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(); diff --git a/test/pseudo-tty/ref_keeps_node_running.out b/test/pseudo-tty/ref_keeps_node_running.out new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/pseudo-tty/ref_keeps_node_running.out diff --git a/test/pseudo-tty/test-handle-wrap-isrefed-tty.js b/test/pseudo-tty/test-handle-wrap-isrefed-tty.js new file mode 100644 index 0000000000..4baf620096 --- /dev/null +++ b/test/pseudo-tty/test-handle-wrap-isrefed-tty.js @@ -0,0 +1,23 @@ +'use strict'; + +// see also test/parallel/test-handle-wrap-isrefed.js + +const common = require('../common'); +const strictEqual = require('assert').strictEqual; +const ReadStream = require('tty').ReadStream; +const tty = new ReadStream(0); +const isTTY = process.binding('tty_wrap').isTTY; +strictEqual(isTTY(0), true, 'tty_wrap: stdin is not a TTY'); +strictEqual(Object.getPrototypeOf(tty._handle).hasOwnProperty('hasRef'), + true, 'tty_wrap: hasRef() missing'); +strictEqual(tty._handle.hasRef(), + true, 'tty_wrap: not initially refed'); +tty.unref(); +strictEqual(tty._handle.hasRef(), + false, 'tty_wrap: unref() ineffective'); +tty.ref(); +strictEqual(tty._handle.hasRef(), + true, 'tty_wrap: ref() ineffective'); +tty._handle.close(common.mustCall(() => + strictEqual(tty._handle.hasRef(), + false, 'tty_wrap: not unrefed on close'))); diff --git a/test/pseudo-tty/test-handle-wrap-isrefed-tty.out b/test/pseudo-tty/test-handle-wrap-isrefed-tty.out new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/pseudo-tty/test-handle-wrap-isrefed-tty.out |