Skip to content

Commit 6d40fe1

Browse files
authored
Use go.uber.org/atomic instead of sync/atomic (#825)
Signed-off-by: Arve Knudsen <[email protected]>
1 parent 149efd6 commit 6d40fe1

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

.golangci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ linters:
6666
rules:
6767
main:
6868
deny:
69-
#- pkg: "sync/atomic"
70-
#desc: "Use go.uber.org/atomic instead of sync/atomic"
69+
- pkg: "sync/atomic"
70+
desc: "Use go.uber.org/atomic instead of sync/atomic"
7171
- pkg: "github.com/go-kit/kit/log"
7272
desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log"
7373
- pkg: "io/ioutil"

config/http_config_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ import (
3131
"strconv"
3232
"strings"
3333
"sync"
34-
"sync/atomic"
3534
"testing"
3635
"time"
3736

3837
"github.com/stretchr/testify/require"
38+
"go.uber.org/atomic"
3939
"gopkg.in/yaml.v2"
4040
)
4141

@@ -1309,7 +1309,8 @@ func TestTLSRoundTripperRaces(t *testing.T) {
13091309

13101310
var wg sync.WaitGroup
13111311
ch := make(chan struct{})
1312-
var total, ok int64
1312+
total := atomic.NewInt64(0)
1313+
ok := atomic.NewInt64(0)
13131314
// Spawn 10 Go routines polling the server concurrently.
13141315
for i := 0; i < 10; i++ {
13151316
wg.Add(1)
@@ -1320,11 +1321,11 @@ func TestTLSRoundTripperRaces(t *testing.T) {
13201321
case <-ch:
13211322
return
13221323
default:
1323-
atomic.AddInt64(&total, 1)
1324+
total.Add(1)
13241325
r, err := c.Get(testServer.URL)
13251326
if err == nil {
13261327
r.Body.Close()
1327-
atomic.AddInt64(&ok, 1)
1328+
ok.Add(1)
13281329
}
13291330
}
13301331
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f
1414
github.com/prometheus/client_model v0.6.2
1515
github.com/stretchr/testify v1.10.0
16+
go.uber.org/atomic v1.11.0
1617
golang.org/x/net v0.42.0
1718
golang.org/x/oauth2 v0.30.0
1819
google.golang.org/protobuf v1.36.6

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
4545
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
4646
github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc=
4747
github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU=
48+
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
49+
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
4850
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
4951
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
5052
golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI=

0 commit comments

Comments
 (0)