Skip to content

Commit

Permalink
test: add test for piping large input from stdin
Browse files Browse the repository at this point in the history
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 [ace1009..89abe86).

PR-URL: #5949
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
addaleax authored and Myles Borins committed Apr 11, 2016
1 parent c33a23f commit 1994ac0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/parallel/test-stdin-pipe-large.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'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(expectedBytes));

child.stdout.on('data', (chunk) => readBytes += chunk.length);
child.stdout.on('end', common.mustCall(() => {
assert.strictEqual(readBytes, expectedBytes);
}));

0 comments on commit 1994ac0

Please sign in to comment.