mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2024-11-22 12:41:11 +00:00
Added timeout to leadership election
This commit is contained in:
parent
6f5e927f70
commit
cbc486de77
3 changed files with 16 additions and 9 deletions
|
@ -25,8 +25,8 @@ var Gather = require("./gather");
|
|||
var gather = new Gather();
|
||||
|
||||
// ***** Generate Test Users *****
|
||||
// var helper = require("./helper");
|
||||
// helper.createTestUsers({ gather: gather });
|
||||
var helper = require("./helper");
|
||||
helper.createTestUsers({ gather: gather });
|
||||
|
||||
module.exports = function (namespace) {
|
||||
var refreshGather = function () {
|
||||
|
|
|
@ -14,10 +14,15 @@
|
|||
var Gatherer = require("./gatherer");
|
||||
var StateMachine = require("javascript-state-machine");
|
||||
|
||||
function Gather () {
|
||||
function Gather (options) {
|
||||
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.gatherers = [];
|
||||
this.ELECTION_INTERVAL = 10000; // 10 Seconds (temporarily)
|
||||
|
|
|
@ -45,6 +45,13 @@ describe("Gather Model:", function () {
|
|||
|
||||
describe("Election Tmimeout", function () {
|
||||
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
|
||||
assert.isNull(gather.electionStartTime);
|
||||
gatherers.forEach(function (gatherer) {
|
||||
|
@ -52,11 +59,6 @@ describe("Gather Model:", function () {
|
|||
});
|
||||
assert.equal(gather.current, "election");
|
||||
assert.isNotNull(gather.electionStartTime);
|
||||
setTimeout(function () {
|
||||
assert.equal(gather.current, "selection");
|
||||
assert.isNull(gather.electionStartTime);
|
||||
done();
|
||||
}, 200);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue