summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGil Pedersen <git@gpost.dk>2013-08-20 15:53:54 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2013-08-20 17:10:18 +0200
commite04c8a8ee400b6453cdb1133e7dd6791b69c0834 (patch)
tree473efa17fe56d2a9fba63e9face9b47cfc6e8b5a
parent26a8c0c6b8f9ed51a574a0bbaebe95e8f36706d5 (diff)
downloadnode-e04c8a8ee400b6453cdb1133e7dd6791b69c0834.tar.gz
fs: use correct self reference for autoClose test
-rw-r--r--lib/fs.js2
-rw-r--r--test/simple/test-fs-read-stream.js26
2 files changed, 17 insertions, 11 deletions
diff --git a/lib/fs.js b/lib/fs.js
index 00496d9ca..222efd1af 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -1494,7 +1494,7 @@ ReadStream.prototype.open = function() {
var self = this;
fs.open(this.path, this.flags, this.mode, function(er, fd) {
if (er) {
- if (this.autoClose) {
+ if (self.autoClose) {
self.destroy();
}
self.emit('error', er);
diff --git a/test/simple/test-fs-read-stream.js b/test/simple/test-fs-read-stream.js
index 9452f95c6..4d1eebb2c 100644
--- a/test/simple/test-fs-read-stream.js
+++ b/test/simple/test-fs-read-stream.js
@@ -171,10 +171,6 @@ function file7Next(){
});
file7.on('end', function(err) {
assert.equal(file7.data, 'xyz\n');
- process.nextTick(function() {
- assert(file7.closed);
- assert(file7.destroyed);
- });
});
}
@@ -182,10 +178,20 @@ function file7Next(){
var file8 = fs.createReadStream(null, {fd: 13337, autoClose: false });
file8.on('data', function() {});
file8.on('error', common.mustCall(function() {}));
-file8.on('end', function() {
- process.nextTick(function() {
- assert(!file8.closed);
- assert(!file8.destroyed);
- assert(file8.fd);
- });
+
+// Make sure stream is destroyed when file does not exist.
+var file9 = fs.createReadStream('/path/to/file/that/does/not/exist');
+file9.on('data', function() {});
+file9.on('error', common.mustCall(function() {}));
+
+process.on('exit', function() {
+ assert(file7.closed);
+ assert(file7.destroyed);
+
+ assert(!file8.closed);
+ assert(!file8.destroyed);
+ assert(file8.fd);
+
+ assert(!file9.closed);
+ assert(file9.destroyed);
});