Skip to content

Commit

Permalink
integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiegurari committed Dec 22, 2016
1 parent 7be58f5 commit 41d90d7
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 19 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ node_js:
- "iojs"
before_install:
- npm install -g npm
env: MULTIPLE_REDIS_TEST_USE_REDIS=true MULTIPLE_REDIS_TEST_INTEGRATION_HOST1=localhost MULTIPLE_REDIS_TEST_INTEGRATION_HOST2=otherhost MULTIPLE_REDIS_TEST_INTEGRATION_PORTS=7777,7778,6379 MULTIPLE_REDIS_TEST_INTEGRATION_KILL_PORT=7777 MULTIPLE_REDIS_TEST_INTEGRATION_PUB_SUB=false
env: MULTIPLE_REDIS_TEST_USE_REDIS=true MULTIPLE_REDIS_TEST_INTEGRATION_HOST1=localhost MULTIPLE_REDIS_TEST_INTEGRATION_HOST2=otherhost MULTIPLE_REDIS_TEST_INTEGRATION_PORTS=7777,7778,6379 MULTIPLE_REDIS_TEST_INTEGRATION_CONF=/etc/redis/redis.conf
services:
- redis-server
before_script:
- sudo redis-server /etc/redis/redis.conf --port 7777
- sudo redis-server /etc/redis/redis.conf --port 7778
- chmod -R 777 ./test/helper/*.sh
- sudo ./test/helper/start_redis.sh 7777 /etc/redis/redis.conf
- sudo ./test/helper/start_redis.sh 7778 /etc/redis/redis.conf
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ See [contributing guide](.github/CONTRIBUTING.md)

| Date | Version | Description |
| ----------- | ------- | ----------- |
| 2016-12-22 | v1.0.22 | Maintenance |
| 2016-12-22 | v1.0.23 | Maintenance |
| 2015-10-22 | v0.0.16 | Timeout child commands (see childCommandTimeout option) |
| 2015-10-16 | v0.0.12 | Maintenance |
| 2015-09-23 | v0.0.7 | Upgrade to redis 2.0 |
Expand Down
2 changes: 1 addition & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
| Date | Version | Description |
| ----------- | ------- | ----------- |
| 2016-12-22 | v1.0.22 | Maintenance |
| 2016-12-22 | v1.0.23 | Maintenance |
| 2015-10-22 | v0.0.16 | Timeout child commands (see childCommandTimeout option) |
| 2015-10-16 | v0.0.12 | Maintenance |
| 2015-09-23 | v0.0.7 | Upgrade to redis 2.0 |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "multiple-redis",
"version": "1.0.22",
"version": "1.0.23",
"description": "Run redis commands against multiple redis instances.",
"author": {
"name": "Sagie Gur-Ari",
Expand Down
4 changes: 2 additions & 2 deletions test/helper/kill_redis.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

#print which process will be killed
ps -ef | grep $1
ps -ef | grep redis-server | grep $1 | grep -v grep

#kill the requested process
ps -ef | grep $1 | grep -v grep | awk '{print $2}' | sudo xargs kill -9
ps -ef | grep redis-server | grep $1 | grep -v grep | awk '{print $2}' | sudo xargs kill -9
3 changes: 3 additions & 0 deletions test/helper/start_redis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

sudo redis-server $2 --port $1
49 changes: 42 additions & 7 deletions test/spec/integration-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
var chai = require('chai');
var assert = chai.assert;
var path = require('path');
var events = require('events');
var EventEmitter = events.EventEmitter;
var childProcess = require('child_process');
var redis = require('redis');
var MultipleRedis = require('../../');
Expand All @@ -27,7 +29,9 @@ describe('Integration Tests', function () {
}

var authPass = process.env.MULTIPLE_REDIS_TEST_INTEGRATION_AUTH_PASS;
var options = {};
var options = {
forceNoMock: true
};
if (authPass) {
options.auth_pass = authPass;
}
Expand Down Expand Up @@ -78,22 +82,30 @@ describe('Integration Tests', function () {
});
}

if ((process.env.MULTIPLE_REDIS_TEST_INTEGRATION_PUB_SUB === 'true') && process.env.MULTIPLE_REDIS_TEST_INTEGRATION_KILL_PORT && (redisPorts.length > 1)) {
if (process.env.MULTIPLE_REDIS_TEST_INTEGRATION_CONF && (redisPorts.length > 1)) {
it('pub/sub - redis killed', function (done) {
this.timeout(60000);

var publisher = redis.createClient(redisPorts[0], 'localhost');
var publisher = redis.createClient(redisPorts[0], 'localhost', options);

publisher.on('error', function () {
return undefined;
});

var connectionInfo = [];
redisPorts.forEach(function (redisPort) {
connectionInfo.push({
host: 'localhost',
port: redisPort
port: parseInt(redisPort, 10)
});
});

var redisClient = MultipleRedis.createClient(connectionInfo, options);

redisClient.on('error', function () {
return undefined;
});

redisClient.once('connect', function () {
setTimeout(function () {
assert.isTrue(redisClient.connected);
Expand Down Expand Up @@ -121,11 +133,34 @@ describe('Integration Tests', function () {

setTimeout(function () {
childProcess.execFile(path.join(__dirname, '../helper/kill_redis.sh'), [
process.env.MULTIPLE_REDIS_TEST_INTEGRATION_KILL_PORT
redisPorts[0]
], function (killError) {
assert.isUndefined(killError);
assert.isNull(killError);

var emitter = new EventEmitter();

var readyCount = 0;
emitter.on('ready', function () {
readyCount++;

if (readyCount === 2) {
emitter.removeAllListeners('ready');
publisher.publish('test', 'end');
}
});

childProcess.execFile(path.join(__dirname, '../helper/start_redis.sh'), [
redisPorts[0],
process.env.MULTIPLE_REDIS_TEST_INTEGRATION_CONF
]);

publisher.once('connect', function () {
emitter.emit('ready');
});

publisher.publish('test', 'end');
redisClient.once('subscribe', function () {
emitter.emit('ready');
});
});
}, 250);
}, 100);
Expand Down
20 changes: 16 additions & 4 deletions test/spec/multiple-redis-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var mockRedis = (process.env.MULTIPLE_REDIS_TEST_USE_REDIS !== 'true');

redis.createClient = function (port, host, options) {
var redisClient;
if ((!mockRedis) && (host === 'localhost') && (port === 6379) && options && (!options.mock)) {
if ((options && options.forceNoMock) || ((!mockRedis) && (host === 'localhost') && (port === 6379) && options && (!options.mock))) {
redisClient = baseCreate.call(redis, port, host, options);
} else {
redisClient = new EventEmitter();
Expand All @@ -36,35 +36,47 @@ redis.createClient = function (port, host, options) {
describe('MultipleRedis Tests', function () {
describe('create tests', function () {
it('no input', function () {
var errorFound = false;

try {
MultipleRedis.createClient();
assert.fail();
} catch (error) {
assert.isDefined(error);
errorFound = true;
}

assert.isTrue(errorFound);
});

it('empty array', function () {
var errorFound = false;

try {
MultipleRedis.createClient([]);
assert.fail();
} catch (error) {
assert.isDefined(error);
errorFound = true;
}

assert.isTrue(errorFound);
});

it('too many arguments', function () {
var errorFound = false;

try {
MultipleRedis.createClient([
{
host: 'localhost1',
port: 1234
}
], {}, {});
assert.fail();
} catch (error) {
assert.isDefined(error);
errorFound = true;
}

assert.isTrue(errorFound);
});

it('redis clients', function () {
Expand Down

0 comments on commit 41d90d7

Please sign in to comment.