0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-stdin-pipe-large.js
Anna Henningsen 761787be91 test: add test for piping large input from stdin
Check that piping a large chunk of data from `process.stdin`
into `process.stdout` does not lose any data by verifying that
the output has the same size as the input.

This is a regression test for #5927 and fails for the commits
in the range [ace100945..89abe8680).

PR-URL: https://github.com/nodejs/node/pull/5949
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2016-03-30 11:09:42 +02:00

24 lines
616 B
JavaScript

'use strict';
// See https://github.com/nodejs/node/issues/5927
const common = require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn;
if (process.argv[2] === 'child') {
process.stdin.pipe(process.stdout);
return;
}
const child = spawn(process.execPath, [__filename, 'child'], { stdio: 'pipe' });
const expectedBytes = 1024 * 1024;
let readBytes = 0;
child.stdin.end(Buffer.alloc(expectedBytes));
child.stdout.on('data', (chunk) => readBytes += chunk.length);
child.stdout.on('end', common.mustCall(() => {
assert.strictEqual(readBytes, expectedBytes);
}));