Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add two child-process stdio flush tests #7257

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions test/parallel/test-child-process-flush-stdio.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const cp = require('child_process');
const common = require('../common');
const assert = require('assert');
const stream = require('stream');

// Windows' `echo` command is a built-in shell command and not an external
// executable like on *nix
Expand All @@ -24,10 +25,42 @@ function spawnWithReadable() {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
assert.strictEqual(Buffer.concat(buffer).toString().trim(), '123');
spawnWithPipe();
}));
p.stdout.on('readable', function() {
let buf;
while (buf = this.read())
buffer.push(buf);
setImmediate(() => {
let buf;
while (buf = this.read())
buffer.push(buf);
});
});
}

function spawnWithPipe() {
const buffer = [];
const through = new stream.PassThrough();
const p = cp.spawn('seq', [ '36000' ]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the spaces inside the square braces.


const ret = [];
for (let i = 1; i <= 36000; i++) {
ret.push(i);
}

p.on('close', common.mustCall(function(code, signal) {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
assert.strictEqual(Buffer.concat(buffer).toString().trim(), ret.join('\n'));
}));

p.on('exit', common.mustCall(function() {
setImmediate(function() {
through.on('readable', function() {
let buf;
while (buf = this.read())
buffer.push(buf);
});
});
}));

p.stdout.pipe(through);
}