Use atomic.Uint64 type rather than atomic.AddUint64 (see Bugs section of atomic package)

This commit is contained in:
Brian Picciano 2024-11-19 12:55:56 +01:00
parent 9545f77cce
commit 8e1dd2b2e9

View File

@ -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)