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

40 lines
796 B
JavaScript
Raw Normal View History

'use strict';
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');
child.stdout.on('data', function(chunk) {
2010-03-18 05:00:17 +08:00
count += chunk.length;
});
child.stderr.on('data', function(chunk) {
console.log('stderr: ' + chunk);
2010-03-18 05:00:17 +08:00
});
child.on('close', function() {
// + 1 for \n or + 2 for \r\n on Windows
assert.equal(SIZE + (common.isWindows ? 2 : 1), count);
2010-03-18 05:00:17 +08:00
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);
process.on('exit', function() {
2010-03-18 05:00:17 +08:00
assert.ok(finished);
});