Skip to content

Commit

Permalink
add test case & close event parameter remove
Browse files Browse the repository at this point in the history
  • Loading branch information
younggi committed Jan 29, 2014
1 parent f2b6918 commit 6894f24
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
24 changes: 14 additions & 10 deletions lib/dirty/dirty.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,20 @@ Dirty.prototype.close = function() {
if (!this.path) {
return;
}

this._maybeFlush();

var self = this;
fs.close(this._fdRead, function() {
self.emit('read_close', 0);
});
fs.close(this._fdWrite, function() {
self.emit('write_close', 0);
});

this._maybeFlush();

var self = this;
if (this._fdRead) {
fs.close(this._fdRead, function() {
self.emit('read_close');
});
}
if (this._fdWrite) {
fs.close(this._fdWrite, function() {
self.emit('write_close');
});
}
};

// Called when a dirty connection is instantiated
Expand Down
22 changes: 21 additions & 1 deletion test/test-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,28 @@ function dirtyAPITests(file) {
done();
});
});
});

describe('db file close', function(done) {
after(cleanup);

it('close', function(done) {
if (!file) {
console.log('N/A in transient mode');
return done();
}
var db = dirty(file);
db.on('load', function(length) {
db.set('close', 'close');
db.on('drain', function() {
db.close();
});
});


db.on('write_close',function() {
done();
});
});
});

});
Expand Down

0 comments on commit 6894f24

Please sign in to comment.