Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integration: use less tidb code #431

Merged
merged 3 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions integration_tests/2pc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import (
"github.com/ninedraft/israce"
"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/kvrpcpb"
drivertxn "github.com/pingcap/tidb/store/driver/txn"
"github.com/pkg/errors"
"github.com/stretchr/testify/suite"
"github.com/tikv/client-go/v2/config"
Expand Down Expand Up @@ -1089,12 +1088,23 @@ func (s *testCommitterSuite) TestPessimisticLockPrimary() {
s.Equal(tikverr.ErrLockWaitTimeout, errors.Unwrap(waitErr))
}

type kvFilter struct{}

func (f kvFilter) IsUnnecessaryKeyValue(key, value []byte, flags kv.KeyFlags) (bool, error) {
untouched := bytes.Equal(key, []byte("t00000001_i000000001"))
if untouched && flags.HasPresumeKeyNotExists() {
return false, errors.New("unexpected path the untouched key value with PresumeKeyNotExists flag")
}
return untouched, nil
}

func (s *testCommitterSuite) TestResolvePessimisticLock() {
untouchedIndexKey := []byte("t00000001_i000000001")
untouchedIndexValue := []byte{0, 0, 0, 0, 0, 0, 0, 1, 49}
noValueIndexKey := []byte("t00000001_i000000002")

txn := s.begin()
txn.SetKVFilter(drivertxn.TiDBKVFilter{})
txn.SetKVFilter(kvFilter{})
err := txn.Set(untouchedIndexKey, untouchedIndexValue)
s.Nil(err)
lockCtx := kv.NewLockCtx(txn.StartTS(), kv.LockNoWait, time.Now())
Expand Down
3 changes: 1 addition & 2 deletions integration_tests/delete_range_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
"sort"
"testing"

"github.com/pingcap/tidb/store/mockstore/mockcopr"
"github.com/stretchr/testify/suite"
"github.com/tikv/client-go/v2/testutils"
"github.com/tikv/client-go/v2/tikv"
Expand All @@ -58,7 +57,7 @@ type testDeleteRangeSuite struct {
}

func (s *testDeleteRangeSuite) SetupTest() {
client, cluster, pdClient, err := testutils.NewMockTiKV("", mockcopr.NewCoprRPCHandler())
client, cluster, pdClient, err := testutils.NewMockTiKV("", nil)
s.Require().Nil(err)
testutils.BootstrapWithMultiRegions(cluster, []byte("b"), []byte("c"), []byte("d"))
s.cluster = cluster
Expand Down
7 changes: 5 additions & 2 deletions integration_tests/isolation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !race
// +build !race

package tikv_test
Expand All @@ -44,8 +45,9 @@ import (
"testing"
"time"

"github.com/pingcap/tidb/kv"
"github.com/pkg/errors"
"github.com/stretchr/testify/suite"
kverr "github.com/tikv/client-go/v2/error"
"github.com/tikv/client-go/v2/tikv"
"github.com/tikv/client-go/v2/txnkv/transaction"
)
Expand Down Expand Up @@ -123,7 +125,8 @@ func (s *testIsolationSuite) GetWithRetry(k []byte) readRecord {
value: val,
}
}
s.True(kv.IsTxnRetryableError(err))
var e *kverr.ErrRetryable
s.True(errors.As(err, &e))
}
}

Expand Down
3 changes: 1 addition & 2 deletions integration_tests/range_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
"sort"
"testing"

"github.com/pingcap/tidb/store/mockstore/mockcopr"
"github.com/stretchr/testify/suite"
"github.com/tikv/client-go/v2/kv"
"github.com/tikv/client-go/v2/testutils"
Expand Down Expand Up @@ -86,7 +85,7 @@ func (s *testRangeTaskSuite) SetupTest() {
}
allRegionRanges = append(allRegionRanges, makeRange("z", ""))

client, cluster, pdClient, err := testutils.NewMockTiKV("", mockcopr.NewCoprRPCHandler())
client, cluster, pdClient, err := testutils.NewMockTiKV("", nil)
s.Require().Nil(err)
testutils.BootstrapWithMultiRegions(cluster, splitKeys...)
s.cluster = cluster
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/raw/rawkv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
"fmt"
"testing"

"github.com/pingcap/tidb/store/mockstore/unistore"
"github.com/stretchr/testify/suite"
"github.com/tikv/client-go/v2/rawkv"
"github.com/tikv/client-go/v2/testutils"
Expand All @@ -59,9 +58,10 @@ type testRawKVSuite struct {
}

func (s *testRawKVSuite) SetupTest() {
client, pdClient, cluster, err := unistore.New("")
client, cluster, pdClient, err := testutils.NewMockTiKV("", nil)
s.Require().NoError(err)
s.Require().Nil(err)
unistore.BootstrapWithSingleStore(cluster)
testutils.BootstrapWithSingleStore(cluster)
s.cluster = cluster
s.client = rawkv.ClientProbe{Client: &rawkv.Client{}}
s.client.SetPDClient(pdClient)
Expand Down
6 changes: 5 additions & 1 deletion integration_tests/raw/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,9 @@ var (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
opts := []goleak.Option{
goleak.IgnoreTopFunction("github.com/pingcap/goleveldb/leveldb.(*DB).mpoolDrain"),
}

goleak.VerifyTestMain(m, opts...)
}
3 changes: 1 addition & 2 deletions integration_tests/split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (

"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/tidb/store/mockstore/mockcopr"
"github.com/pkg/errors"
"github.com/stretchr/testify/suite"
"github.com/tikv/client-go/v2/testutils"
Expand All @@ -62,7 +61,7 @@ type testSplitSuite struct {
}

func (s *testSplitSuite) SetupTest() {
client, cluster, pdClient, err := testutils.NewMockTiKV("", mockcopr.NewCoprRPCHandler())
client, cluster, pdClient, err := testutils.NewMockTiKV("", nil)
s.Require().Nil(err)
testutils.BootstrapWithSingleStore(cluster)
s.cluster = cluster
Expand Down
8 changes: 5 additions & 3 deletions integration_tests/ticlient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ package tikv_test

import (
"context"
"errors"
"fmt"
"testing"
"time"

"github.com/ninedraft/israce"
"github.com/pingcap/tidb/kv"
"github.com/stretchr/testify/suite"
kverr "github.com/tikv/client-go/v2/error"
tikvstore "github.com/tikv/client-go/v2/kv"
"github.com/tikv/client-go/v2/tikv"
)
Expand Down Expand Up @@ -150,7 +151,8 @@ func (s *testTiclientSuite) TestLargeRequest() {
s.NotNil(err)
err = txn.Commit(context.Background())
s.Nil(err)
s.False(kv.IsTxnRetryableError(err))
var retryableErr *kverr.ErrRetryable
s.False(errors.As(err, &retryableErr))
}

func (s *testTiclientSuite) TestSplitRegionIn2PC() {
Expand Down Expand Up @@ -199,7 +201,7 @@ func (s *testTiclientSuite) TestSplitRegionIn2PC() {
txn := s.beginTxn()
if m == "pessimistic" {
txn.SetPessimistic(true)
lockCtx := &kv.LockCtx{}
lockCtx := &tikvstore.LockCtx{}
lockCtx.ForUpdateTS = txn.StartTS()
keys := make([][]byte, 0, preSplitThresholdInTest)
for i := 0; i < preSplitThresholdInTest; i++ {
Expand Down