Skip to content

Commit

Permalink
test: skip test-fs-largefile if not enough disk space
Browse files Browse the repository at this point in the history
Fixes: nodejs/build#3071

PR-URL: #45339
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Nitzan Uziely <[email protected]>
  • Loading branch information
Trott authored and danielleadams committed Jan 3, 2023
1 parent 913b669 commit 7e0332a
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions test/pummel/test-fs-largefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

0 comments on commit 7e0332a

Please sign in to comment.