0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-25 08:19:38 +01:00
nodejs/test/parallel/test-child-process-stdio-big-write-end.js
isaacs 3e1b1dd4a9 Remove excessive copyright/license boilerplate
The copyright and license notice is already in the LICENSE file.  There
is no justifiable reason to also require that it be included in every
file, since the individual files are not individually distributed except
as part of the entire package.
2015-01-12 15:30:28 -08:00

59 lines
1.2 KiB
JavaScript

var common = require('../common');
var assert = require('assert');
var BUFSIZE = 1024;
switch (process.argv[2]) {
case undefined:
return parent();
case 'child':
return child();
default:
throw new Error('wtf?');
}
function parent() {
var spawn = require('child_process').spawn;
var child = spawn(process.execPath, [__filename, 'child']);
var sent = 0;
var n = '';
child.stdout.setEncoding('ascii');
child.stdout.on('data', function(c) {
n += c;
});
child.stdout.on('end', function() {
assert.equal(+n, sent);
console.log('ok');
});
// Write until the buffer fills up.
do {
var buf = new Buffer(BUFSIZE);
buf.fill('.');
sent += BUFSIZE;
} while (child.stdin.write(buf));
// then write a bunch more times.
for (var i = 0; i < 100; i++) {
var buf = new Buffer(BUFSIZE);
buf.fill('.');
sent += BUFSIZE;
child.stdin.write(buf);
}
// now end, before it's all flushed.
child.stdin.end();
// now we wait...
}
function child() {
var received = 0;
process.stdin.on('data', function(c) {
received += c.length;
});
process.stdin.on('end', function() {
console.log(received);
});
}