store/tikv: optimize testing (#3886)

This commit is contained in:
tiancaiamao
2017-07-27 13:39:07 +08:00
committed by Shen Li
parent df4d25b8fd
commit ae7c8d0d14
4 changed files with 14 additions and 58 deletions

View File

@ -45,6 +45,11 @@ func (s *testCommitterSuite) SetUpTest(c *C) {
store, err := newTikvStore("mock-tikv-store", pdCli, client, false)
c.Assert(err, IsNil)
s.store = store
commitMaxBackoff = 2000
}
func (s *testCommitterSuite) TearDownSuite(c *C) {
commitMaxBackoff = 20000
}
func (s *testCommitterSuite) begin(c *C) *tikvTxn {

View File

@ -124,13 +124,14 @@ const (
copNextMaxBackoff = 20000
getMaxBackoff = 20000
prewriteMaxBackoff = 20000
commitMaxBackoff = 20000
cleanupMaxBackoff = 20000
gcMaxBackoff = 100000
gcResolveLockMaxBackoff = 100000
rawkvMaxBackoff = 20000
)
var commitMaxBackoff = 20000
// Backoffer is a utility for retrying queries.
type Backoffer struct {
fn map[backoffType]func() int

View File

@ -1,54 +0,0 @@
// Copyright 2016 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
// +build !race
package tikv
import (
. "github.com/pingcap/check"
"github.com/pingcap/tidb/kv"
mocktikv "github.com/pingcap/tidb/store/tikv/mock-tikv"
"github.com/pingcap/tidb/util/codec"
goctx "golang.org/x/net/context"
)
// The test takes too long under the race detector.
func (s *testCoprocessorSuite) TestBuildHugeTasks(c *C) {
cluster := mocktikv.NewCluster()
var splitKeys [][]byte
for ch := byte('a'); ch <= byte('z'); ch++ {
splitKeys = append(splitKeys, []byte{ch})
}
mocktikv.BootstrapWithMultiRegions(cluster, splitKeys...)
bo := NewBackoffer(3000, goctx.Background())
pdCli := &codecPDClient{mocktikv.NewPDClient(cluster)}
cache := NewRegionCache(pdCli)
const rangesPerRegion = 1e6
ranges := make([]kv.KeyRange, 0, 26*rangesPerRegion)
for ch := byte('a'); ch <= byte('z'); ch++ {
for i := 0; i < rangesPerRegion; i++ {
start := make([]byte, 0, 9)
end := make([]byte, 0, 9)
ranges = append(ranges, kv.KeyRange{
StartKey: codec.EncodeInt(append(start, ch), int64(i*2)),
EndKey: codec.EncodeInt(append(end, ch), int64(i*2+1)),
})
}
}
_, err := buildCopTasks(bo, cache, &copRanges{mid: ranges}, false)
c.Assert(err, IsNil)
}

View File

@ -338,11 +338,15 @@ type checkRequestClient struct {
}
func (c *checkRequestClient) SendReq(ctx goctx.Context, addr string, req *tikvrpc.Request) (*tikvrpc.Response, error) {
resp, err := c.Client.SendReq(ctx, addr, req)
if c.priority != req.Priority {
return nil, errors.New("request check error")
if resp.Get != nil {
resp.Get.Error = &pb.KeyError{
Abort: "request check error",
}
}
}
return c.Client.SendReq(ctx, addr, req)
return resp, err
}
func (s *testStoreSuite) TestRequestPriority(c *C) {