From bb6787cb57c4a7ee2d92210fe301bd2c5e08503f Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Mon, 18 Jul 2022 12:24:48 +0100 Subject: [PATCH] test: add check to test-fs-readfile-tostring-fail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/pull/43850 Refs: https://github.com/nodejs/node/issues/43833 Reviewed-By: Luigi Pinca Reviewed-By: Tobias Nießen Reviewed-By: LiviaMedeiros Reviewed-By: Matteo Collina --- test/pummel/test-fs-readfile-tostring-fail.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/pummel/test-fs-readfile-tostring-fail.js b/test/pummel/test-fs-readfile-tostring-fail.js index 1a1e7d62175638..eb12ed3d8c5cc0 100644 --- a/test/pummel/test-fs-readfile-tostring-fail.js +++ b/test/pummel/test-fs-readfile-tostring-fail.js @@ -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') {