From ce93b82e1e780b2fa6a9fa4d28bfcd27427ff7ee Mon Sep 17 00:00:00 2001 From: James Phillips Date: Thu, 1 Sep 2016 01:01:28 -0700 Subject: [PATCH] Makes port selection atomic in unit tests. --- consul/server_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/consul/server_test.go b/consul/server_test.go index a8d65d36f..20333e44b 100644 --- a/consul/server_test.go +++ b/consul/server_test.go @@ -7,18 +7,17 @@ import ( "net" "os" "strings" + "sync/atomic" "testing" "time" "github.com/hashicorp/consul/testutil" ) -var nextPort = 15000 +var nextPort int32 = 15000 func getPort() int { - p := nextPort - nextPort++ - return p + return int(atomic.AddInt32(&nextPort, 1)) } func tmpDir(t *testing.T) string {