Skip to content
Open
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
14 changes: 9 additions & 5 deletions test/parallel/test-filehandle-close.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// Flags: --expose-internals
'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const { internalBinding } = require('internal/test/binding');
const { FileHandle } = require('internal/fs/promises');
const { FileHandle: NativeFileHandle } = internalBinding('fs');

// Test that using FileHandle.close to close an already-closed fd fails
// with EBADF.
// Test that closing a FileHandle with an invalid fd fails with EBADF.
// Use a high invalid fd so background I/O cannot reuse it before close runs.

(async function() {
const fh = await fs.promises.open(__filename);
fs.closeSync(fh.fd);
const fh = common.runWithInvalidFD(
(fd) => new FileHandle(new NativeFileHandle(fd)),
);

await assert.rejects(() => fh.close(), {
code: 'EBADF',
Expand Down
Loading