From 717db1d46af446e1408810467b00a6c0781f7683 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 6 Nov 2022 07:53:18 -0800 Subject: [PATCH] test: skip test-fs-largefile if not enough disk space Fixes: https://github.com/nodejs/build/issues/3071 PR-URL: https://github.com/nodejs/node/pull/45339 Reviewed-By: Yagiz Nizipli Reviewed-By: Nitzan Uziely --- test/pummel/test-fs-largefile.js | 40 +++++++++++++++++++------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/test/pummel/test-fs-largefile.js b/test/pummel/test-fs-largefile.js index 9c2b26782d9c96..7f2630f497b817 100644 --- a/test/pummel/test-fs-largefile.js +++ b/test/pummel/test-fs-largefile.js @@ -29,21 +29,29 @@ const path = require('path'); const tmpdir = require('../common/tmpdir'); tmpdir.refresh(); -const filepath = path.join(tmpdir.path, 'large.txt'); -const fd = fs.openSync(filepath, 'w+'); -const offset = 5 * 1024 * 1024 * 1024; // 5GB -const message = 'Large File'; +try { -fs.ftruncateSync(fd, offset); -assert.strictEqual(fs.statSync(filepath).size, offset); -const writeBuf = Buffer.from(message); -fs.writeSync(fd, writeBuf, 0, writeBuf.length, offset); -const readBuf = Buffer.allocUnsafe(writeBuf.length); -fs.readSync(fd, readBuf, 0, readBuf.length, offset); -assert.strictEqual(readBuf.toString(), message); -fs.readSync(fd, readBuf, 0, 1, 0); -assert.strictEqual(readBuf[0], 0); + const filepath = path.join(tmpdir.path, 'large.txt'); + const fd = fs.openSync(filepath, 'w+'); + const offset = 5 * 1024 * 1024 * 1024; // 5GB + const message = 'Large File'; -// Verify that floating point positions do not throw. -fs.writeSync(fd, writeBuf, 0, writeBuf.length, 42.000001); -fs.close(fd, common.mustCall()); + fs.ftruncateSync(fd, offset); + assert.strictEqual(fs.statSync(filepath).size, offset); + const writeBuf = Buffer.from(message); + fs.writeSync(fd, writeBuf, 0, writeBuf.length, offset); + const readBuf = Buffer.allocUnsafe(writeBuf.length); + fs.readSync(fd, readBuf, 0, readBuf.length, offset); + assert.strictEqual(readBuf.toString(), message); + fs.readSync(fd, readBuf, 0, 1, 0); + assert.strictEqual(readBuf[0], 0); + + // Verify that floating point positions do not throw. + fs.writeSync(fd, writeBuf, 0, writeBuf.length, 42.000001); + fs.close(fd, common.mustCall()); +} catch (e) { + if (e.code !== 'ENOSPC') { + throw e; + } + common.skip('insufficient disk space'); +}