mirror of https://github.com/lukechilds/node.git
Browse Source
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>v7.x
Ben Schmidt
9 years ago
committed by
Anna Henningsen
8 changed files with 135 additions and 83 deletions
@ -1,33 +0,0 @@ |
|||
'use strict'; |
|||
|
|||
const common = require('../common'); |
|||
const strictEqual = require('assert').strictEqual; |
|||
const spawn = require('child_process').spawn; |
|||
|
|||
function makeAssert(message) { |
|||
return function(actual, expected) { |
|||
strictEqual(actual, expected, message); |
|||
}; |
|||
} |
|||
const assert = makeAssert('hasRef() not working on tty_wrap'); |
|||
|
|||
if (process.argv[2] === 'child') { |
|||
// Test tty_wrap in piped child to guarentee stdin being a TTY.
|
|||
const ReadStream = require('tty').ReadStream; |
|||
const tty = new ReadStream(0); |
|||
assert(Object.getPrototypeOf(tty._handle).hasOwnProperty('hasRef'), true); |
|||
assert(tty._handle.hasRef(), true); |
|||
tty.unref(); |
|||
assert(tty._handle.hasRef(), false); |
|||
tty._handle.close( |
|||
common.mustCall(() => assert(tty._handle.hasRef(), false))); |
|||
return; |
|||
} |
|||
|
|||
// Use spawn so that we can be sure that stdin has a _handle property.
|
|||
// Refs: https://github.com/nodejs/node/pull/5916
|
|||
const proc = spawn(process.execPath, [__filename, 'child'], { stdio: 'pipe' }); |
|||
proc.stderr.pipe(process.stderr); |
|||
proc.on('exit', common.mustCall(function(exitCode) { |
|||
process.exitCode = exitCode; |
|||
})); |
@ -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(); |
@ -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'))); |
Loading…
Reference in new issue