Skip to content

Commit

Permalink
Inserts are correctly pipelined
Browse files Browse the repository at this point in the history
  • Loading branch information
louischatriot committed Jun 4, 2013
1 parent 185af0b commit bf0b879
Showing 1 changed file with 56 additions and 2 deletions.
58 changes: 56 additions & 2 deletions test/db.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ describe('Database', function () {
var d;

beforeEach(function (done) {
d = new Datastore(testDb);
d = new Datastore({ filename: testDb });
d.filename.should.equal(testDb);
d.pipeline.should.equal(false);
d.inMemoryOnly.should.equal(false);

async.waterfall([
function (cb) {
Expand All @@ -39,6 +42,23 @@ describe('Database', function () {

});

it('Constructor compatibility with v0.6-', function () {
var dbef = new Datastore('somefile');
dbef.filename.should.equal('somefile');
dbef.pipeline.should.equal(false);
dbef.inMemoryOnly.should.equal(false);

var dbef = new Datastore('');
assert.isNull(dbef.filename);
dbef.pipeline.should.equal(false);
dbef.inMemoryOnly.should.equal(true);

var dbef = new Datastore();
assert.isNull(dbef.filename);
dbef.pipeline.should.equal(false);
dbef.inMemoryOnly.should.equal(true);
});


describe('Loading the database data from file and persistence', function () {

Expand Down Expand Up @@ -1890,10 +1910,44 @@ describe('Database', function () {

}); // ==== End of 'Removing indexes upon document update' ==== //

}); // ==== End of 'Using indexes' ==== //


describe.only('Pipelining', function () {

}); // ==== End of 'Using indexes' ==== //
it('Can insert documents and persist them', function (done) {
d = new Datastore({ filename: testDb, pipeline: true });
d.filename.should.equal(testDb);
d.pipeline.should.equal(true);
d.inMemoryOnly.should.equal(false);
assert.isDefined(d.persistenceExecutor);

d.insert({ f: 12 }, function (err, doc12) {
assert.isNull(err);
d.insert({ f: 5 }, function (err, doc5) {
assert.isNull(err);
d.insert({ f: 31 }, function (err, doc31) {
assert.isNull(err);

// Need to wait a bit for persistence pipeline to be taken care of
// 2ms is enough but let's use 50 to be really sure tests don't fail for a bad reason
setTimeout(function () {
var rawData = fs.readFileSync(testDb, 'utf8')
, treatedData = Datastore.treatRawData(rawData)
;

treatedData.sort(function (a, b) { return a.f - b.f; });
treatedData.length.should.equal(3);
assert.deepEqual(treatedData[0], doc5);

done();
}, 50);
});
});
});
});

}); // ==== End of 'Pipelining' ==== //


});

0 comments on commit bf0b879

Please sign in to comment.