Add scripts for testing cluster failover scenarios

This commit is contained in:
James Allen 2017-05-04 11:14:17 +01:00
parent 4104ca4889
commit 5f93640077
2 changed files with 74 additions and 0 deletions

View file

@ -0,0 +1,41 @@
redis = require "redis-sharelatex"
rclient1 = redis.createClient(cluster: [{
port: "7000"
host: "localhost"
}])
rclient2 = redis.createClient(cluster: [{
port: "7000"
host: "localhost"
}])
counter = 0
sendPing = (cb = () ->) ->
rclient1.rpush "test-blpop", counter, (error) ->
console.error "[SENDING ERROR]", error.message if error?
if !error?
counter += 1
cb()
previous = null
listenForPing = (cb) ->
rclient2.blpop "test-blpop", 200, (error, result) ->
return cb(error) if error?
[key, value] = result
value = parseInt(value, 10)
if value % 10 == 0
console.log "."
if previous? and value != previous + 1
error = new Error("Counter not in order. Got #{value}, expected #{previous + 1}")
previous = value
return cb(error, value)
PING_DELAY = 100
do sendPings = () ->
sendPing () ->
setTimeout sendPings, PING_DELAY
do listenInBackground = (cb = () ->) ->
listenForPing (error, value) ->
console.error "[RECEIVING ERROR]", error.message if error
setTimeout listenInBackground

View file

@ -0,0 +1,33 @@
redis = require "redis-sharelatex"
rclient1 = redis.createClient(cluster: [{
port: "7000"
host: "localhost"
}])
rclient2 = redis.createClient(cluster: [{
port: "7000"
host: "localhost"
}])
counter = 0
sendPing = (cb = () ->) ->
rclient1.publish "test-pubsub", counter, (error) ->
console.error "[SENDING ERROR]", error.message if error?
if !error?
counter += 1
cb()
previous = null
rclient2.subscribe "test-pubsub"
rclient2.on "message", (channel, value) ->
value = parseInt(value, 10)
if value % 10 == 0
console.log "."
if previous? and value != previous + 1
console.error "[RECEIVING ERROR]", "Counter not in order. Got #{value}, expected #{previous + 1}"
previous = value
PING_DELAY = 100
do sendPings = () ->
sendPing () ->
setTimeout sendPings, PING_DELAY