-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In node v0.10.x db.set callback would not fire on second write. Node streams API changes meant that drain event is not emitted in same frequency. This fix appropriately only relies on the drain event when the write buffer was full. Tested in node v0.10.0 and node v0.8.17. Also makes existing tests non version specific.
- Loading branch information
Showing
3 changed files
with
97 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
var _ = require('underscore'); | ||
var async = require('async'); | ||
var dirty = require('../index.js'); | ||
|
||
describe('db.set()', function() { | ||
describe('using the memory store', function() { | ||
|
||
|
||
it('should trigger the callback for each of 10 db calls', function(cb) { | ||
connectToMemDb(function (count, db) { | ||
db.on('error', function (err) { | ||
return cb(err); | ||
}); | ||
|
||
async.eachSeries(_.range(10),function (i,cb) { | ||
setSample(db,cb); | ||
}, cb); | ||
}); | ||
}); | ||
|
||
|
||
it('should trigger the callback if provided', function(cb) { | ||
connectToMemDb(function (count, db) { | ||
db.on('error', function (err) { | ||
return cb(err); | ||
}); | ||
setSample(db,cb); | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
describe('using the disk store', function() { | ||
|
||
it('should trigger the callback if provided', function(cb) { | ||
connectToDiskDb(function (count, db) { | ||
db.on('error', function (err) { | ||
return cb(err); | ||
}); | ||
setSample(db,cb); | ||
}); | ||
}); | ||
|
||
it('should work again as long as a fresh connection is used', function(cb) { | ||
connectToDiskDb(function (count, db) { | ||
db.on('error', function (err) { | ||
return cb(err); | ||
}); | ||
setSample(db,cb); | ||
}); | ||
}); | ||
|
||
it('callback should fire each time if set() is used multiple times over the same db connection', function(cb) { | ||
connectToDiskDb(function (count, db) { | ||
db.on('error', function (err) { | ||
return cb(err); | ||
}); | ||
async.eachSeries(_.range(2),function (i,cb) { | ||
setSample(db, cb); | ||
}, cb); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
// Instantiate sample memory database | ||
function connectToMemDb(cb) { | ||
var db = new(dirty.Dirty)(); | ||
db.on('load', function (err){ | ||
cb(err, db); | ||
}); | ||
} | ||
|
||
// Instantiate sample disk database | ||
function connectToDiskDb(cb) { | ||
var db = dirty('dirty.db'); | ||
db.on('load', function (err) { | ||
cb(err, db); | ||
}); | ||
} | ||
|
||
// Set sample db entry | ||
function setSample(db, cb) { | ||
var key = 'sample'; | ||
var val = {id: Math.round(Math.random()*100)}; | ||
db.set(key, val, cb); | ||
} |