Skip to content

Commit

Permalink
test: test tty-wrap handle isrefed properly
Browse files Browse the repository at this point in the history
  • Loading branch information
insightfuls authored and Ben Schmidt committed Feb 21, 2017
1 parent 5dcc6a9 commit 18d9be2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
3 changes: 3 additions & 0 deletions test/parallel/test-handle-wrap-isrefed.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,6 @@ function makeAssert(message) {
timer._handle.close(
common.mustCall(() => assert(timer._handle.hasRef(), false)));
}


// see also test/pseudo-tty/test-handle-wrap-isrefed-tty.js
36 changes: 15 additions & 21 deletions test/pseudo-tty/test-handle-wrap-isrefed-tty.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
'use strict';

// see also test/parallel/test-handle-wrap-isrefed.js

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;
}
const assert = makeAssert('hasRef() not working on tty_wrap');

// 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;
}));
const ReadStream = require('tty').ReadStream;
const tty = new ReadStream(0);
const isTTY = process.binding('tty_wrap').isTTY;
assert(isTTY(0), true);
assert(Object.getPrototypeOf(tty._handle).hasOwnProperty('hasRef'), true);
assert(tty._handle.hasRef(), true);
tty.unref();
assert(tty._handle.hasRef(), false);
tty.ref();
assert(tty._handle.hasRef(), true);
tty._handle.close(
common.mustCall(() => assert(tty._handle.hasRef(), false)));
Empty file.

0 comments on commit 18d9be2

Please sign in to comment.