-
Notifications
You must be signed in to change notification settings - Fork 32
/
test_http.js
37 lines (32 loc) · 1.04 KB
/
test_http.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
if (typeof module !== 'undefined') {
var copyMap = require('./base').copyMap,
RaftServerHttp = require('./http').RaftServerHttp,
test_common = require('./test_common'),
tests = require('./tests')
} else {
var test_http = {},
exports = test_http
}
serverPool = {} // Map of server IDs to raft instances
serverAddress = {} // Map of server IDs to listen addresses
portIdx = 9000
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 = "localhost:" + (portIdx++)
serverAddress[i] = serverOpts[i].listenAddress
serverOpts[i].serverAddress = serverAddress
}
test_common.startServers(RaftServerHttp, serverOpts)
return serverOpts
}
if (typeof require !== 'undefined' && require.main === module) {
startServers()
tests.test1(serverPool)
} else {
exports.serverPool = serverPool
exports.startServers = startServers
}