diff options
author | Matteo Collina <hello@matteocollina.com> | 2018-01-05 10:41:14 +0100 |
---|---|---|
committer | Matteo Collina <hello@matteocollina.com> | 2018-01-08 09:17:16 +0100 |
commit | acf56be536ee67e3696f3c2b097cfd176d3d76c6 (patch) | |
tree | f4d772ec1d6a55bd17b51fd69adf92c3a25d33a6 /test/parallel/test-fs-write-stream-double-close.js | |
parent | 46f783d74fd3c9a011b30870e11f2194e6d08af4 (diff) | |
download | android-node-v8-acf56be536ee67e3696f3c2b097cfd176d3d76c6.tar.gz android-node-v8-acf56be536ee67e3696f3c2b097cfd176d3d76c6.tar.bz2 android-node-v8-acf56be536ee67e3696f3c2b097cfd176d3d76c6.zip |
fs: guarantee order of callbacks in ws.close
Refactor WriteStream.prototype.close and WriteStream.prototype._destroy
to always call the callback passed to close in order. Protects from
calling .close() without a callback.
Fixes: https://github.com/nodejs/node/issues/17951
See: https://github.com/nodejs/node/pull/15407
PR-URL: https://github.com/nodejs/node/pull/18002
Fixes: https://github.com/nodejs/node/issues/17951
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-fs-write-stream-double-close.js')
-rw-r--r-- | test/parallel/test-fs-write-stream-double-close.js | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/test/parallel/test-fs-write-stream-double-close.js b/test/parallel/test-fs-write-stream-double-close.js index c73c9c7d6a..10ce9077a0 100644 --- a/test/parallel/test-fs-write-stream-double-close.js +++ b/test/parallel/test-fs-write-stream-double-close.js @@ -1,12 +1,45 @@ 'use strict'; const common = require('../common'); +const assert = require('assert'); const fs = require('fs'); const path = require('path'); common.refreshTmpDir(); -const s = fs.createWriteStream(path.join(common.tmpDir, 'rw')); +{ + const s = fs.createWriteStream(path.join(common.tmpDir, 'rw')); -s.close(common.mustCall()); -s.close(common.mustCall()); + s.close(common.mustCall()); + s.close(common.mustCall()); +} + +{ + const s = fs.createWriteStream(path.join(common.tmpDir, 'rw2')); + + let emits = 0; + s.on('close', () => { + emits++; + }); + + s.close(common.mustCall(() => { + assert.strictEqual(emits, 1); + s.close(common.mustCall(() => { + assert.strictEqual(emits, 1); + })); + process.nextTick(() => { + s.close(common.mustCall(() => { + assert.strictEqual(emits, 1); + })); + }); + })); +} + +{ + const s = fs.createWriteStream(path.join(common.tmpDir, 'rw'), { + autoClose: false + }); + + s.close(common.mustCall()); + s.close(common.mustCall()); +} |