mirror of https://github.com/tikv/client-go.git
2pc_test: replace pingcap/check with testify (#163)
Signed-off-by: disksing <i@disksing.com>
This commit is contained in:
parent
ccb3cdb2f1
commit
f634df18a9
|
|
@ -1,153 +0,0 @@
|
|||
// Copyright 2021 TiKV Authors
|
||||
//
|
||||
// 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.
|
||||
|
||||
// NOTE: The code in this file is based on code from the
|
||||
// TiDB project, licensed under the Apache License v 2.0
|
||||
//
|
||||
// https://github.com/pingcap/tidb/tree/cc5e161ac06827589c4966674597c137cc9e809c/store/tikv/tests/2pc_fail_test.go
|
||||
//
|
||||
|
||||
// Copyright 2017 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.
|
||||
|
||||
package tikv_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
. "github.com/pingcap/check"
|
||||
"github.com/pingcap/errors"
|
||||
"github.com/pingcap/failpoint"
|
||||
"github.com/pingcap/parser/terror"
|
||||
tikverr "github.com/tikv/client-go/v2/error"
|
||||
)
|
||||
|
||||
// TestFailCommitPrimaryRpcErrors tests rpc errors are handled properly when
|
||||
// committing primary region task.
|
||||
func (s *testCommitterSuite) TestFailCommitPrimaryRpcErrors(c *C) {
|
||||
c.Assert(failpoint.Enable("tikvclient/rpcCommitResult", `return("timeout")`), IsNil)
|
||||
defer func() {
|
||||
c.Assert(failpoint.Disable("tikvclient/rpcCommitResult"), IsNil)
|
||||
}()
|
||||
// The rpc error will be wrapped to ErrResultUndetermined.
|
||||
t1 := s.begin(c)
|
||||
err := t1.Set([]byte("a"), []byte("a1"))
|
||||
c.Assert(err, IsNil)
|
||||
err = t1.Commit(context.Background())
|
||||
c.Assert(err, NotNil)
|
||||
c.Assert(terror.ErrorEqual(err, terror.ErrResultUndetermined), IsTrue, Commentf("%s", errors.ErrorStack(err)))
|
||||
|
||||
// We don't need to call "Rollback" after "Commit" fails.
|
||||
err = t1.Rollback()
|
||||
c.Assert(err, Equals, tikverr.ErrInvalidTxn)
|
||||
}
|
||||
|
||||
// TestFailCommitPrimaryRegionError tests RegionError is handled properly when
|
||||
// committing primary region task.
|
||||
func (s *testCommitterSuite) TestFailCommitPrimaryRegionError(c *C) {
|
||||
c.Assert(failpoint.Enable("tikvclient/rpcCommitResult", `return("notLeader")`), IsNil)
|
||||
defer func() {
|
||||
c.Assert(failpoint.Disable("tikvclient/rpcCommitResult"), IsNil)
|
||||
}()
|
||||
// Ensure it returns the original error without wrapped to ErrResultUndetermined
|
||||
// if it exceeds max retry timeout on RegionError.
|
||||
t2 := s.begin(c)
|
||||
err := t2.Set([]byte("b"), []byte("b1"))
|
||||
c.Assert(err, IsNil)
|
||||
err = t2.Commit(context.Background())
|
||||
c.Assert(err, NotNil)
|
||||
c.Assert(terror.ErrorNotEqual(err, terror.ErrResultUndetermined), IsTrue)
|
||||
}
|
||||
|
||||
// TestFailCommitPrimaryRPCErrorThenRegionError tests the case when commit first
|
||||
// receive a rpc timeout, then region errors afterwrards.
|
||||
func (s *testCommitterSuite) TestFailCommitPrimaryRPCErrorThenRegionError(c *C) {
|
||||
c.Assert(failpoint.Enable("tikvclient/rpcCommitResult", `1*return("timeout")->return("notLeader")`), IsNil)
|
||||
defer func() {
|
||||
c.Assert(failpoint.Disable("tikvclient/rpcCommitResult"), IsNil)
|
||||
}()
|
||||
// The region error will be wrapped to ErrResultUndetermined.
|
||||
t1 := s.begin(c)
|
||||
err := t1.Set([]byte("a"), []byte("a1"))
|
||||
c.Assert(err, IsNil)
|
||||
err = t1.Commit(context.Background())
|
||||
c.Assert(err, NotNil)
|
||||
c.Assert(terror.ErrorEqual(err, terror.ErrResultUndetermined), IsTrue, Commentf("%s", errors.ErrorStack(err)))
|
||||
}
|
||||
|
||||
// TestFailCommitPrimaryKeyError tests KeyError is handled properly when
|
||||
// committing primary region task.
|
||||
func (s *testCommitterSuite) TestFailCommitPrimaryKeyError(c *C) {
|
||||
c.Assert(failpoint.Enable("tikvclient/rpcCommitResult", `return("keyError")`), IsNil)
|
||||
defer func() {
|
||||
c.Assert(failpoint.Disable("tikvclient/rpcCommitResult"), IsNil)
|
||||
}()
|
||||
// Ensure it returns the original error without wrapped to ErrResultUndetermined
|
||||
// if it meets KeyError.
|
||||
t3 := s.begin(c)
|
||||
err := t3.Set([]byte("c"), []byte("c1"))
|
||||
c.Assert(err, IsNil)
|
||||
err = t3.Commit(context.Background())
|
||||
c.Assert(err, NotNil)
|
||||
c.Assert(terror.ErrorNotEqual(err, terror.ErrResultUndetermined), IsTrue)
|
||||
}
|
||||
|
||||
// TestFailCommitPrimaryRPCErrorThenKeyError tests KeyError overwrites the undeterminedErr.
|
||||
func (s *testCommitterSuite) TestFailCommitPrimaryRPCErrorThenKeyError(c *C) {
|
||||
c.Assert(failpoint.Enable("tikvclient/rpcCommitResult", `1*return("timeout")->return("keyError")`), IsNil)
|
||||
defer func() {
|
||||
c.Assert(failpoint.Disable("tikvclient/rpcCommitResult"), IsNil)
|
||||
}()
|
||||
// Ensure it returns the original error without wrapped to ErrResultUndetermined
|
||||
// if it meets KeyError.
|
||||
t3 := s.begin(c)
|
||||
err := t3.Set([]byte("c"), []byte("c1"))
|
||||
c.Assert(err, IsNil)
|
||||
err = t3.Commit(context.Background())
|
||||
c.Assert(err, NotNil)
|
||||
c.Assert(terror.ErrorEqual(err, terror.ErrResultUndetermined), IsFalse)
|
||||
}
|
||||
|
||||
func (s *testCommitterSuite) TestFailCommitTimeout(c *C) {
|
||||
c.Assert(failpoint.Enable("tikvclient/rpcCommitTimeout", `return(true)`), IsNil)
|
||||
defer func() {
|
||||
c.Assert(failpoint.Disable("tikvclient/rpcCommitTimeout"), IsNil)
|
||||
}()
|
||||
txn := s.begin(c)
|
||||
err := txn.Set([]byte("a"), []byte("a1"))
|
||||
c.Assert(err, IsNil)
|
||||
err = txn.Set([]byte("b"), []byte("b1"))
|
||||
c.Assert(err, IsNil)
|
||||
err = txn.Set([]byte("c"), []byte("c1"))
|
||||
c.Assert(err, IsNil)
|
||||
err = txn.Commit(context.Background())
|
||||
c.Assert(err, NotNil)
|
||||
|
||||
txn2 := s.begin(c)
|
||||
value, err := txn2.Get(context.TODO(), []byte("a"))
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(len(value), Greater, 0)
|
||||
_, err = txn2.Get(context.TODO(), []byte("b"))
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(len(value), Greater, 0)
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
// Copyright 2021 TiKV Authors
|
||||
//
|
||||
// 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.
|
||||
|
||||
// NOTE: The code in this file is based on code from the
|
||||
// TiDB project, licensed under the Apache License v 2.0
|
||||
//
|
||||
// https://github.com/pingcap/tidb/tree/cc5e161ac06827589c4966674597c137cc9e809c/store/tikv/tests/2pc_slow_test.go
|
||||
//
|
||||
|
||||
// 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_test
|
||||
|
||||
import (
|
||||
. "github.com/pingcap/check"
|
||||
)
|
||||
|
||||
// TestCommitMultipleRegions tests commit multiple regions.
|
||||
// The test takes too long under the race detector.
|
||||
func (s *testCommitterSuite) TestCommitMultipleRegions(c *C) {
|
||||
m := make(map[string]string)
|
||||
for i := 0; i < 100; i++ {
|
||||
k, v := randKV(10, 10)
|
||||
m[k] = v
|
||||
}
|
||||
s.mustCommit(c, m)
|
||||
|
||||
// Test big values.
|
||||
m = make(map[string]string)
|
||||
for i := 0; i < 50; i++ {
|
||||
k, v := randKV(11, int(txnCommitBatchSize)/7)
|
||||
m[k] = v
|
||||
}
|
||||
s.mustCommit(c, m)
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue