From 8e1dd2b2e989c619e822f4ac9f41c2fd509e0f56 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Tue, 19 Nov 2024 12:55:56 +0100 Subject: [PATCH] Use atomic.Uint64 type rather than atomic.AddUint64 (see Bugs section of atomic package) --- go/daemon/network/network_it_util_test.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/go/daemon/network/network_it_util_test.go b/go/daemon/network/network_it_util_test.go index 9fe9a70..a292110 100644 --- a/go/daemon/network/network_it_util_test.go +++ b/go/daemon/network/network_it_util_test.go @@ -30,15 +30,19 @@ var ( return filepath.Join(appDirPath, "bin") }) - ipNetCounter uint64 = 0 - publicAddrPortCounter uint64 = 1024 + ipNetCounter = new(atomic.Uint64) + publicAddrPortCounter = func() *atomic.Uint64 { + i := new(atomic.Uint64) + i.Store(1024) + return i + }() ) func newIPNet() nebula.IPNet { var ( ipNet nebula.IPNet ipNetStr = fmt.Sprintf( - "172.16.%d.0/24", atomic.AddUint64(&ipNetCounter, 1), + "172.16.%d.0/24", ipNetCounter.Add(1)-1, ) ) @@ -51,7 +55,7 @@ func newIPNet() nebula.IPNet { func newPublicAddr() string { return fmt.Sprintf( - "127.0.0.200:%d", atomic.AddUint64(&publicAddrPortCounter, 1), + "127.0.0.200:%d", publicAddrPortCounter.Add(1)-1, ) } @@ -59,7 +63,7 @@ type integrationHarness struct { ctx context.Context logger *mlog.Logger rootDir toolkit.Dir - dirCounter uint64 + dirCounter atomic.Uint64 } func newIntegrationHarness(t *testing.T) *integrationHarness { @@ -89,7 +93,7 @@ func newIntegrationHarness(t *testing.T) *integrationHarness { } func (h *integrationHarness) mkDir(t *testing.T, name string) toolkit.Dir { - fullName := fmt.Sprintf("%s-%d", name, atomic.AddUint64(&h.dirCounter, 1)) + fullName := fmt.Sprintf("%s-%d", name, h.dirCounter.Add(1)-1) t.Logf("Creating directory %q", fullName) d, err := h.rootDir.MkChildDir(fullName, false)