summaryrefslogtreecommitdiff
path: root/test/pseudo-tty/test-readable-tty-keepalive.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/pseudo-tty/test-readable-tty-keepalive.js')
-rw-r--r--test/pseudo-tty/test-readable-tty-keepalive.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/pseudo-tty/test-readable-tty-keepalive.js b/test/pseudo-tty/test-readable-tty-keepalive.js
new file mode 100644
index 0000000000..4cf0b9fb29
--- /dev/null
+++ b/test/pseudo-tty/test-readable-tty-keepalive.js
@@ -0,0 +1,29 @@
+'use strict';
+
+const common = require('../common');
+const assert = require('assert');
+
+// This test ensures that Node.js will not ignore tty 'readable' subscribers
+// when it's the only tty subscriber and the only thing keeping event loop alive
+// https://github.com/nodejs/node/issues/20503
+
+process.stdin.setEncoding('utf8');
+
+const expectedInput = ['foo', 'bar', null];
+
+process.stdin.on('readable', common.mustCall(function() {
+ const data = process.stdin.read();
+ assert.strictEqual(data, expectedInput.shift());
+}, 3)); // first 2 data, then end
+
+process.stdin.on('end', common.mustCall());
+
+setTimeout(() => {
+ process.stdin.push('foo');
+ process.nextTick(() => {
+ process.stdin.push('bar');
+ process.nextTick(() => {
+ process.stdin.push(null);
+ });
+ });
+}, 1);