diff options
author | Matteo Collina <hello@matteocollina.com> | 2019-03-15 19:58:42 +0100 |
---|---|---|
committer | Matteo Collina <hello@matteocollina.com> | 2019-03-18 10:30:07 +0100 |
commit | abafd38c8d4e1a280f97ea452688cda54424d185 (patch) | |
tree | b4ee9333cc9d03a26fdf7b5ec6d938cb2a921c8a /test | |
parent | 36101558fd9f8d5079d780930d97eb44bac479c9 (diff) | |
download | android-node-v8-abafd38c8d4e1a280f97ea452688cda54424d185.tar.gz android-node-v8-abafd38c8d4e1a280f97ea452688cda54424d185.tar.bz2 android-node-v8-abafd38c8d4e1a280f97ea452688cda54424d185.zip |
fs: use proper .destroy() implementation for SyncWriteStream
PR-URL: https://github.com/nodejs/node/pull/26690
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-internal-fs-syncwritestream.js | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/test/parallel/test-internal-fs-syncwritestream.js b/test/parallel/test-internal-fs-syncwritestream.js index 49c29e0738..bf4776550b 100644 --- a/test/parallel/test-internal-fs-syncwritestream.js +++ b/test/parallel/test-internal-fs-syncwritestream.js @@ -19,7 +19,6 @@ const filename = path.join(tmpdir.path, 'sync-write-stream.txt'); assert.strictEqual(stream.fd, 1); assert.strictEqual(stream.readable, false); assert.strictEqual(stream.autoClose, true); - assert.strictEqual(stream.listenerCount('end'), 1); } // Verify constructing the instance with specified options. @@ -29,7 +28,6 @@ const filename = path.join(tmpdir.path, 'sync-write-stream.txt'); assert.strictEqual(stream.fd, 1); assert.strictEqual(stream.readable, false); assert.strictEqual(stream.autoClose, false); - assert.strictEqual(stream.listenerCount('end'), 1); } // Verify that the file will be written synchronously. @@ -47,21 +45,28 @@ const filename = path.join(tmpdir.path, 'sync-write-stream.txt'); const fd = fs.openSync(filename, 'w'); const stream = new SyncWriteStream(fd); - stream.on('close', common.mustCall(3)); + stream.on('close', common.mustCall()); + assert.strictEqual(stream.destroy(), stream); + assert.strictEqual(stream.fd, null); +} + +// Verify that the stream will unset the fd after destroySoon(). +{ + const fd = fs.openSync(filename, 'w'); + const stream = new SyncWriteStream(fd); - assert.strictEqual(stream.destroy(), true); + stream.on('close', common.mustCall()); + assert.strictEqual(stream.destroySoon(), stream); assert.strictEqual(stream.fd, null); - assert.strictEqual(stream.destroy(), true); - assert.strictEqual(stream.destroySoon(), true); } -// Verify that the 'end' event listener will also destroy the stream. +// Verify that calling end() will also destroy the stream. { const fd = fs.openSync(filename, 'w'); const stream = new SyncWriteStream(fd); assert.strictEqual(stream.fd, fd); - stream.emit('end'); + stream.end(); assert.strictEqual(stream.fd, null); } |