Skip to content

test: dispose of filehandles in filehandle.read tests #58543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/parallel/test-fs-read-empty-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ assert.throws(
);

(async () => {
const filehandle = await fsPromises.open(filepath, 'r');
await using filehandle = await fsPromises.open(filepath, 'r');
assert.rejects(
() => filehandle.read(buffer, 0, 1, 0),
{
Expand Down
11 changes: 3 additions & 8 deletions test/parallel/test-fs-read-offset-null.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,25 @@ fs.open(filepath, 'r', common.mustSucceed((fd) => {
}));
}));

let filehandle = null;

// Tests for promises api
(async () => {
filehandle = await fsPromises.open(filepath, 'r');
await using filehandle = await fsPromises.open(filepath, 'r');
const readObject = await filehandle.read(buf, { offset: null });
assert.strictEqual(readObject.buffer[0], 120);
})()
.finally(() => filehandle?.close())
.then(common.mustCall());

// Undocumented: omitted position works the same as position === null
(async () => {
filehandle = await fsPromises.open(filepath, 'r');
await using filehandle = await fsPromises.open(filepath, 'r');
const readObject = await filehandle.read(buf, null, buf.length);
assert.strictEqual(readObject.buffer[0], 120);
})()
.finally(() => filehandle?.close())
.then(common.mustCall());

(async () => {
filehandle = await fsPromises.open(filepath, 'r');
await using filehandle = await fsPromises.open(filepath, 'r');
const readObject = await filehandle.read(buf, null, buf.length, 0);
assert.strictEqual(readObject.buffer[0], 120);
})()
.finally(() => filehandle?.close())
.then(common.mustCall());
Loading