Skip to content

Commit

Permalink
test: refactor test-child-process-spawnsync-maxbuf
Browse files Browse the repository at this point in the history
This commit refactors test-child-process-spawnsync-maxbuf.js,
and adds testing for the case where maxBuffer is Infinity.

PR-URL: #10769
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
cjihrig committed Jan 17, 2017
1 parent 8f3ff98 commit 5b30c4f
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions test/parallel/test-child-process-spawnsync-maxbuf.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict';
require('../common');
const assert = require('assert');

const spawnSync = require('child_process').spawnSync;

const msgOut = 'this is stdout';

// This is actually not os.EOL?
Expand All @@ -14,14 +12,21 @@ const args = [
`console.log("${msgOut}");`
];

const options = {
maxBuffer: 1
};
// Verify that an error is returned if maxBuffer is surpassed.
{
const ret = spawnSync(process.execPath, args, { maxBuffer: 1 });

assert.ok(ret.error, 'maxBuffer should error');
assert.strictEqual(ret.error.errno, 'ENOBUFS');
// We can have buffers larger than maxBuffer because underneath we alloc 64k
// that matches our read sizes.
assert.deepStrictEqual(ret.stdout, msgOutBuf);
}

const ret = spawnSync(process.execPath, args, options);
// Verify that a maxBuffer size of Infinity works.
{
const ret = spawnSync(process.execPath, args, { maxBuffer: Infinity });

assert.ok(ret.error, 'maxBuffer should error');
assert.strictEqual(ret.error.errno, 'ENOBUFS');
// We can have buffers larger than maxBuffer because underneath we alloc 64k
// that matches our read sizes
assert.deepStrictEqual(ret.stdout, msgOutBuf);
assert.ifError(ret.error);
assert.deepStrictEqual(ret.stdout, msgOutBuf);
}

0 comments on commit 5b30c4f

Please sign in to comment.