Skip to content
Permalink
Browse files
test: add check to test-fs-readfile-tostring-fail
Check that all of the bytes were written to the temporary file before
reading it to catch the case where there is insufficient disk space.

PR-URL: #43850
Refs: #43833
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
richardlau authored and danielleadams committed Jul 26, 2022
1 parent bb5511e commit bb6787cb57c4a7ee2d92210fe301bd2c5e08503f
Showing 1 changed file with 5 additions and 1 deletion.
@@ -25,13 +25,17 @@ stream.on('error', (err) => { throw err; });

const size = kStringMaxLength / 200;
const a = Buffer.alloc(size, 'a');
let expectedSize = 0;

for (let i = 0; i < 201; i++) {
stream.write(a);
stream.write(a, (err) => { assert.ifError(err); });
expectedSize += a.length;
}

stream.end();
stream.on('finish', common.mustCall(function() {
assert.strictEqual(stream.bytesWritten, expectedSize,
`${stream.bytesWritten} bytes written (expected ${expectedSize} bytes).`);
fs.readFile(file, 'utf8', common.mustCall(function(err, buf) {
assert.ok(err instanceof Error);
if (err.message !== 'Array buffer allocation failed') {

0 comments on commit bb6787c

Please sign in to comment.