| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3befe5d commit 97a3d39
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1030,6 +1030,15 @@ Avoid calling it more than once in an asynchronous context as one call | |||
| 1030 | 1030 | might refresh the temporary directory of a different context, causing | |
| 1031 | 1031 | the test to fail somewhat mysteriously. | |
| 1032 | 1032 | ||
| 1033 | + ### `hasEnoughSpace(size)` | ||
| 1034 | + | ||
| 1035 | + * `size` [\<number>][<number>] Required size, in bytes. | ||
| 1036 | + | ||
| 1037 | + Returns `true` if the available blocks of the file system underlying `path` | ||
| 1038 | + are likely sufficient to hold a single file of `size` bytes. This is useful for | ||
| 1039 | + skipping tests that require hundreds of megabytes or even gigabytes of temporary | ||
| 1040 | + files, but it is inaccurate and susceptible to race conditions. | ||
| 1041 | + | ||
| 1033 | 1042 | ## UDP pair helper | |
| 1034 | 1043 | ||
| 1035 | 1044 | The `common/udppair` module exports a function `makeUDPPair` and a class | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -69,7 +69,13 @@ function onexit(useSpawn) { | |||
| 69 | 69 | } | |
| 70 | 70 | } | |
| 71 | 71 | ||
| 72 | + function hasEnoughSpace(size) { | ||
| 73 | + const { bavail, bsize } = fs.statfsSync(tmpPath); | ||
| 74 | + return bavail >= Math.ceil(size / bsize); | ||
| 75 | + } | ||
| 76 | + | ||
| 72 | 77 | module.exports = { | |
| 73 | 78 | path: tmpPath, | |
| 74 | 79 | refresh, | |
| 80 | + hasEnoughSpace, | ||
| 75 | 81 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -106,17 +106,22 @@ async function doReadAndCancel() { | |||
| 106 | 106 | // Variable taken from https://github.com/nodejs/node/blob/1377163f3351/lib/internal/fs/promises.js#L5 | |
| 107 | 107 | const kIoMaxLength = 2 ** 31 - 1; | |
| 108 | 108 | ||
| 109 | - const newFile = path.resolve(tmpDir, 'dogs-running3.txt'); | ||
| 110 | - await writeFile(newFile, Buffer.from('0')); | ||
| 111 | - await truncate(newFile, kIoMaxLength + 1); | ||
| 112 | - | ||
| 113 | - const fileHandle = await open(newFile, 'r'); | ||
| 114 | - | ||
| 115 | - await assert.rejects(fileHandle.readFile(), { | ||
| 116 | - name: 'RangeError', | ||
| 117 | - code: 'ERR_FS_FILE_TOO_LARGE' | ||
| 118 | - }); | ||
| 119 | - await fileHandle.close(); | ||
| 109 | + if (!tmpdir.hasEnoughSpace(kIoMaxLength)) { | ||
| 110 | + // truncate() will fail with ENOSPC if there is not enough space. | ||
| 111 | + common.printSkipMessage(`Not enough space in ${tmpDir}`); | ||
| 112 | + } else { | ||
| 113 | + const newFile = path.resolve(tmpDir, 'dogs-running3.txt'); | ||
| 114 | + await writeFile(newFile, Buffer.from('0')); | ||
| 115 | + await truncate(newFile, kIoMaxLength + 1); | ||
| 116 | + | ||
| 117 | + const fileHandle = await open(newFile, 'r'); | ||
| 118 | + | ||
| 119 | + await assert.rejects(fileHandle.readFile(), { | ||
| 120 | + name: 'RangeError', | ||
| 121 | + code: 'ERR_FS_FILE_TOO_LARGE' | ||
| 122 | + }); | ||
| 123 | + await fileHandle.close(); | ||
| 124 | + } | ||
| 120 | 125 | } | |
| 121 | 126 | } | |
| 122 | 127 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,21 +52,27 @@ for (const e of fileInfo) { | |||
| 52 | 52 | assert.deepStrictEqual(buf, e.contents); | |
| 53 | 53 | })); | |
| 54 | 54 | } | |
| 55 | - // Test readFile size too large | ||
| 55 | + | ||
| 56 | + // readFile() and readFileSync() should fail if the file is too big. | ||
| 56 | 57 | { | |
| 57 | 58 | const kIoMaxLength = 2 ** 31 - 1; | |
| 58 | 59 | ||
| 59 | - const file = path.join(tmpdir.path, `${prefix}-too-large.txt`); | ||
| 60 | - fs.writeFileSync(file, Buffer.from('0')); | ||
| 61 | - fs.truncateSync(file, kIoMaxLength + 1); | ||
| 60 | + if (!tmpdir.hasEnoughSpace(kIoMaxLength)) { | ||
| 61 | + // truncateSync() will fail with ENOSPC if there is not enough space. | ||
| 62 | + common.printSkipMessage(`Not enough space in ${tmpdir.path}`); | ||
| 63 | + } else { | ||
| 64 | + const file = path.join(tmpdir.path, `${prefix}-too-large.txt`); | ||
| 65 | + fs.writeFileSync(file, Buffer.from('0')); | ||
| 66 | + fs.truncateSync(file, kIoMaxLength + 1); | ||
| 62 | 67 | ||
| 63 | - fs.readFile(file, common.expectsError({ | ||
| 64 | - code: 'ERR_FS_FILE_TOO_LARGE', | ||
| 65 | - name: 'RangeError', | ||
| 66 | - })); | ||
| 67 | - assert.throws(() => { | ||
| 68 | - fs.readFileSync(file); | ||
| 69 | - }, { code: 'ERR_FS_FILE_TOO_LARGE', name: 'RangeError' }); | ||
| 68 | + fs.readFile(file, common.expectsError({ | ||
| 69 | + code: 'ERR_FS_FILE_TOO_LARGE', | ||
| 70 | + name: 'RangeError', | ||
| 71 | + })); | ||
| 72 | + assert.throws(() => { | ||
| 73 | + fs.readFileSync(file); | ||
| 74 | + }, { code: 'ERR_FS_FILE_TOO_LARGE', name: 'RangeError' }); | ||
| 75 | + } | ||
| 70 | 76 | } | |
| 71 | 77 | ||
| 72 | 78 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,10 @@ if (common.isAIX && (Number(cp.execSync('ulimit -f')) * 512) < kStringMaxLength) | |||
| 16 | 16 | const tmpdir = require('../common/tmpdir'); | |
| 17 | 17 | tmpdir.refresh(); | |
| 18 | 18 | ||
| 19 | + if (!tmpdir.hasEnoughSpace(kStringMaxLength)) { | ||
| 20 | + common.skip(`Not enough space in ${tmpdir.path}`); | ||
| 21 | + } | ||
| 22 | + | ||
| 19 | 23 | const file = path.join(tmpdir.path, 'toobig.txt'); | |
| 20 | 24 | const stream = fs.createWriteStream(file, { | |
| 21 | 25 | flags: 'a', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments