Skip to content

Commit

Permalink
*: migrate sync.WaitGroup to util.WaitGroupWrapper (#30644)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkingrei committed Dec 13, 2021
1 parent 7555536 commit 1f26870
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 30 deletions.
17 changes: 6 additions & 11 deletions session/isolation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
package session_test

import (
"sync"

. "github.com/pingcap/check"
"github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/testkit"
)

Expand Down Expand Up @@ -55,12 +54,10 @@ func (s *testIsolationSuite) TestP0DirtyWrite(c *C) {
session1.MustExec("begin;")
session1.MustExec("update x set c = c+1 where id = 1;")
session2.MustExec("begin;")
var wg sync.WaitGroup
wg.Add(1)
go func() {
var wg util.WaitGroupWrapper
wg.Run(func() {
session2.MustExec("update x set c = c+1 where id = 1;")
wg.Done()
}()
})
session1.MustExec("commit;")
wg.Wait()
session2.MustExec("commit;")
Expand All @@ -75,11 +72,9 @@ func (s *testIsolationSuite) TestP0DirtyWrite(c *C) {
session1.MustExec("begin;")
session1.MustExec("update x set c = c+1 where id = 1;")
session2.MustExec("begin;")
wg.Add(1)
go func() {
wg.Run(func() {
session2.MustExec("update x set c = c+1 where id = 1;")
wg.Done()
}()
})
session1.MustExec("commit;")
wg.Wait()
session2.MustExec("commit;")
Expand Down
22 changes: 8 additions & 14 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import (
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/sqlexec"
"github.com/pingcap/tidb/util/testkit"
Expand Down Expand Up @@ -1762,31 +1763,24 @@ func (s *testSessionSuite2) TestRetry(c *C) {
tk2.MustExec("set @@tidb_disable_txn_auto_retry = 0")
tk3.MustExec("set @@tidb_disable_txn_auto_retry = 0")

var wg sync.WaitGroup
wg.Add(3)
f1 := func() {
defer wg.Done()
var wg util.WaitGroupWrapper
wg.Run(func() {
for i := 0; i < 30; i++ {
tk1.MustExec("update t set c = 1;")
}
}
f2 := func() {
defer wg.Done()
})
wg.Run(func() {
for i := 0; i < 30; i++ {
tk2.MustExec("update t set c = ?;", 1)
}
}
f3 := func() {
defer wg.Done()
})
wg.Run(func() {
for i := 0; i < 30; i++ {
tk3.MustExec("begin")
tk3.MustExec("update t set c = 1;")
tk3.MustExec("commit")
}
}
go f1()
go f2()
go f3()
})
wg.Wait()
}

Expand Down
9 changes: 4 additions & 5 deletions statistics/handle/dump_serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/pingcap/tidb/statistics"
"github.com/pingcap/tidb/statistics/handle"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/util"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -322,12 +323,10 @@ func TestDumpExtendedStats(t *testing.T) {
requireTableEqual(t, loadTbl, tbl)

cleanStats(tk, dom)
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
wg := util.WaitGroupWrapper{}
wg.Run(func() {
require.Nil(t, h.Update(is))
wg.Done()
}()
})
err = h.LoadStatsFromJSON(is, jsonTbl)
wg.Wait()
require.NoError(t, err)
Expand Down

0 comments on commit 1f26870

Please sign in to comment.