Skip to content

Commit 2619aed

Browse files
authored
refactor: use WaitGroup.Go to simplify code (#1616)
use WaitGroup.Go to simplify code. More info: golang/go#63796 Signed-off-by: nuxtreact <[email protected]>
1 parent b74b831 commit 2619aed

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

pkg/blockchain/oracle/oracle_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,10 @@ func TestOracleConcurrentGetGasPrice(t *testing.T) {
6363
// GetGasPrice is safe for concurrent calls
6464
var wg sync.WaitGroup
6565
for i := 0; i < 100; i++ {
66-
wg.Add(1)
67-
go func() {
68-
defer wg.Done()
66+
wg.Go(func() {
6967
price := o.GetGasPrice()
7068
require.Greater(t, price, int64(0))
71-
}()
69+
})
7270
}
7371
wg.Wait()
7472
}
@@ -81,14 +79,12 @@ func TestOracleGetGasPriceRandom(t *testing.T) {
8179

8280
var wg sync.WaitGroup
8381
for i := 0; i < 100; i++ {
84-
wg.Add(1)
85-
go func() {
86-
defer wg.Done()
82+
wg.Go(func() {
8783
// Force the oracle to fetch a new gas price for some goroutines.
8884
time.Sleep(time.Duration(rand.Intn(500)) * time.Millisecond)
8985
price := o.GetGasPrice()
9086
require.Greater(t, price, int64(0))
91-
}()
87+
})
9288
}
9389
wg.Wait()
9490
}

pkg/db/gateway_envelope_batch_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,7 @@ func TestBatchInsert_ParallelDuplicates(t *testing.T) {
481481

482482
// All goroutines try to insert the SAME batch (duplicates).
483483
for i := 0; i < numGoroutines; i++ {
484-
wg.Add(1)
485-
go func() {
486-
defer wg.Done()
484+
wg.Go(func() {
487485
p := buildBatchInput(payerID, originatorID, 1, batchSize, spendPerMessage)
488486
n, err := xmtpd_db.InsertGatewayEnvelopeBatchAndIncrementUnsettledUsage(
489487
ctx,
@@ -492,7 +490,7 @@ func TestBatchInsert_ParallelDuplicates(t *testing.T) {
492490
)
493491
require.NoError(t, err)
494492
atomic.AddInt64(&totalInserted, n)
495-
}()
493+
})
496494
}
497495

498496
wg.Wait()

0 commit comments

Comments
 (0)