Skip to content

Commit

Permalink
test: improve test-internal-fs-syncwritestream
Browse files Browse the repository at this point in the history
First One is about, `destroy()` called when already destroyed.
And Second One is about, the behavior when `autoClose=false`
  • Loading branch information
sungpaks committed Aug 31, 2024
1 parent 4c844a2 commit f6d2f5a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/parallel/test-internal-fs-syncwritestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ const filename = tmpdir.resolve('sync-write-stream.txt');
assert.strictEqual(stream.fd, null);
}

// Verify that the callback will be called when already destroy()ed.
{
const fd = fs.openSync(filename, 'w');
const stream = new SyncWriteStream(fd);
const theErr = new Error('my error');
const cb = () => {};

stream.on('close', common.mustCall());
assert.strictEqual(stream.destroy(), stream);
stream.destroy(theErr, common.mustCall(cb));
stream.destroySoon(theErr, common.mustCall(cb));
stream._destroy(theErr, common.mustCall(cb));
}

// Verify that the file is not closed when autoClose=false
{
const fd = fs.openSync(filename, 'w');
const stream = new SyncWriteStream(fd, { autoClose: false });

stream.on('close', common.mustNotCall());
stream._destroy(null, () => {});
assert.strictEqual(stream.closed, false);
}

// Verify that calling end() will also destroy the stream.
{
const fd = fs.openSync(filename, 'w');
Expand Down

0 comments on commit f6d2f5a

Please sign in to comment.