From 4dad94f9713a70131a0b47868e4721269ef81927 Mon Sep 17 00:00:00 2001 From: Louis Chatriot Date: Tue, 4 Jun 2013 10:17:20 +0200 Subject: [PATCH] Pipelining tested --- test/db.test.js | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/test/db.test.js b/test/db.test.js index 3dadd00..79a8122 100644 --- a/test/db.test.js +++ b/test/db.test.js @@ -1913,7 +1913,7 @@ describe('Database', function () { }); // ==== End of 'Using indexes' ==== // - describe.only('Pipelining', function () { + describe('Pipelining', function () { it('Can insert documents and persist them', function (done) { d = new Datastore({ filename: testDb, pipeline: true }); @@ -1963,6 +1963,38 @@ describe('Database', function () { d.remove({ f: 12 }, {}, 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(1); + assert.deepEqual(treatedData[0], doc5); + + done(); + }, 50); + }); + }); + }); + }); + + it('Can update documents in persistence file too', 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.update({ f: 12 }, { $set: { f: 555 } }, {}, function (err) { + 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 () { @@ -1973,6 +2005,7 @@ describe('Database', function () { treatedData.sort(function (a, b) { return a.f - b.f; }); treatedData.length.should.equal(2); assert.deepEqual(treatedData[0], doc5); + assert.deepEqual(treatedData[1], { f: 555, _id: doc12._id }); done(); }, 50);