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

Commit

Permalink
Merge pull request #461 from stableShip/catch-persistence-error
Browse files Browse the repository at this point in the history
Added exception catch for invalid persistence
  • Loading branch information
mcollina committed Apr 26, 2016
2 parents 37497cf + 05f0d36 commit a0324d4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,12 @@ function Server(opts, callback) {
that.emit("ready");
done(null);
}
]);
], function(err, results){
if(err) {
callback(err)
}
});


that.on("clientConnected", function(client) {
if(that.modernOpts.publishNewClient) {
Expand Down
19 changes: 19 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,23 @@ describe("mosca.Server", function() {
});
});

it("should fail if persistence can not connect", function (done) {
var newSettings = moscaSettings();

newSettings.persistence = {
factory: mosca.persistence.Mongo,
url: "mongodb://someUrlCannotConnect"
};

var server = new mosca.Server(newSettings, function (err) {
if (err instanceof Error) {
done();
} else {
expect().fail("new mosca.Server should fail");
}
});
});

describe("timers", function() {
var clock;

Expand Down Expand Up @@ -797,4 +814,6 @@ describe("mosca.Server - MQTT backend", function() {
}
});
});


});

0 comments on commit a0324d4

Please sign in to comment.