From ae7c8d0d148ca4c8a574aed99801a987c99b21e6 Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Thu, 27 Jul 2017 13:39:07 +0800 Subject: [PATCH] store/tikv: optimize testing (#3886) --- store/tikv/2pc_test.go | 5 +++ store/tikv/backoff.go | 3 +- store/tikv/coprocessor_slow_test.go | 54 ----------------------------- store/tikv/store_test.go | 10 ++++-- 4 files changed, 14 insertions(+), 58 deletions(-) delete mode 100644 store/tikv/coprocessor_slow_test.go diff --git a/store/tikv/2pc_test.go b/store/tikv/2pc_test.go index ba295b2f2f..e858994896 100644 --- a/store/tikv/2pc_test.go +++ b/store/tikv/2pc_test.go @@ -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 { diff --git a/store/tikv/backoff.go b/store/tikv/backoff.go index 2729a65400..0667bb53ad 100644 --- a/store/tikv/backoff.go +++ b/store/tikv/backoff.go @@ -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 diff --git a/store/tikv/coprocessor_slow_test.go b/store/tikv/coprocessor_slow_test.go deleted file mode 100644 index fc213cc37f..0000000000 --- a/store/tikv/coprocessor_slow_test.go +++ /dev/null @@ -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) -} diff --git a/store/tikv/store_test.go b/store/tikv/store_test.go index e8e798bcd3..7f03d37c4c 100644 --- a/store/tikv/store_test.go +++ b/store/tikv/store_test.go @@ -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) {