-
Notifications
You must be signed in to change notification settings - Fork 32
/
test_local.js
33 lines (29 loc) · 894 Bytes
/
test_local.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
if (typeof module !== 'undefined') {
var copyMap = require('./base').copyMap,
RaftServerLocal = require('./local').RaftServerLocal,
test_common = require('./test_common'),
tests = require('./tests')
} else {
var test_local = {},
exports = test_local
}
serverPool = {} // Map of server IDs to raft instances
idIdx = 0
function startServers(opts, n) {
n = n || 3
var serverOpts = {}
for (var i=0; i<n; i++) {
serverOpts[i] = copyMap(opts)
serverOpts[i].serverPool = serverPool
serverOpts[i].listenAddress = "local:" + (idIdx++)
}
test_common.startServers(RaftServerLocal, serverOpts)
return serverOpts
}
if (typeof require !== 'undefined' && require.main === module) {
startServers()
tests.test1(serverPool)
} else {
exports.serverPool = serverPool
exports.startServers = startServers
}