Skip to content

Commit 1af82f3

Browse files
committed
test: fix buggy getTTYfd() implementation
PR-URL: #17781 Ref: #17781 (comment) Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 40bab30 commit 1af82f3

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

test/sequential/test-async-wrap-getasyncid.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,28 +249,25 @@ if (common.hasCrypto) { // eslint-disable-line crypto-check
249249
// Do our best to grab a tty fd.
250250
function getTTYfd() {
251251
const tty = require('tty');
252-
let tty_fd = 0;
253-
if (!tty.isatty(tty_fd)) tty_fd++;
254-
else if (!tty.isatty(tty_fd)) tty_fd++;
255-
else if (!tty.isatty(tty_fd)) tty_fd++;
256-
else {
252+
let ttyFd = [0, 1, 2].find(tty.isatty);
253+
if (ttyFd === undefined) {
257254
try {
258-
tty_fd = fs.openSync('/dev/tty');
255+
ttyFd = fs.openSync('/dev/tty');
259256
} catch (e) {
260257
// There aren't any tty fd's available to use.
261258
return -1;
262259
}
263260
}
264-
return tty_fd;
261+
return ttyFd;
265262
}
266263

267-
const tty_fd = getTTYfd();
268-
if (tty_fd >= 0) {
264+
const ttyFd = getTTYfd();
265+
if (ttyFd >= 0) {
269266
const tty_wrap = process.binding('tty_wrap');
270267
// fd may still be invalid, so guard against it.
271268
const handle = (() => {
272269
try {
273-
return new tty_wrap.TTY(tty_fd, false);
270+
return new tty_wrap.TTY(ttyFd, false);
274271
} catch (e) {
275272
return null;
276273
}

0 commit comments

Comments
 (0)