Skip to content

Commit

Permalink
Add tests for executeFailoverCommands and executeClusterDownCommands
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Dec 5, 2015
1 parent 1f410ac commit 45364ec
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ node_js:
- '0.10.16'
- '0.11'
- '0.12'
- '1'
- '2'
- '3'
- '4'
- 'iojs'
- '4.0.x'
- '4.1.x'

services:
- redis-server
Expand Down
9 changes: 5 additions & 4 deletions lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ Cluster.defaultOptions = _.assign({}, Redis.defaultOptions, {
util.inherits(Cluster, EventEmitter);
_.assign(Cluster.prototype, Commander.prototype);

Cluster.prototype.resetOfflineQueue = function() {
Cluster.prototype.resetOfflineQueue = function () {
this.offlineQueue = new Deque();
};

Cluster.prototype.resetFailoverQueue = function() {
Cluster.prototype.resetFailoverQueue = function () {
this.failoverQueue = new Deque();
};

Cluster.prototype.resetClusterDownQueue = function() {
Cluster.prototype.resetClusterDownQueue = function () {
this.clusterDownQueue = new Deque();
};

Expand All @@ -111,6 +111,7 @@ Cluster.prototype.connect = function () {
}
this.setStatus('connecting');

var closeListener;
var refreshListener = function () {
this.removeListener('close', closeListener);
this.retryAttempts = 0;
Expand All @@ -121,7 +122,7 @@ Cluster.prototype.connect = function () {
resolve();
};

var closeListener = function () {
closeListener = function () {
this.removeListener('refresh', refreshListener);
reject(new Error('None of startup nodes is available'));
};
Expand Down
34 changes: 34 additions & 0 deletions test/unit/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,38 @@ describe('cluster', function () {
new Cluster([{}]);
}).to.not.throw(/startupNodes/);
});

describe('#executeFailoverCommands', function () {
it('should execute the commands', function (done) {
var cluster = {
resetFailoverQueue: function () {
this.failoverQueue = [];
},
failoverQueue: []
};

cluster.failoverQueue.push(function () {
expect(this.failoverQueue).to.have.length(0);
done();
}.bind(cluster));
Cluster.prototype.executeFailoverCommands.call(cluster);
});
});

describe('#executeClusterDownCommands', function () {
it('should execute the commands', function (done) {
var cluster = {
resetClusterDownQueue: function () {
this.clusterDownQueue = [];
},
clusterDownQueue: []
};

cluster.clusterDownQueue.push(function () {
expect(this.clusterDownQueue).to.have.length(0);
done();
}.bind(cluster));
Cluster.prototype.executeClusterDownCommands.call(cluster);
});
});
});

0 comments on commit 45364ec

Please sign in to comment.