forked from limitd/limitdb
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add tests for the clustered environment * add username support for clustered environments
- Loading branch information
Showing
17 changed files
with
2,558 additions
and
2,160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export CLUSTER_NO_TLS_VALIDATION=true | ||
|
||
test-standalone-setup: | ||
docker-compose up -d | ||
|
||
test-standalone-teardown: | ||
docker-compose down | ||
|
||
test-cluster-setup: | ||
docker-compose -f docker-compose-cluster.yml up -d | ||
|
||
test-cluster-teardown: | ||
docker-compose -f docker-compose-cluster.yml down | ||
|
||
test-cluster: | ||
npm run test-cluster | ||
test-standalone: | ||
npm run test-standalone | ||
|
||
test: test-standalone test-cluster | ||
test-setup: test-standalone-setup test-cluster-setup | ||
test-teardown: test-standalone-teardown test-cluster-teardown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
services: | ||
redis-1: | ||
image: 'redis:6' | ||
healthcheck: | ||
interval: "1s" | ||
test: [ "CMD", "redis-cli", "-p", "16371", "ping", "|", "grep", "PONG" ] | ||
command: ["redis-server", "/etc/redis/redis.conf"] | ||
volumes: | ||
- ${PWD}/test-resources/redis-cluster/node-1/conf/redis.conf:/etc/redis/redis.conf | ||
network_mode: host | ||
redis-2: | ||
image: 'redis:6' | ||
healthcheck: | ||
interval: "1s" | ||
test: [ "CMD", "redis-cli", "-p", "16372", "ping", "|", "grep", "PONG" ] | ||
command: [ "redis-server", "/etc/redis/redis.conf" ] | ||
volumes: | ||
- ${PWD}/test-resources/redis-cluster/node-2/conf/redis.conf:/etc/redis/redis.conf | ||
network_mode: host | ||
redis-3: | ||
image: 'redis:6' | ||
healthcheck: | ||
interval: "1s" | ||
test: [ "CMD", "redis-cli", "-p", "16373", "ping", "|", "grep", "PONG" ] | ||
command: [ "redis-server", "/etc/redis/redis.conf" ] | ||
volumes: | ||
- ${PWD}/test-resources/redis-cluster/node-3/conf/redis.conf:/etc/redis/redis.conf | ||
network_mode: host | ||
redis-cluster-create: | ||
image: 'redis:6' | ||
command: '/usr/local/etc/redis/redis-cluster-create.sh' | ||
depends_on: | ||
redis-1: | ||
condition: service_healthy | ||
redis-2: | ||
condition: service_healthy | ||
redis-3: | ||
condition: service_healthy | ||
volumes: | ||
- ${PWD}/test-resources/redis-cluster/redis-cluster-create.sh:/usr/local/etc/redis/redis-cluster-create.sh | ||
network_mode: host | ||
healthcheck: | ||
test: ["CMD-SHELL", "redis-cli -p 16371 -c cluster info | grep cluster_state:ok"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
port 16371 | ||
bind 0.0.0.0 | ||
cluster-enabled yes | ||
cluster-config-file nodes.conf | ||
cluster-node-timeout 5000 | ||
cluster-announce-ip 0.0.0.0 | ||
cluster-announce-port 16371 | ||
cluster-announce-bus-port 26371 | ||
appendonly yes | ||
user testuser on >testpass ~* +@all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
port 16372 | ||
bind 0.0.0.0 | ||
cluster-enabled yes | ||
cluster-config-file nodes.conf | ||
cluster-node-timeout 5000 | ||
cluster-announce-ip 0.0.0.0 | ||
cluster-announce-port 16372 | ||
cluster-announce-bus-port 26372 | ||
appendonly yes | ||
user testuser on >testpass ~* +@all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
port 16373 | ||
bind 0.0.0.0 | ||
cluster-enabled yes | ||
cluster-config-file nodes.conf | ||
cluster-node-timeout 5000 | ||
cluster-announce-ip 0.0.0.0 | ||
cluster-announce-port 16373 | ||
cluster-announce-bus-port 26373 | ||
appendonly yes | ||
user testuser on >testpass ~* +@all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_1_ip="0.0.0.0" | ||
node_2_ip="0.0.0.0" | ||
node_3_ip="0.0.0.0" | ||
|
||
redis-cli --cluster create $node_1_ip:16371 $node_2_ip:16372 $node_3_ip:16373 --cluster-replicas 0 --cluster-yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* eslint-env node, mocha */ | ||
const _ = require('lodash'); | ||
const assert = require('chai').assert; | ||
const LimitRedis = require('../lib/client'); | ||
const clusterNodes = [{ host: '127.0.0.1', port: 16371 }, { host: '127.0.0.1', port: 16372 }, { host: '127.0.0.1', port: 16373 }]; | ||
const clientTests = require('./client.tests'); | ||
|
||
describe('when using LimitdClient', () => { | ||
describe('in Cluster mode', () => { | ||
const clusteredClientFn = (params) => { | ||
return new LimitRedis({ nodes: clusterNodes, buckets: {}, prefix: 'tests:', ..._.omit(params, ['uri']) }); | ||
}; | ||
|
||
clientTests(clusteredClientFn); | ||
|
||
describe('when using the clustered #constructor', () => { | ||
it('should allow setting username and password', (done) => { | ||
let client = clusteredClientFn({ username: 'testuser', password: 'testpass' }); | ||
client.on('ready', () => { | ||
client.db.redis.acl("WHOAMI", (err, res) => { | ||
assert.equal(res, 'testuser'); | ||
done(); | ||
}) | ||
}); | ||
}); | ||
it('should use the default user if no one is provided', (done) => { | ||
let client = clusteredClientFn(); | ||
client.on('ready', () => { | ||
client.db.redis.acl("WHOAMI", (err, res) => { | ||
assert.equal(res, 'default'); | ||
done(); | ||
}) | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* eslint-env node, mocha */ | ||
const _ = require('lodash'); | ||
const assert = require('chai').assert; | ||
const LimitRedis = require('../lib/client'); | ||
const clientTests = require('./client.tests'); | ||
|
||
|
||
describe('when using LimitdClient', () => { | ||
describe('Standalone Redis', () => { | ||
const standaloneClientFn = (params) => { | ||
return new LimitRedis({ uri: 'localhost', buckets: {}, prefix: 'tests:', ..._.omit(params, ['nodes']) }); | ||
}; | ||
|
||
clientTests(standaloneClientFn); | ||
|
||
describe('when using the standalone #constructor', () => { | ||
// in cluster mode, ioredis doesn't fail when given a bad node address, it keeps retrying | ||
it('should call error if db fails', (done) => { | ||
let called = false; // avoid uncaught | ||
let client = standaloneClientFn({ uri: 'localhost:fail' }); | ||
client.on('error', () => { | ||
if (!called) { | ||
called = true; | ||
return done(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.