From fe48cc5321ce29366a9061369fe42d3f3b83cea4 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Sat, 7 May 2022 07:01:27 +0800 Subject: [PATCH 1/9] test: reduce flakiness of `test-fs-read-position-validation.mjs` --- .../test-fs-read-position-validation.mjs | 101 ++++++------------ .../test-fs-readSync-position-validation.mjs | 80 ++++++++++++++ 2 files changed, 111 insertions(+), 70 deletions(-) create mode 100644 test/parallel/test-fs-readSync-position-validation.mjs diff --git a/test/parallel/test-fs-read-position-validation.mjs b/test/parallel/test-fs-read-position-validation.mjs index bbd4e9ab4176fe..c223c701aaa099 100644 --- a/test/parallel/test-fs-read-position-validation.mjs +++ b/test/parallel/test-fs-read-position-validation.mjs @@ -1,7 +1,8 @@ -import * as common from '../common/index.mjs'; +import '../common/index.mjs'; import * as fixtures from '../common/fixtures.mjs'; import fs from 'fs'; import assert from 'assert'; +import util from 'util'; // This test ensures that "position" argument is correctly validated @@ -11,90 +12,50 @@ const buffer = Buffer.from('xyz\n'); const offset = 0; const length = buffer.byteLength; +const close = util.promisify(fs.close); +const open = util.promisify(fs.open); +const read = util.promisify(fs.read); + // allowedErrors is an array of acceptable internal errors // For example, on some platforms read syscall might return -EFBIG async function testValid(position, allowedErrors = []) { - let fdSync; + let fd; try { - fdSync = fs.openSync(filepath, 'r'); - fs.readSync(fdSync, buffer, offset, length, position); - fs.readSync(fdSync, buffer, { offset, length, position }); - } catch (err) { - if (!allowedErrors.includes(err.code)) { - assert.fail(err); + fd = await open(filepath, 'r'); + if (allowedErrors.length) { + await read(fd, buffer, offset, length, position).catch((err) => { + if (!allowedErrors.includes(err.code)) { + assert.fail(err); + } + }); + await read(fd, { buffer, offset, length, position }).catch((err) => { + if (!allowedErrors.includes(err.code)) { + assert.fail(err); + } + }); + } else { + await read(fd, buffer, offset, length, position); + await read(fd, { buffer, offset, length, position }); } } finally { - if (fdSync) fs.closeSync(fdSync); + if (fd) await close(fd); } - - fs.open(filepath, 'r', common.mustSucceed((fd) => { - try { - if (allowedErrors.length) { - fs.read(fd, buffer, offset, length, position, common.mustCall((err, ...results) => { - if (err && !allowedErrors.includes(err.code)) { - assert.fail(err); - } - })); - fs.read(fd, { buffer, offset, length, position }, common.mustCall((err, ...results) => { - if (err && !allowedErrors.includes(err.code)) { - assert.fail(err); - } - })); - } else { - fs.read(fd, buffer, offset, length, position, common.mustSucceed()); - fs.read(fd, { buffer, offset, length, position }, common.mustSucceed()); - } - } finally { - fs.close(fd, common.mustSucceed()); - } - })); } -async function testInvalid(code, position, internalCatch = false) { - let fdSync; +async function testInvalid(code, position) { + let fd; try { - fdSync = fs.openSync(filepath, 'r'); - assert.throws( - () => fs.readSync(fdSync, buffer, offset, length, position), + fd = await open(filepath, 'r'); + await assert.rejects( + read(fd, buffer, offset, length, position), { code } ); - assert.throws( - () => fs.readSync(fdSync, buffer, { offset, length, position }), + await assert.rejects( + read(fd, { buffer, offset, length, position }), { code } ); } finally { - if (fdSync) fs.closeSync(fdSync); - } - - // Set this flag for catching errors via first argument of callback function - if (internalCatch) { - fs.open(filepath, 'r', common.mustSucceed((fd) => { - try { - fs.read(fd, buffer, offset, length, position, (err, ...results) => { - assert.strictEqual(err.code, code); - }); - fs.read(fd, { buffer, offset, length, position }, (err, ...results) => { - assert.strictEqual(err.code, code); - }); - } finally { - fs.close(fd, common.mustSucceed()); - } - })); - } else { - fs.open(filepath, 'r', common.mustSucceed((fd) => { - try { - assert.throws( - () => fs.read(fd, buffer, offset, length, position, common.mustNotCall()), - { code } - ); - assert.throws( - () => fs.read(fd, { buffer, offset, length, position }, common.mustNotCall()), - { code } - ); - } finally { - fs.close(fd, common.mustSucceed()); - } - })); + if (fd) await close(fd); } } diff --git a/test/parallel/test-fs-readSync-position-validation.mjs b/test/parallel/test-fs-readSync-position-validation.mjs new file mode 100644 index 00000000000000..5cf40ba1b08578 --- /dev/null +++ b/test/parallel/test-fs-readSync-position-validation.mjs @@ -0,0 +1,80 @@ +import '../common/index.mjs'; +import * as fixtures from '../common/fixtures.mjs'; +import fs from 'fs'; +import assert from 'assert'; + +// This test ensures that "position" argument is correctly validated + +const filepath = fixtures.path('x.txt'); + +const buffer = Buffer.from('xyz\n'); +const offset = 0; +const length = buffer.byteLength; + +// allowedErrors is an array of acceptable internal errors +// For example, on some platforms read syscall might return -EFBIG +function testValid(position, allowedErrors = []) { + let fdSync; + try { + fdSync = fs.openSync(filepath, 'r'); + fs.readSync(fdSync, buffer, offset, length, position); + fs.readSync(fdSync, buffer, { offset, length, position }); + } catch (err) { + if (!allowedErrors.includes(err.code)) { + assert.fail(err); + } + } finally { + if (fdSync) fs.closeSync(fdSync); + } +} + +function testInvalid(code, position, internalCatch = false) { + let fdSync; + try { + fdSync = fs.openSync(filepath, 'r'); + assert.throws( + () => fs.readSync(fdSync, buffer, offset, length, position), + { code } + ); + assert.throws( + () => fs.readSync(fdSync, buffer, { offset, length, position }), + { code } + ); + } finally { + if (fdSync) fs.closeSync(fdSync); + } +} + +{ + testValid(undefined); + testValid(null); + testValid(-1); + testValid(-1n); + + testValid(0); + testValid(0n); + testValid(1); + testValid(1n); + testValid(9); + testValid(9n); + testValid(Number.MAX_SAFE_INTEGER, [ 'EFBIG' ]); + + testValid(2n ** 63n - 1n - BigInt(length), [ 'EFBIG' ]); + testInvalid('ERR_OUT_OF_RANGE', 2n ** 63n); + + // TODO(LiviaMedeiros): test `2n ** 63n - BigInt(length)` + + testInvalid('ERR_OUT_OF_RANGE', NaN); + testInvalid('ERR_OUT_OF_RANGE', -Infinity); + testInvalid('ERR_OUT_OF_RANGE', Infinity); + testInvalid('ERR_OUT_OF_RANGE', -0.999); + testInvalid('ERR_OUT_OF_RANGE', -(2n ** 64n)); + testInvalid('ERR_OUT_OF_RANGE', Number.MAX_SAFE_INTEGER + 1); + testInvalid('ERR_OUT_OF_RANGE', Number.MAX_VALUE); + + for (const badTypeValue of [ + false, true, '1', Symbol(1), {}, [], () => {}, Promise.resolve(1), + ]) { + testInvalid('ERR_INVALID_ARG_TYPE', badTypeValue); + } +} From 21a0db5c69d451d19c984834f7cbf262118c5d00 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Sat, 7 May 2022 17:14:45 +0800 Subject: [PATCH 2/9] squash: adjust promisification --- .../test-fs-read-position-validation.mjs | 87 ++++++++++--------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/test/parallel/test-fs-read-position-validation.mjs b/test/parallel/test-fs-read-position-validation.mjs index c223c701aaa099..630048b0531edd 100644 --- a/test/parallel/test-fs-read-position-validation.mjs +++ b/test/parallel/test-fs-read-position-validation.mjs @@ -1,4 +1,4 @@ -import '../common/index.mjs'; +import * as common from '../common/index.mjs'; import * as fixtures from '../common/fixtures.mjs'; import fs from 'fs'; import assert from 'assert'; @@ -12,51 +12,56 @@ const buffer = Buffer.from('xyz\n'); const offset = 0; const length = buffer.byteLength; -const close = util.promisify(fs.close); -const open = util.promisify(fs.open); -const read = util.promisify(fs.read); - // allowedErrors is an array of acceptable internal errors // For example, on some platforms read syscall might return -EFBIG -async function testValid(position, allowedErrors = []) { - let fd; - try { - fd = await open(filepath, 'r'); - if (allowedErrors.length) { - await read(fd, buffer, offset, length, position).catch((err) => { - if (!allowedErrors.includes(err.code)) { - assert.fail(err); - } - }); - await read(fd, { buffer, offset, length, position }).catch((err) => { - if (!allowedErrors.includes(err.code)) { - assert.fail(err); - } - }); - } else { - await read(fd, buffer, offset, length, position); - await read(fd, { buffer, offset, length, position }); +function testValidCb([position, allowedErrors], callback) { + fs.open(filepath, 'r', common.mustSucceed((fd) => { + try { + if (allowedErrors?.length) { + fs.read(fd, buffer, offset, length, position, common.mustCall((err, ...results) => { + if (err && !allowedErrors.includes(err.code)) { + assert.fail(err); + } + })); + fs.read(fd, { buffer, offset, length, position }, common.mustCall((err, ...results) => { + if (err && !allowedErrors.includes(err.code)) { + assert.fail(err); + } + })); + } else { + fs.read(fd, buffer, offset, length, position, common.mustSucceed()); + fs.read(fd, { buffer, offset, length, position }, common.mustSucceed()); + } + } finally { + fs.close(fd, common.mustSucceed(callback)); } - } finally { - if (fd) await close(fd); - } + })); } -async function testInvalid(code, position) { - let fd; - try { - fd = await open(filepath, 'r'); - await assert.rejects( - read(fd, buffer, offset, length, position), - { code } - ); - await assert.rejects( - read(fd, { buffer, offset, length, position }), - { code } - ); - } finally { - if (fd) await close(fd); - } +function testInvalidCb(code, position, callback) { + fs.open(filepath, 'r', common.mustSucceed((fd) => { + try { + assert.throws( + () => fs.read(fd, buffer, offset, length, position, common.mustNotCall()), + { code } + ); + assert.throws( + () => fs.read(fd, { buffer, offset, length, position }, common.mustNotCall()), + { code } + ); + } finally { + fs.close(fd, common.mustSucceed(callback)); + } + })); +} + +// Promisify to reduce flakiness +const testValidArr = util.promisify(testValidCb); +const testInvalid = util.promisify(testInvalidCb); + +// Wrapper to make allowerErrors optional +async function testValid(position, allowedErrors) { + return testValidArr([position, allowedErrors]); } { From e2c07c973732d47d54a024daeef34e3bda215323 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Sat, 7 May 2022 19:19:26 +0800 Subject: [PATCH 3/9] squash: fix typo --- test/parallel/test-fs-read-position-validation.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-fs-read-position-validation.mjs b/test/parallel/test-fs-read-position-validation.mjs index 630048b0531edd..17c48e9f91c072 100644 --- a/test/parallel/test-fs-read-position-validation.mjs +++ b/test/parallel/test-fs-read-position-validation.mjs @@ -59,7 +59,7 @@ function testInvalidCb(code, position, callback) { const testValidArr = util.promisify(testValidCb); const testInvalid = util.promisify(testInvalidCb); -// Wrapper to make allowerErrors optional +// Wrapper to make allowedErrors optional async function testValid(position, allowedErrors) { return testValidArr([position, allowedErrors]); } From d9a88badd34935331adb123622fae49972d8a9f1 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Sat, 7 May 2022 20:55:44 +0800 Subject: [PATCH 4/9] squash: the actual fix: do not close file too early --- .../test-fs-read-position-validation.mjs | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/test/parallel/test-fs-read-position-validation.mjs b/test/parallel/test-fs-read-position-validation.mjs index 17c48e9f91c072..727509e220663f 100644 --- a/test/parallel/test-fs-read-position-validation.mjs +++ b/test/parallel/test-fs-read-position-validation.mjs @@ -14,27 +14,25 @@ const length = buffer.byteLength; // allowedErrors is an array of acceptable internal errors // For example, on some platforms read syscall might return -EFBIG -function testValidCb([position, allowedErrors], callback) { +function testValidCbPositional([position, allowedErrors], callback) { fs.open(filepath, 'r', common.mustSucceed((fd) => { - try { - if (allowedErrors?.length) { - fs.read(fd, buffer, offset, length, position, common.mustCall((err, ...results) => { - if (err && !allowedErrors.includes(err.code)) { - assert.fail(err); - } - })); - fs.read(fd, { buffer, offset, length, position }, common.mustCall((err, ...results) => { - if (err && !allowedErrors.includes(err.code)) { - assert.fail(err); - } - })); - } else { - fs.read(fd, buffer, offset, length, position, common.mustSucceed()); - fs.read(fd, { buffer, offset, length, position }, common.mustSucceed()); + fs.read(fd, buffer, offset, length, position, common.mustCall((err) => { + fs.close(fd, common.mustSucceed(callback)); + if (err && !allowedErrors?.includes(err.code)) { + assert.fail(err); } - } finally { + })); + })); +} + +function testValidCbNamedParams([position, allowedErrors], callback) { + fs.open(filepath, 'r', common.mustSucceed((fd) => { + fs.read(fd, { buffer, offset, length, position }, common.mustCall((err) => { fs.close(fd, common.mustSucceed(callback)); - } + if (err && !allowedErrors?.includes(err.code)) { + assert.fail(err); + } + })); })); } @@ -56,12 +54,14 @@ function testInvalidCb(code, position, callback) { } // Promisify to reduce flakiness -const testValidArr = util.promisify(testValidCb); +const testValidArrPositional = util.promisify(testValidCbPositional); +const testValidArrNamedParams = util.promisify(testValidCbNamedParams); const testInvalid = util.promisify(testInvalidCb); // Wrapper to make allowedErrors optional async function testValid(position, allowedErrors) { - return testValidArr([position, allowedErrors]); + await testValidArrPositional([position, allowedErrors]); + await testValidArrNamedParams([position, allowedErrors]); } { From 90e5cd793928a95b55f66c66893d8ccfc69297ff Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Sat, 7 May 2022 22:38:53 +0800 Subject: [PATCH 5/9] squash: refactor callbacks, add test for buffer[, options] --- .../test-fs-read-position-validation.mjs | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/test/parallel/test-fs-read-position-validation.mjs b/test/parallel/test-fs-read-position-validation.mjs index 727509e220663f..bd25eee4b3364a 100644 --- a/test/parallel/test-fs-read-position-validation.mjs +++ b/test/parallel/test-fs-read-position-validation.mjs @@ -14,25 +14,21 @@ const length = buffer.byteLength; // allowedErrors is an array of acceptable internal errors // For example, on some platforms read syscall might return -EFBIG -function testValidCbPositional([position, allowedErrors], callback) { +function testValidCb([position, allowedErrors], callback) { fs.open(filepath, 'r', common.mustSucceed((fd) => { - fs.read(fd, buffer, offset, length, position, common.mustCall((err) => { - fs.close(fd, common.mustSucceed(callback)); + let callCount = 3; + function handler(err) { + callCount--; if (err && !allowedErrors?.includes(err.code)) { + fs.close(fd, common.mustSucceed()); assert.fail(err); + } else if (callCount === 0) { + fs.close(fd, common.mustSucceed(callback)); } - })); - })); -} - -function testValidCbNamedParams([position, allowedErrors], callback) { - fs.open(filepath, 'r', common.mustSucceed((fd) => { - fs.read(fd, { buffer, offset, length, position }, common.mustCall((err) => { - fs.close(fd, common.mustSucceed(callback)); - if (err && !allowedErrors?.includes(err.code)) { - assert.fail(err); - } - })); + } + fs.read(fd, buffer, offset, length, position, common.mustCall(handler)); + fs.read(fd, { buffer, offset, length, position }, common.mustCall(handler)); + fs.read(fd, buffer, { offset, length, position }, common.mustCall(handler)); })); } @@ -47,6 +43,10 @@ function testInvalidCb(code, position, callback) { () => fs.read(fd, { buffer, offset, length, position }, common.mustNotCall()), { code } ); + assert.throws( + () => fs.read(fd, buffer, { offset, length, position }, common.mustNotCall()), + { code } + ); } finally { fs.close(fd, common.mustSucceed(callback)); } @@ -54,14 +54,12 @@ function testInvalidCb(code, position, callback) { } // Promisify to reduce flakiness -const testValidArrPositional = util.promisify(testValidCbPositional); -const testValidArrNamedParams = util.promisify(testValidCbNamedParams); +const testValidArr = util.promisify(testValidCb); const testInvalid = util.promisify(testInvalidCb); // Wrapper to make allowedErrors optional async function testValid(position, allowedErrors) { - await testValidArrPositional([position, allowedErrors]); - await testValidArrNamedParams([position, allowedErrors]); + await testValidArr([position, allowedErrors]); } { From 45b36261815dd4cd8dd00d7eb512cd4c2e3b1d6a Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Sun, 8 May 2022 00:37:37 +0800 Subject: [PATCH 6/9] squash: refactor promisification --- .../test-fs-read-position-validation.mjs | 84 +++++++++---------- 1 file changed, 39 insertions(+), 45 deletions(-) diff --git a/test/parallel/test-fs-read-position-validation.mjs b/test/parallel/test-fs-read-position-validation.mjs index bd25eee4b3364a..3b1fe47cc645f4 100644 --- a/test/parallel/test-fs-read-position-validation.mjs +++ b/test/parallel/test-fs-read-position-validation.mjs @@ -2,7 +2,6 @@ import * as common from '../common/index.mjs'; import * as fixtures from '../common/fixtures.mjs'; import fs from 'fs'; import assert from 'assert'; -import util from 'util'; // This test ensures that "position" argument is correctly validated @@ -14,52 +13,47 @@ const length = buffer.byteLength; // allowedErrors is an array of acceptable internal errors // For example, on some platforms read syscall might return -EFBIG -function testValidCb([position, allowedErrors], callback) { - fs.open(filepath, 'r', common.mustSucceed((fd) => { - let callCount = 3; - function handler(err) { - callCount--; - if (err && !allowedErrors?.includes(err.code)) { - fs.close(fd, common.mustSucceed()); - assert.fail(err); - } else if (callCount === 0) { - fs.close(fd, common.mustSucceed(callback)); - } - } - fs.read(fd, buffer, offset, length, position, common.mustCall(handler)); - fs.read(fd, { buffer, offset, length, position }, common.mustCall(handler)); - fs.read(fd, buffer, { offset, length, position }, common.mustCall(handler)); - })); -} - -function testInvalidCb(code, position, callback) { - fs.open(filepath, 'r', common.mustSucceed((fd) => { - try { - assert.throws( - () => fs.read(fd, buffer, offset, length, position, common.mustNotCall()), - { code } - ); - assert.throws( - () => fs.read(fd, { buffer, offset, length, position }, common.mustNotCall()), - { code } - ); - assert.throws( - () => fs.read(fd, buffer, { offset, length, position }, common.mustNotCall()), - { code } - ); - } finally { - fs.close(fd, common.mustSucceed(callback)); - } - })); +function testValid(position, allowedErrors = []) { + return new Promise((resolve, reject) => { + fs.open(filepath, 'r', common.mustSucceed((fd) => { + let callCount = 3; + const handler = common.mustCall((err) => { + callCount--; + if (err && !allowedErrors.includes(err.code)) { + fs.close(fd, common.mustSucceed()); + assert.fail(err); + } else if (callCount === 0) { + fs.close(fd, common.mustSucceed(resolve)); + } + }, callCount); + fs.read(fd, buffer, offset, length, position, handler); + fs.read(fd, { buffer, offset, length, position }, handler); + fs.read(fd, buffer, { offset, length, position }, handler); + })); + }); } -// Promisify to reduce flakiness -const testValidArr = util.promisify(testValidCb); -const testInvalid = util.promisify(testInvalidCb); - -// Wrapper to make allowedErrors optional -async function testValid(position, allowedErrors) { - await testValidArr([position, allowedErrors]); +function testInvalid(code, position) { + return new Promise((resolve, reject) => { + fs.open(filepath, 'r', common.mustSucceed((fd) => { + try { + assert.throws( + () => fs.read(fd, buffer, offset, length, position, common.mustNotCall()), + { code } + ); + assert.throws( + () => fs.read(fd, { buffer, offset, length, position }, common.mustNotCall()), + { code } + ); + assert.throws( + () => fs.read(fd, buffer, { offset, length, position }, common.mustNotCall()), + { code } + ); + } finally { + fs.close(fd, common.mustSucceed(resolve)); + } + })); + }); } { From c85e84df535905bfdf61234e70e1b03373259e79 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Sun, 8 May 2022 00:55:13 +0800 Subject: [PATCH 7/9] squash: add explicit async --- test/parallel/test-fs-read-position-validation.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-fs-read-position-validation.mjs b/test/parallel/test-fs-read-position-validation.mjs index 3b1fe47cc645f4..db99bdafd46314 100644 --- a/test/parallel/test-fs-read-position-validation.mjs +++ b/test/parallel/test-fs-read-position-validation.mjs @@ -13,7 +13,7 @@ const length = buffer.byteLength; // allowedErrors is an array of acceptable internal errors // For example, on some platforms read syscall might return -EFBIG -function testValid(position, allowedErrors = []) { +async function testValid(position, allowedErrors = []) { return new Promise((resolve, reject) => { fs.open(filepath, 'r', common.mustSucceed((fd) => { let callCount = 3; @@ -33,7 +33,7 @@ function testValid(position, allowedErrors = []) { }); } -function testInvalid(code, position) { +async function testInvalid(code, position) { return new Promise((resolve, reject) => { fs.open(filepath, 'r', common.mustSucceed((fd) => { try { From f114cbbaa46eb54a0ae3c347fdfb6af1547ebb3b Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Sun, 8 May 2022 01:39:37 +0800 Subject: [PATCH 8/9] squash: reject on errors --- test/parallel/test-fs-read-position-validation.mjs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-fs-read-position-validation.mjs b/test/parallel/test-fs-read-position-validation.mjs index db99bdafd46314..10be65bfafd653 100644 --- a/test/parallel/test-fs-read-position-validation.mjs +++ b/test/parallel/test-fs-read-position-validation.mjs @@ -20,8 +20,7 @@ async function testValid(position, allowedErrors = []) { const handler = common.mustCall((err) => { callCount--; if (err && !allowedErrors.includes(err.code)) { - fs.close(fd, common.mustSucceed()); - assert.fail(err); + fs.close(fd, common.mustSucceed(() => reject(err))); } else if (callCount === 0) { fs.close(fd, common.mustSucceed(resolve)); } @@ -49,8 +48,11 @@ async function testInvalid(code, position) { () => fs.read(fd, buffer, { offset, length, position }, common.mustNotCall()), { code } ); + resolve(); + } catch (err) { + reject(err); } finally { - fs.close(fd, common.mustSucceed(resolve)); + fs.close(fd, common.mustSucceed()); } })); }); From 11a5b35bc63893bede0dc0fcd5de609a19c822d6 Mon Sep 17 00:00:00 2001 From: Livia Medeiros <74449973+LiviaMedeiros@users.noreply.github.com> Date: Mon, 9 May 2022 20:10:20 +0800 Subject: [PATCH 9/9] squash: fix race condition on closing fd Co-authored-by: Antoine du Hamel --- test/parallel/test-fs-read-position-validation.mjs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-fs-read-position-validation.mjs b/test/parallel/test-fs-read-position-validation.mjs index 10be65bfafd653..919a8dd1419903 100644 --- a/test/parallel/test-fs-read-position-validation.mjs +++ b/test/parallel/test-fs-read-position-validation.mjs @@ -20,7 +20,8 @@ async function testValid(position, allowedErrors = []) { const handler = common.mustCall((err) => { callCount--; if (err && !allowedErrors.includes(err.code)) { - fs.close(fd, common.mustSucceed(() => reject(err))); + fs.close(fd, common.mustSucceed()); + reject(err); } else if (callCount === 0) { fs.close(fd, common.mustSucceed(resolve)); }