-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
test-clusters.js
63 lines (54 loc) · 1.39 KB
/
test-clusters.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const test = require('tape').test
const persistence = require('./persistence')
const Redis = require('ioredis')
const mqemitterRedis = require('mqemitter-redis')
const abs = require('aedes-cached-persistence/abstract')
function unref () {
this.connector.stream.unref()
}
const nodes = [
{ host: 'localhost', port: 6378 },
{ host: 'localhost', port: 6380 },
{ host: 'localhost', port: 6381 },
{ host: 'localhost', port: 6382 },
{ host: 'localhost', port: 6383 },
{ host: 'localhost', port: 6384 }
]
const db = new Redis.Cluster(nodes)
db.on('error', e => {
console.trace(e)
})
db.on('ready', function () {
abs({
test,
buildEmitter () {
const emitter = mqemitterRedis()
emitter.subConn.on('connect', unref)
emitter.pubConn.on('connect', unref)
return emitter
},
persistence (cb) {
const slaves = db.nodes('master')
Promise.all(slaves.map(function (node) {
return node.flushdb().catch(err => {
console.error('flushRedisKeys-error:', err)
})
})).then(() => {
const conn = new Redis.Cluster(nodes)
conn.on('error', e => {
console.trace(e)
})
conn.on('ready', function () {
cb(null, persistence({
conn,
cluster: true
}))
})
})
},
waitForReady: true
})
test.onFinish(() => {
process.exit(0)
})
})