integration: add goleak (#173)

This commit is contained in:
disksing 2021-06-28 14:41:10 +08:00 committed by GitHub
parent dd88a925ec
commit 666340265a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 46 additions and 5 deletions

View File

@ -58,6 +58,10 @@ func (s *testOnePCSuite) SetupTest() {
s.bo = tikv.NewBackofferWithVars(context.Background(), 5000, nil) s.bo = tikv.NewBackofferWithVars(context.Background(), 5000, nil)
} }
func (s *testOnePCSuite) TearDownTest() {
s.testAsyncCommitCommon.tearDownTest()
}
func (s *testOnePCSuite) Test1PC() { func (s *testOnePCSuite) Test1PC() {
ctx := context.WithValue(context.Background(), util.SessionID, uint64(1)) ctx := context.WithValue(context.Background(), util.SessionID, uint64(1))

View File

@ -83,6 +83,11 @@ func (s *testCommitterSuite) SetupSuite() {
atomic.StoreUint64(&tikv.VeryLongMaxBackoff, 1000) atomic.StoreUint64(&tikv.VeryLongMaxBackoff, 1000)
} }
func (s *testCommitterSuite) TearDownSuite() {
atomic.StoreUint64(&tikv.CommitMaxBackoff, 20000)
atomic.StoreUint64(&tikv.VeryLongMaxBackoff, 600000)
}
func (s *testCommitterSuite) SetupTest() { func (s *testCommitterSuite) SetupTest() {
mvccStore, err := mocktikv.NewMVCCLevelDB("") mvccStore, err := mocktikv.NewMVCCLevelDB("")
s.Require().Nil(err) s.Require().Nil(err)
@ -99,9 +104,7 @@ func (s *testCommitterSuite) SetupTest() {
s.store = tikv.StoreProbe{KVStore: store} s.store = tikv.StoreProbe{KVStore: store}
} }
func (s *testCommitterSuite) TearDownSuite() { func (s *testCommitterSuite) TearDownTest() {
atomic.StoreUint64(&tikv.CommitMaxBackoff, 20000)
atomic.StoreUint64(&tikv.VeryLongMaxBackoff, 600000)
s.store.Close() s.store.Close()
} }

View File

@ -61,6 +61,10 @@ func (s *testAsyncCommitFailSuite) SetupTest() {
s.testAsyncCommitCommon.setUpTest() s.testAsyncCommitCommon.setUpTest()
} }
func (s *testAsyncCommitFailSuite) TearDownTest() {
s.testAsyncCommitCommon.tearDownTest()
}
// TestFailCommitPrimaryRpcErrors tests rpc errors are handled properly when // TestFailCommitPrimaryRpcErrors tests rpc errors are handled properly when
// committing primary region task. // committing primary region task.
func (s *testAsyncCommitFailSuite) TestFailAsyncCommitPrewriteRpcErrors() { func (s *testAsyncCommitFailSuite) TestFailAsyncCommitPrewriteRpcErrors() {

View File

@ -74,6 +74,7 @@ func (s *testAsyncCommitCommon) setUpTest() {
client, pdClient, cluster, err := unistore.New("") client, pdClient, cluster, err := unistore.New("")
s.Require().Nil(err) s.Require().Nil(err)
unistore.BootstrapWithSingleStore(cluster) unistore.BootstrapWithSingleStore(cluster)
s.cluster = cluster s.cluster = cluster
store, err := tikv.NewTestTiKVStore(fpClient{Client: client}, pdClient, nil, nil, 0) store, err := tikv.NewTestTiKVStore(fpClient{Client: client}, pdClient, nil, nil, 0)
@ -82,6 +83,10 @@ func (s *testAsyncCommitCommon) setUpTest() {
s.store = store s.store = store
} }
func (s *testAsyncCommitCommon) tearDownTest() {
s.store.Close()
}
func (s *testAsyncCommitCommon) putAlphabets(enableAsyncCommit bool) { func (s *testAsyncCommitCommon) putAlphabets(enableAsyncCommit bool) {
for ch := byte('a'); ch <= byte('z'); ch++ { for ch := byte('a'); ch <= byte('z'); ch++ {
s.putKV([]byte{ch}, []byte{ch}, enableAsyncCommit) s.putKV([]byte{ch}, []byte{ch}, enableAsyncCommit)
@ -180,6 +185,10 @@ func (s *testAsyncCommitSuite) SetupTest() {
s.bo = tikv.NewBackofferWithVars(context.Background(), 5000, nil) s.bo = tikv.NewBackofferWithVars(context.Background(), 5000, nil)
} }
func (s *testAsyncCommitSuite) TearDownTest() {
s.testAsyncCommitCommon.tearDownTest()
}
func (s *testAsyncCommitSuite) lockKeysWithAsyncCommit(keys, values [][]byte, primaryKey, primaryValue []byte, commitPrimary bool) (uint64, uint64) { func (s *testAsyncCommitSuite) lockKeysWithAsyncCommit(keys, values [][]byte, primaryKey, primaryValue []byte, commitPrimary bool) (uint64, uint64) {
txn, err := s.store.Begin() txn, err := s.store.Begin()
s.Nil(err) s.Nil(err)

View File

@ -12,6 +12,7 @@ require (
github.com/stretchr/testify v1.7.0 github.com/stretchr/testify v1.7.0
github.com/tikv/client-go/v2 v2.0.0 github.com/tikv/client-go/v2 v2.0.0
github.com/tikv/pd v1.1.0-beta.0.20210323121136-78679e5e209d github.com/tikv/pd v1.1.0-beta.0.20210323121136-78679e5e209d
go.uber.org/goleak v1.1.10
go.uber.org/zap v1.17.0 go.uber.org/zap v1.17.0
) )

View File

@ -17,9 +17,16 @@ import (
"testing" "testing"
"github.com/tikv/client-go/v2/tikv" "github.com/tikv/client-go/v2/tikv"
"go.uber.org/goleak"
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
tikv.EnableFailpoints() tikv.EnableFailpoints()
m.Run()
opts := []goleak.Option{
goleak.IgnoreTopFunction("github.com/pingcap/goleveldb/leveldb.(*DB).mpoolDrain"),
goleak.IgnoreTopFunction("github.com/tikv/client-go/v2/tikv.(*ttlManager).keepAlive"), // TODO: fix ttlManager goroutine leak
}
goleak.VerifyTestMain(m, opts...)
} }

View File

@ -50,6 +50,7 @@ func TestSetMinCommitTSInAsyncCommit(t *testing.T) {
unistore.BootstrapWithSingleStore(cluster) unistore.BootstrapWithSingleStore(cluster)
store, err := tikv.NewTestTiKVStore(client, pdClient, nil, nil, 0) store, err := tikv.NewTestTiKVStore(client, pdClient, nil, nil, 0)
require.Nil(err) require.Nil(err)
defer store.Close()
tx, err := store.Begin() tx, err := store.Begin()
require.Nil(err) require.Nil(err)

View File

@ -64,6 +64,10 @@ func (s *testSnapshotFailSuite) SetupSuite() {
s.store = tikv.StoreProbe{KVStore: store} s.store = tikv.StoreProbe{KVStore: store}
} }
func (s *testSnapshotFailSuite) TearDownSuite() {
s.store.Close()
}
func (s *testSnapshotFailSuite) TearDownTest() { func (s *testSnapshotFailSuite) TearDownTest() {
txn, err := s.store.Begin() txn, err := s.store.Begin()
s.Require().Nil(err) s.Require().Nil(err)

View File

@ -79,6 +79,10 @@ func (s *testSplitSuite) SetupTest() {
s.bo = tikv.NewBackofferWithVars(context.Background(), 5000, nil) s.bo = tikv.NewBackofferWithVars(context.Background(), 5000, nil)
} }
func (s *testSplitSuite) TearDownTest() {
s.store.Close()
}
func (s *testSplitSuite) begin() tikv.TxnProbe { func (s *testSplitSuite) begin() tikv.TxnProbe {
txn, err := s.store.Begin() txn, err := s.store.Begin()
s.Require().Nil(err) s.Require().Nil(err)

View File

@ -65,6 +65,7 @@ func (s *testStoreSuite) TearDownTest() {
} }
func (s *testStoreSuite) TestOracle() { func (s *testStoreSuite) TestOracle() {
s.store.GetOracle().Close()
o := &oracles.MockOracle{} o := &oracles.MockOracle{}
s.store.SetOracle(o) s.store.SetOracle(o)

View File

@ -82,7 +82,10 @@ func (s StoreProbe) SetRegionCachePDClient(client pd.Client) {
// ClearTxnLatches clears store's txn latch scheduler. // ClearTxnLatches clears store's txn latch scheduler.
func (s StoreProbe) ClearTxnLatches() { func (s StoreProbe) ClearTxnLatches() {
if s.txnLatches != nil {
s.txnLatches.Close()
s.txnLatches = nil s.txnLatches = nil
}
} }
// SendTxnHeartbeat renews a txn's ttl. // SendTxnHeartbeat renews a txn's ttl.