Skip to content

Commit

Permalink
integration: replace some unistore with mockstore (#432)
Browse files Browse the repository at this point in the history
Signed-off-by: disksing <i@disksing.com>
  • Loading branch information
disksing authored Mar 2, 2022
1 parent cb99553 commit 0214a9e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 24 deletions.
2 changes: 1 addition & 1 deletion integration_tests/assertion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type testAssertionSuite struct {
}

func (s *testAssertionSuite) SetupTest() {
s.store = tikv.StoreProbe{KVStore: NewTestStore(s.T())}
s.store = tikv.StoreProbe{KVStore: NewTestUniStore(s.T())}
}

func (s *testAssertionSuite) TearDownTest() {
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type testLockSuite struct {
}

func (s *testLockSuite) SetupTest() {
s.store = tikv.StoreProbe{KVStore: NewTestStore(s.T())}
s.store = tikv.StoreProbe{KVStore: NewTestUniStore(s.T())}
}

func (s *testLockSuite) TearDownTest() {
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/prewrite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ import (
"testing"

"github.com/pingcap/kvproto/pkg/kvrpcpb"
"github.com/pingcap/tidb/store/mockstore/unistore"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tikv/client-go/v2/testutils"
"github.com/tikv/client-go/v2/tikv"
"github.com/tikv/client-go/v2/txnkv/transaction"
)

func TestSetMinCommitTSInAsyncCommit(t *testing.T) {
require, assert := require.New(t), assert.New(t)

client, pdClient, cluster, err := unistore.New("")
client, cluster, pdClient, err := testutils.NewMockTiKV("", nil)
require.Nil(err)
unistore.BootstrapWithSingleStore(cluster)
testutils.BootstrapWithSingleStore(cluster)
store, err := tikv.NewTestTiKVStore(client, pdClient, nil, nil, 0)
require.Nil(err)
defer store.Close()
Expand Down
7 changes: 1 addition & 6 deletions integration_tests/snapshot_fail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (

"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/kvrpcpb"
"github.com/pingcap/tidb/store/mockstore/unistore"
"github.com/stretchr/testify/suite"
tikverr "github.com/tikv/client-go/v2/error"
"github.com/tikv/client-go/v2/oracle"
Expand All @@ -62,11 +61,7 @@ type testSnapshotFailSuite struct {
}

func (s *testSnapshotFailSuite) SetupSuite() {
client, pdClient, cluster, err := unistore.New("")
s.Require().Nil(err)
unistore.BootstrapWithSingleStore(cluster)
store, err := tikv.NewTestTiKVStore(fpClient{Client: client}, pdClient, nil, nil, 0)
s.Require().Nil(err)
store := NewTestUniStore(s.T())
s.store = tikv.StoreProbe{KVStore: store}
}

Expand Down
49 changes: 36 additions & 13 deletions integration_tests/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
"github.com/pingcap/tidb/store/mockstore/unistore"
"github.com/stretchr/testify/require"
"github.com/tikv/client-go/v2/config"
"github.com/tikv/client-go/v2/testutils"
"github.com/tikv/client-go/v2/tikv"
"github.com/tikv/client-go/v2/txnkv/transaction"
"github.com/tikv/client-go/v2/util/codec"
Expand All @@ -65,19 +66,25 @@ func NewTestStore(t *testing.T) *tikv.KVStore {
}

if *withTiKV {
addrs := strings.Split(*pdAddrs, ",")
pdClient, err := pd.NewClient(addrs, pd.SecurityOption{})
require.Nil(t, err)
var securityConfig config.Security
tlsConfig, err := securityConfig.ToTLSConfig()
require.Nil(t, err)
spKV, err := tikv.NewEtcdSafePointKV(addrs, tlsConfig)
require.Nil(t, err)
store, err := tikv.NewKVStore("test-store", &tikv.CodecPDClient{Client: pdClient}, spKV, tikv.NewRPCClient())
require.Nil(t, err)
err = clearStorage(store)
require.Nil(t, err)
return store
return newTiKVStore(t)
}
client, cluster, pdClient, err := testutils.NewMockTiKV("", nil)
require.NoError(t, err)
testutils.BootstrapWithSingleStore(cluster)
store, err := tikv.NewTestTiKVStore(client, pdClient, nil, nil, 0)
require.Nil(t, err)
return store
}

// NewTestUniStore creates a KVStore (using tidb/unistore) for testing purpose.
// TODO: switch to use mockstore and remove it.
func NewTestUniStore(t *testing.T) *tikv.KVStore {
if !flag.Parsed() {
flag.Parse()
}

if *withTiKV {
return newTiKVStore(t)
}
client, pdClient, cluster, err := unistore.New("")
require.Nil(t, err)
Expand All @@ -87,6 +94,22 @@ func NewTestStore(t *testing.T) *tikv.KVStore {
return store
}

func newTiKVStore(t *testing.T) *tikv.KVStore {
addrs := strings.Split(*pdAddrs, ",")
pdClient, err := pd.NewClient(addrs, pd.SecurityOption{})
require.Nil(t, err)
var securityConfig config.Security
tlsConfig, err := securityConfig.ToTLSConfig()
require.Nil(t, err)
spKV, err := tikv.NewEtcdSafePointKV(addrs, tlsConfig)
require.Nil(t, err)
store, err := tikv.NewKVStore("test-store", &tikv.CodecPDClient{Client: pdClient}, spKV, tikv.NewRPCClient())
require.Nil(t, err)
err = clearStorage(store)
require.Nil(t, err)
return store
}

func clearStorage(store *tikv.KVStore) error {
txn, err := store.Begin()
if err != nil {
Expand Down

0 comments on commit 0214a9e

Please sign in to comment.