Skip to content

Commit

Permalink
test: check TTY mode reset on exit
Browse files Browse the repository at this point in the history
Before PR 20592, closing all handles associated with the main
event loop would also mean that `uv_tty_reset_mode()`
can’t function properly because the corresponding FDs have
already been closed.

Add regression tests for this condition.

Refs: #21020
Refs: #20592

PR-URL: #21027
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
addaleax committed Jun 29, 2018
1 parent 9b611d2 commit bcbae88
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/pseudo-tty/test-set-raw-mode-reset-process-exit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';
require('../common');
const child_process = require('child_process');

// Tests that exiting through process.exit() resets the TTY mode.

child_process.spawnSync(process.execPath, [
'-e', 'process.stdin.setRawMode(true); process.exit(0)'
], { stdio: 'inherit' });

const { stdout } = child_process.spawnSync('stty', {
stdio: ['inherit', 'pipe', 'inherit'],
encoding: 'utf8'
});

if (stdout.match(/-echo\b/)) {
console.log(stdout);
}
Empty file.
24 changes: 24 additions & 0 deletions test/pseudo-tty/test-set-raw-mode-reset-signal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';
const common = require('../common');
const child_process = require('child_process');

// Tests that exiting through a catchable signal resets the TTY mode.

const proc = child_process.spawn(process.execPath, [
'-e', 'process.stdin.setRawMode(true); console.log("Y"); while(true) {}'
], { stdio: ['inherit', 'pipe', 'inherit'] });

proc.stdout.on('data', common.mustCall(() => {
proc.kill('SIGINT');
}));

proc.on('exit', common.mustCall(() => {
const { stdout } = child_process.spawnSync('stty', {
stdio: ['inherit', 'pipe', 'inherit'],
encoding: 'utf8'
});

if (stdout.match(/-echo\b/)) {
console.log(stdout);
}
}));
Empty file.
19 changes: 19 additions & 0 deletions test/pseudo-tty/test-set-raw-mode-reset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';
require('../common');
const child_process = require('child_process');

// Tests that exiting through normal means resets the TTY mode.
// Refs: https://github.com/nodejs/node/issues/21020

child_process.spawnSync(process.execPath, [
'-e', 'process.stdin.setRawMode(true)'
], { stdio: 'inherit' });

const { stdout } = child_process.spawnSync('stty', {
stdio: ['inherit', 'pipe', 'inherit'],
encoding: 'utf8'
});

if (stdout.match(/-echo\b/)) {
console.log(stdout);
}
Empty file.

0 comments on commit bcbae88

Please sign in to comment.