From 45364ec93a7951f519846ff8fb0823ec64fc897e Mon Sep 17 00:00:00 2001 From: Zihua Li Date: Sat, 5 Dec 2015 13:32:34 +0800 Subject: [PATCH] Add tests for executeFailoverCommands and executeClusterDownCommands --- .travis.yml | 7 +++---- lib/cluster.js | 9 +++++---- test/unit/cluster.js | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index c7d6674b..042de920 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/lib/cluster.js b/lib/cluster.js index 6fa6791a..39d64d18 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -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(); }; @@ -111,6 +111,7 @@ Cluster.prototype.connect = function () { } this.setStatus('connecting'); + var closeListener; var refreshListener = function () { this.removeListener('close', closeListener); this.retryAttempts = 0; @@ -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')); }; diff --git a/test/unit/cluster.js b/test/unit/cluster.js index f676f459..672efb96 100644 --- a/test/unit/cluster.js +++ b/test/unit/cluster.js @@ -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); + }); + }); });