Skip to content

Commit

Permalink
test: add check to test-fs-readfile-tostring-fail
Browse files Browse the repository at this point in the history
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: nodejs#43850
Refs: nodejs#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 Fyko committed Sep 15, 2022
1 parent 91f0322 commit d6de386
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion test/pummel/test-fs-readfile-tostring-fail.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down

0 comments on commit d6de386

Please sign in to comment.