mirror of https://github.com/nodejs/node.git
test: fix disabled test-fs-largefile
Add `common.refreshTmpDir()` before using the tmp directory. fs.writeSync no longer requires an integer for the position argument, so change test from `assert.throws()` to `assert.doesNotThrow()`. The test now passes. Because it involves a 5 GB file, we're not going to activate the test, although that is possible if we add checking for appropriate available resources (definitely disk space, likely memory, maybe check that it's a 64-bit OS). PR-URL: https://github.com/nodejs/node/pull/13147 Reviewed-By: James M Snell <jasnell@gmail.com>pull/13206/head
parent
3954ea9f41
commit
bbf74fb87b
|
@ -21,13 +21,17 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const path = require('path'),
|
const fs = require('fs');
|
||||||
fs = require('fs'),
|
const path = require('path');
|
||||||
filepath = path.join(common.tmpDir, 'large.txt'),
|
|
||||||
fd = fs.openSync(filepath, 'w+'),
|
common.refreshTmpDir();
|
||||||
offset = 5 * 1024 * 1024 * 1024, // 5GB
|
|
||||||
message = 'Large File';
|
const filepath = path.join(common.tmpDir, 'large.txt');
|
||||||
|
const fd = fs.openSync(filepath, 'w+');
|
||||||
|
const offset = 5 * 1024 * 1024 * 1024; // 5GB
|
||||||
|
const message = 'Large File';
|
||||||
|
|
||||||
fs.truncateSync(fd, offset);
|
fs.truncateSync(fd, offset);
|
||||||
assert.strictEqual(fs.statSync(filepath).size, offset);
|
assert.strictEqual(fs.statSync(filepath).size, offset);
|
||||||
|
@ -39,17 +43,13 @@ assert.strictEqual(readBuf.toString(), message);
|
||||||
fs.readSync(fd, readBuf, 0, 1, 0);
|
fs.readSync(fd, readBuf, 0, 1, 0);
|
||||||
assert.strictEqual(readBuf[0], 0);
|
assert.strictEqual(readBuf[0], 0);
|
||||||
|
|
||||||
var exceptionRaised = false;
|
assert.doesNotThrow(
|
||||||
try {
|
() => { fs.writeSync(fd, writeBuf, 0, writeBuf.length, 42.000001); }
|
||||||
fs.writeSync(fd, writeBuf, 0, writeBuf.length, 42.000001);
|
);
|
||||||
} catch (err) {
|
|
||||||
console.log(err);
|
|
||||||
exceptionRaised = true;
|
|
||||||
assert.strictEqual(err.message, 'Not an integer');
|
|
||||||
}
|
|
||||||
assert.ok(exceptionRaised);
|
|
||||||
fs.close(fd);
|
fs.close(fd);
|
||||||
|
|
||||||
|
// Normally, we don't clean up tmp files at the end of a test, but we'll make an
|
||||||
|
// exception for a 5 GB file.
|
||||||
process.on('exit', function() {
|
process.on('exit', function() {
|
||||||
fs.unlinkSync(filepath);
|
fs.unlinkSync(filepath);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue