0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 23:43:09 +01:00
nodejs/test/pummel/test-child-process-spawn-loop.js

38 lines
762 B
JavaScript
Raw Normal View History

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