Merge pull request #3751 from halseth/itest-numactivenodes-mtx

lntest/node: add numActiveNodesMtx
This commit is contained in:
Conner Fromknecht 2019-11-22 13:56:45 -08:00 committed by GitHub
commit b07fb37c34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -78,6 +78,7 @@ const (
var (
// numActiveNodes is the number of active nodes within the test network.
numActiveNodes = 0
numActiveNodesMtx sync.Mutex
// logOutput is a flag that can be set to append the output from the
// seed nodes to log files.
@ -96,6 +97,9 @@ var (
// support multiple test nodes running at once, the p2p, rpc, rest and
// profiling ports are incremented after each initialization.
func generateListeningPorts() (int, int, int, int) {
numActiveNodesMtx.Lock()
defer numActiveNodesMtx.Unlock()
p2p := defaultNodePort + (4 * numActiveNodes)
rpc := defaultClientPort + (4 * numActiveNodes)
rest := defaultRestPort + (4 * numActiveNodes)
@ -295,8 +299,10 @@ func newNode(cfg nodeConfig) (*HarnessNode, error) {
cfg.P2PPort, cfg.RPCPort, cfg.RESTPort, cfg.ProfilePort = generateListeningPorts()
numActiveNodesMtx.Lock()
nodeNum := numActiveNodes
numActiveNodes++
numActiveNodesMtx.Unlock()
return &HarnessNode{
cfg: &cfg,