Skip to content

Commit 6d2eb84

Browse files
cjihrigitaloacasas
authored andcommitted
test: refactor test-child-process-spawnsync-maxbuf
This commit refactors test-child-process-spawnsync-maxbuf.js, and adds testing for the case where maxBuffer is Infinity. PR-URL: nodejs#10769 Reviewed-By: James M Snell <[email protected]>
1 parent e4e29ad commit 6d2eb84

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
'use strict';
22
require('../common');
33
const assert = require('assert');
4-
54
const spawnSync = require('child_process').spawnSync;
6-
75
const msgOut = 'this is stdout';
86

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

17-
const options = {
18-
maxBuffer: 1
19-
};
15+
// Verify that an error is returned if maxBuffer is surpassed.
16+
{
17+
const ret = spawnSync(process.execPath, args, { maxBuffer: 1 });
18+
19+
assert.ok(ret.error, 'maxBuffer should error');
20+
assert.strictEqual(ret.error.errno, 'ENOBUFS');
21+
// We can have buffers larger than maxBuffer because underneath we alloc 64k
22+
// that matches our read sizes.
23+
assert.deepStrictEqual(ret.stdout, msgOutBuf);
24+
}
2025

21-
const ret = spawnSync(process.execPath, args, options);
26+
// Verify that a maxBuffer size of Infinity works.
27+
{
28+
const ret = spawnSync(process.execPath, args, { maxBuffer: Infinity });
2229

23-
assert.ok(ret.error, 'maxBuffer should error');
24-
assert.strictEqual(ret.error.errno, 'ENOBUFS');
25-
// We can have buffers larger than maxBuffer because underneath we alloc 64k
26-
// that matches our read sizes
27-
assert.deepStrictEqual(ret.stdout, msgOutBuf);
30+
assert.ifError(ret.error);
31+
assert.deepStrictEqual(ret.stdout, msgOutBuf);
32+
}

0 commit comments

Comments
 (0)