diff --git a/store/tikv/client_fail_test.go b/store/tikv/client_fail_test.go index e98bcb253d8d4..96f64bd571629 100644 --- a/store/tikv/client_fail_test.go +++ b/store/tikv/client_fail_test.go @@ -25,11 +25,24 @@ import ( "github.com/pingcap/tidb/store/tikv/tikvrpc" ) +type testClientFailSuite struct { + OneByOneSuite +} + +func (s *testClientFailSuite) SetUpSuite(c *C) { + // This lock make testClientFailSuite runs exclusively. + withTiKVGlobalLock.Lock() +} + +func (s testClientFailSuite) TearDownSuite(c *C) { + withTiKVGlobalLock.Unlock() +} + func setGrpcConnectionCount(count uint) { config.GetGlobalConfig().TiKVClient.GrpcConnectionCount = count } -func (s *testClientSuite) TestPanicInRecvLoop(c *C) { +func (s *testClientFailSuite) TestPanicInRecvLoop(c *C) { c.Assert(failpoint.Enable("github.com/pingcap/tidb/store/tikv/panicInFailPendingRequests", `panic`), IsNil) c.Assert(failpoint.Enable("github.com/pingcap/tidb/store/tikv/gotErrorInRecvLoop", `return("0")`), IsNil) diff --git a/store/tikv/client_test.go b/store/tikv/client_test.go index ab6a84d87b9ba..c7e197bbe351a 100644 --- a/store/tikv/client_test.go +++ b/store/tikv/client_test.go @@ -34,6 +34,7 @@ type testClientSuite struct { } var _ = Suite(&testClientSuite{}) +var _ = Suite(&testClientFailSuite{}) func setMaxBatchSize(size uint) { config.GetGlobalConfig().TiKVClient.MaxBatchSize = size diff --git a/store/tikv/ticlient_test.go b/store/tikv/ticlient_test.go index 6662bb9a8ad20..44ca2d40f7f41 100644 --- a/store/tikv/ticlient_test.go +++ b/store/tikv/ticlient_test.go @@ -28,7 +28,7 @@ import ( ) var ( - withTiKVGlobalLock sync.Mutex + withTiKVGlobalLock sync.RWMutex 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") ) diff --git a/store/tikv/tikv_test.go b/store/tikv/tikv_test.go index a4db0b7df60ec..d4a5bfe1d6a6c 100644 --- a/store/tikv/tikv_test.go +++ b/store/tikv/tikv_test.go @@ -18,18 +18,21 @@ import ( ) // OneByOneSuite is a suite, When with-tikv flag is true, there is only one storage, so the test suite have to run one by one. -type OneByOneSuite struct { -} +type OneByOneSuite struct{} -func (s OneByOneSuite) SetUpSuite(c *C) { +func (s *OneByOneSuite) SetUpSuite(c *C) { if *withTiKV { withTiKVGlobalLock.Lock() + } else { + withTiKVGlobalLock.RLock() } } -func (s OneByOneSuite) TearDownSuite(c *C) { +func (s *OneByOneSuite) TearDownSuite(c *C) { if *withTiKV { withTiKVGlobalLock.Unlock() + } else { + withTiKVGlobalLock.RUnlock() } }