Skip to content
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.

Commit

Permalink
Fixed Memory and Mongo persistence ready callback support.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Aug 7, 2013
1 parent a876d00 commit 7e979b7
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 25 deletions.
8 changes: 5 additions & 3 deletions lib/persistence/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ var factory = function (location) { return new MemDOWN(location); };
* minus the `db`, which is set to MemDOWN for convenience.
*
* @api public
* @param {Object} options The options to create this persistance
* @param {Function} callback Called when ready.
*/
function MemoryPersistence(options) {
function MemoryPersistence(options, callback) {
if (!(this instanceof MemoryPersistence)) {
return new MemoryPersistence(options);
return new MemoryPersistence(options, callback);
}

options = options || {};
options.db = factory;
options.path = "RAM";
LevelUpPersistence.call(this, options);
LevelUpPersistence.call(this, options, callback);
}

util.inherits(MemoryPersistence, LevelUpPersistence);
Expand Down
2 changes: 1 addition & 1 deletion lib/persistence/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var defaults = {
*/
function MongoPersistence(options, done) {
if (!(this instanceof MongoPersistence)) {
return new MongoPersistence(options);
return new MongoPersistence(options, done);
}


Expand Down
24 changes: 19 additions & 5 deletions test/persistence/abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,32 @@
var async = require("async");
var EventEmitter = require("events").EventEmitter;

module.exports = function(create) {
module.exports = function(create, buildOpts) {
var _opts;

if (typeof buildOpts !== "function") {
_opts = buildOpts;
buildOpts = function(cb) {
cb(null, _opts);
};
}

beforeEach(function(done) {
var that = this;
create.call(this, function(err, result, opts) {
buildOpts(function(err, opts) {
if (err) {
return done(err);
}

that.instance = result;
that.opts = opts;
done();
create(opts, function(err, result) {
if (err) {
return done(err);
}

that.instance = result;
that.opts = opts;
done();
});
});
});

Expand Down
5 changes: 2 additions & 3 deletions test/persistence/levelup_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ describe("mosca.persistence.LevelUp", function() {
}
};

abstract(function(cb) {
abstract(LevelUp, function(cb) {
var that = this;
tmp.dir(function (err, path) {
if (err) {
return cb(err);
}

that.path = path;
opts.path = path;
cb(null, new LevelUp(opts), opts);
cb(null, opts);
});
});

Expand Down
4 changes: 1 addition & 3 deletions test/persistence/memory_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ describe("mosca.persistence.Memory", function() {
}
};

abstract(function(cb) {
cb(null, new Memory(opts), opts);
});
abstract(Memory, opts);
});
6 changes: 1 addition & 5 deletions test/persistence/mongo_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ describe("mosca.persistence.Mongo", function() {
this.secondInstance = null;
});

abstract(function(cb) {
new Mongo(opts, function(err, mongo) {
cb(err, mongo, opts);
});
});
abstract(Mongo, opts);

describe("two clients", function() {

Expand Down
6 changes: 1 addition & 5 deletions test/persistence/redis_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ describe("mosca.persistence.Redis", function() {
}
};

abstract(function(cb) {
new Redis(opts, function(err, instance) {
cb(null, instance, opts);
});
});
abstract(Redis, opts);

afterEach(function(cb) {
var flush = function() {
Expand Down

0 comments on commit 7e979b7

Please sign in to comment.