mirror of https://github.com/ENSL/ensl_gathers.git
Added timeout to leadership election
This commit is contained in:
parent
6f5e927f70
commit
cbc486de77
|
@ -25,8 +25,8 @@ var Gather = require("./gather");
|
||||||
var gather = new Gather();
|
var gather = new Gather();
|
||||||
|
|
||||||
// ***** Generate Test Users *****
|
// ***** Generate Test Users *****
|
||||||
// var helper = require("./helper");
|
var helper = require("./helper");
|
||||||
// helper.createTestUsers({ gather: gather });
|
helper.createTestUsers({ gather: gather });
|
||||||
|
|
||||||
module.exports = function (namespace) {
|
module.exports = function (namespace) {
|
||||||
var refreshGather = function () {
|
var refreshGather = function () {
|
||||||
|
|
|
@ -14,10 +14,15 @@
|
||||||
var Gatherer = require("./gatherer");
|
var Gatherer = require("./gatherer");
|
||||||
var StateMachine = require("javascript-state-machine");
|
var StateMachine = require("javascript-state-machine");
|
||||||
|
|
||||||
function Gather () {
|
function Gather (options) {
|
||||||
if (!(this instanceof Gather)) {
|
if (!(this instanceof Gather)) {
|
||||||
return new Gather();
|
return new Gather(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof options.onElectionTimeout === 'function') {
|
||||||
|
this.onElectionTimeout = options.onElectionTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
this.TEAM_SIZE = 6;
|
this.TEAM_SIZE = 6;
|
||||||
this.gatherers = [];
|
this.gatherers = [];
|
||||||
this.ELECTION_INTERVAL = 10000; // 10 Seconds (temporarily)
|
this.ELECTION_INTERVAL = 10000; // 10 Seconds (temporarily)
|
||||||
|
|
|
@ -45,6 +45,13 @@ describe("Gather Model:", function () {
|
||||||
|
|
||||||
describe("Election Tmimeout", function () {
|
describe("Election Tmimeout", function () {
|
||||||
it ("starts a timer and transitions to next state when timer runs out", function (done) {
|
it ("starts a timer and transitions to next state when timer runs out", function (done) {
|
||||||
|
gather = new Gather({
|
||||||
|
onElectionTimeout: function () {
|
||||||
|
assert.equal(gather.current, "selection");
|
||||||
|
assert.isNull(gather.electionStartTime);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
gather.ELECTION_INTERVAL = 100; // 1 second
|
gather.ELECTION_INTERVAL = 100; // 1 second
|
||||||
assert.isNull(gather.electionStartTime);
|
assert.isNull(gather.electionStartTime);
|
||||||
gatherers.forEach(function (gatherer) {
|
gatherers.forEach(function (gatherer) {
|
||||||
|
@ -52,11 +59,6 @@ describe("Gather Model:", function () {
|
||||||
});
|
});
|
||||||
assert.equal(gather.current, "election");
|
assert.equal(gather.current, "election");
|
||||||
assert.isNotNull(gather.electionStartTime);
|
assert.isNotNull(gather.electionStartTime);
|
||||||
setTimeout(function () {
|
|
||||||
assert.equal(gather.current, "selection");
|
|
||||||
assert.isNull(gather.electionStartTime);
|
|
||||||
done();
|
|
||||||
}, 200);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue