Skip to content

Commit dcceee1

Browse files
committed
chore: modernize sync.WaitGroup usage and use strings.Cut
These updates were found by the modernize tool.
1 parent e8aa813 commit dcceee1

File tree

4 files changed

+10
-14
lines changed

4 files changed

+10
-14
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ stressgen: tools
7575
cd ./internal/testprotos; stress -timeout=10s -p=1 ./testprotos.test
7676
rm ./internal/testprotos/testprotos.test
7777

78+
modernize:
79+
@go run golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize@latest -fix ./...
80+
7881
# Regenerate all Gorums and protobuf generated files across the repo (dev, benchmark, internal/tests, examples).
7982
# This will force regeneration even though the proto files have not changed.
8083
genproto: installgorums dev

cmd/protoc-gen-gorums/gengorums/gorums_func_map.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ var funcMap = template.FuncMap{
5252
if strings.Count(pkgIdent, ".") != 1 {
5353
return "EXPECTED PACKAGE NAME AND IDENTIFIER, but got: " + pkgIdent
5454
}
55-
i := strings.Index(pkgIdent, ".")
56-
path, ident := pkgIdent[0:i], pkgIdent[i+1:]
55+
path, ident, _ := strings.Cut(pkgIdent, ".")
5756
pkg, ok := importMap[path]
5857
if !ok {
5958
return "IMPORT NOT FOUND: " + path

config_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,13 @@ func TestConfigConcurrentAccess(t *testing.T) {
223223
errCh := make(chan error, 2)
224224
var wg sync.WaitGroup
225225
for range 2 {
226-
wg.Add(1)
227-
go func() {
226+
wg.Go(func() {
228227
node := cfg.Nodes()[0]
229228
_, err := node.Test(context.Background(), &dummy.Empty{})
230229
if err != nil {
231230
errCh <- err
232231
}
233-
wg.Done()
234-
}()
232+
})
235233
}
236234
wg.Wait()
237235
close(errCh)

internal/tests/ordering/order_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ func TestQCAsyncOrdering(t *testing.T) {
159159
for time.Now().Before(stopTime) {
160160
i++
161161
promise := cfg.QCAsync(ctx, Request_builder{Num: uint64(i)}.Build())
162-
wg.Add(1)
163-
go func(promise *AsyncResponse) {
164-
defer wg.Done()
162+
wg.Go(func() {
165163
resp, err := promise.Get()
166164
if err != nil {
167165
if errors.Is(err, context.Canceled) {
@@ -175,7 +173,7 @@ func TestQCAsyncOrdering(t *testing.T) {
175173
if !resp.GetInOrder() && !t.Failed() {
176174
t.Errorf("Message received out of order.")
177175
}
178-
}(promise)
176+
})
179177
}
180178
wg.Wait()
181179
cancel()
@@ -202,10 +200,8 @@ func TestMixedOrdering(t *testing.T) {
202200
t.Fatalf("Message received out of order.")
203201
}
204202
var wg sync.WaitGroup
205-
wg.Add(len(nodes))
206203
for _, node := range nodes {
207-
go func(node *Node) {
208-
defer wg.Done()
204+
wg.Go(func() {
209205
resp, err := node.UnaryRPC(context.Background(), Request_builder{Num: uint64(i)}.Build())
210206
if err != nil {
211207
t.Errorf("RPC error: %v", err)
@@ -218,7 +214,7 @@ func TestMixedOrdering(t *testing.T) {
218214
t.Errorf("Message received out of order.")
219215
return
220216
}
221-
}(node)
217+
})
222218
}
223219
wg.Wait()
224220
i++

0 commit comments

Comments
 (0)