Skip to content

Commit

Permalink
store/tikv: make tikv_integration_test more stable (pingcap#6113)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored and winkyao committed Mar 22, 2018
1 parent 838ac2f commit d3c5f7f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 78 deletions.
43 changes: 0 additions & 43 deletions store/mockstore/test_util.go

This file was deleted.

15 changes: 6 additions & 9 deletions store/tikv/gcworker/gc_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package gcworker

import (
"flag"
"math"
"strconv"
"testing"
Expand All @@ -23,18 +22,14 @@ import (
gofail "github.com/coreos/gofail/runtime"
. "github.com/pingcap/check"
"github.com/pingcap/kvproto/pkg/errorpb"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/store/mockoracle"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/store/tikv"
"golang.org/x/net/context"
)

var (
withTiKV = flag.Bool("with-tikv", false, "run tests with TiKV cluster started. (not use the mock server)")
pdAddrs = flag.String("pd-addrs", "127.0.0.1:2379", "pd addrs")
)

func TestT(t *testing.T) {
TestingT(t)
}
Expand All @@ -43,18 +38,19 @@ type testGCWorkerSuite struct {
store tikv.Storage
oracle *mockoracle.MockOracle
gcWorker *GCWorker
dom *domain.Domain
}

var _ = Suite(&testGCWorkerSuite{})

func (s *testGCWorkerSuite) SetUpTest(c *C) {
tikv.NewGCHandlerFunc = NewGCWorker
var err error
s.store, err = mockstore.NewTestTiKVStorage(*withTiKV, *pdAddrs)
store, err := mockstore.NewMockTikvStore()
s.store = store.(tikv.Storage)
c.Assert(err, IsNil)
s.oracle = &mockoracle.MockOracle{}
s.store.SetOracle(s.oracle)
_, err = session.BootstrapSession(s.store)
s.dom, err = session.BootstrapSession(s.store)
c.Assert(err, IsNil)
gcWorker, err := NewGCWorker(s.store)
c.Assert(err, IsNil)
Expand All @@ -64,6 +60,7 @@ func (s *testGCWorkerSuite) SetUpTest(c *C) {
}

func (s *testGCWorkerSuite) TearDownTest(c *C) {
s.dom.Close()
err := s.store.Close()
c.Assert(err, IsNil)
}
Expand Down
2 changes: 0 additions & 2 deletions store/tikv/lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package tikv

import (
"fmt"
"math"
"runtime"
"time"
Expand All @@ -34,7 +33,6 @@ type testLockSuite struct {
var _ = Suite(&testLockSuite{})

func (s *testLockSuite) SetUpTest(c *C) {
fmt.Println("SetUpTest .... test Lock suite")
s.store = NewTestStore(c).(*tikvStore)
}

Expand Down
6 changes: 2 additions & 4 deletions store/tikv/scan_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ type testScanMockSuite struct {
var _ = Suite(&testScanMockSuite{})

func (s *testScanMockSuite) TestScanMultipleRegions(c *C) {
kvStore, err := newTestTiKVStore()
c.Assert(err, IsNil)
defer kvStore.Close()
store := NewTestStore(c).(*tikvStore)
defer store.Close()

store := kvStore.(*tikvStore)
txn, err := store.Begin()
c.Assert(err, IsNil)
for ch := byte('a'); ch <= byte('z'); ch++ {
Expand Down
8 changes: 5 additions & 3 deletions store/tikv/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ type testStoreSuite struct {
var _ = Suite(&testStoreSuite{})

func (s *testStoreSuite) SetUpTest(c *C) {
store, err := newTestTiKVStore()
c.Check(err, IsNil)
s.store = store.(*tikvStore)
s.store = NewTestStore(c).(*tikvStore)
}

func (s *testStoreSuite) TearDownTest(c *C) {
c.Assert(s.store.Close(), IsNil)
}

func (s *testStoreSuite) TestParsePath(c *C) {
Expand Down
22 changes: 5 additions & 17 deletions store/tikv/ticlient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,8 @@ var (
pdAddrs = flag.String("pd-addrs", "127.0.0.1:2379", "pd addrs")
)

func newTestTiKVStore() (kv.Storage, error) {
client, pdClient, err := mocktikv.NewTestClient(nil, nil, "")
if err != nil {
return nil, err
}
store, err := NewTestTiKVStore(client, pdClient, nil, nil)
if err != nil {
return nil, errors.Trace(err)
}
return store, err
}

// NewTestStore new a mockStore.
// NewTestStore creates a kv.Storage for testing purpose.
func NewTestStore(c *C) kv.Storage {
// duplicated code with mockstore NewTestTiKVStorage,
// but I have no idea to fix the cycle depenedence
// TODO: try to simplify the code later
if !flag.Parsed() {
flag.Parse()
}
Expand All @@ -63,7 +48,10 @@ func NewTestStore(c *C) kv.Storage {
return store
}

store, err := newTestTiKVStore()
client, pdClient, err := mocktikv.NewTestClient(nil, nil, "")
c.Assert(err, IsNil)

store, err := NewTestTiKVStore(client, pdClient, nil, nil)
c.Assert(err, IsNil)
return store
}
Expand Down

0 comments on commit d3c5f7f

Please sign in to comment.