node/test/pummel/test-child-process-spawn-lo...

38 lines
761 B
JavaScript
Raw Normal View History

2010-12-05 07:20:34 +08:00
var common = require('../common');
var assert = require('assert');
2010-03-18 05:00:17 +08:00
var spawn = require('child_process').spawn;
var SIZE = 1000 * 1024;
var N = 40;
var finished = false;
2010-12-03 09:03:18 +08:00
function doSpawn(i) {
var child = spawn('python', ['-c', 'print ' + SIZE + ' * "C"']);
2010-03-18 05:00:17 +08:00
var count = 0;
child.stdout.setEncoding('ascii');
2010-12-03 09:03:18 +08:00
child.stdout.addListener('data', function(chunk) {
2010-03-18 05:00:17 +08:00
count += chunk.length;
});
2010-12-03 09:03:18 +08:00
child.stderr.addListener('data', function(chunk) {
console.log('stderr: ' + chunk);
2010-03-18 05:00:17 +08:00
});
2010-12-03 09:03:18 +08:00
child.addListener('exit', function() {
2010-03-18 05:00:17 +08:00
assert.equal(SIZE + 1, count); // + 1 for \n
if (i < N) {
2010-12-03 09:03:18 +08:00
doSpawn(i + 1);
2010-03-18 05:00:17 +08:00
} else {
finished = true;
}
});
}
doSpawn(0);
2010-12-03 09:03:18 +08:00
process.addListener('exit', function() {
2010-03-18 05:00:17 +08:00
assert.ok(finished);
});