test: check TTY mode reset on exit

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: https://github.com/nodejs/node/issues/21020
Refs: https://github.com/nodejs/node/pull/20592

PR-URL: https://github.com/nodejs/node/pull/21027
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Anna Henningsen 2018-05-30 11:18:43 +02:00
parent 48a2568f41
commit 7c8eec0648
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
6 changed files with 61 additions and 0 deletions

View File

@ -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);
}

View File

@ -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);
}
}));

View File

@ -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);
}