From 56f480a633404ff418c1e69adcdce3b76814f311 Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Mon, 20 Jun 2016 14:33:46 -0700 Subject: [PATCH] Use stable, monotonically increasing port numbers for tests --- command/agent/agent_test.go | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/command/agent/agent_test.go b/command/agent/agent_test.go index c7331aa7a9..bab39a7d08 100644 --- a/command/agent/agent_test.go +++ b/command/agent/agent_test.go @@ -19,10 +19,24 @@ import ( "github.com/hashicorp/consul/testutil" ) -var offset uint64 +const ( + basePortNumber = 10000 + + portOffsetDNS = iota + portOffsetHTTP + portOffsetRPC + portOffsetSerfLan + portOffsetSerfWan + portOffsetServer + + // Must be last in list + numPortsPerIndex +) + +var offset uint64 = basePortNumber func nextConfig() *Config { - idx := int(atomic.AddUint64(&offset, 1)) + idx := int(atomic.AddUint64(&offset, numPortsPerIndex)) conf := DefaultConfig() conf.Version = "a.b" @@ -32,12 +46,12 @@ func nextConfig() *Config { conf.Datacenter = "dc1" conf.NodeName = fmt.Sprintf("Node %d", idx) conf.BindAddr = "127.0.0.1" - conf.Ports.DNS = 19000 + idx - conf.Ports.HTTP = 18800 + idx - conf.Ports.RPC = 18600 + idx - conf.Ports.SerfLan = 18200 + idx - conf.Ports.SerfWan = 18400 + idx - conf.Ports.Server = 18000 + idx + conf.Ports.DNS = basePortNumber + idx + portOffsetDNS + conf.Ports.HTTP = basePortNumber + idx + portOffsetHTTP + conf.Ports.RPC = basePortNumber + idx + portOffsetRPC + conf.Ports.SerfLan = basePortNumber + idx + portOffsetSerfLan + conf.Ports.SerfWan = basePortNumber + idx + portOffsetSerfWan + conf.Ports.Server = basePortNumber + idx + portOffsetServer conf.Server = true conf.ACLDatacenter = "dc1" conf.ACLMasterToken = "root"