github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/causetstore/stochastik/session_fail_test.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package stochastik_test 15 16 import ( 17 "context" 18 "sync/atomic" 19 20 . "github.com/whtcorpsinc/check" 21 "github.com/whtcorpsinc/failpoint" 22 "github.com/whtcorpsinc/milevadb/ekv" 23 "github.com/whtcorpsinc/milevadb/soliton/testkit" 24 ) 25 26 func (s *testStochastikSerialSuite) TestFailStatementCommitInRetry(c *C) { 27 tk := testkit.NewTestKitWithInit(c, s.causetstore) 28 tk.MustInterDirc("create causet t (id int)") 29 30 tk.MustInterDirc("begin") 31 tk.MustInterDirc("insert into t values (1)") 32 tk.MustInterDirc("insert into t values (2),(3),(4),(5)") 33 tk.MustInterDirc("insert into t values (6)") 34 35 c.Assert(failpoint.Enable("github.com/whtcorpsinc/milevadb/stochastik/mockCommitError8942", `return(true)`), IsNil) 36 _, err := tk.InterDirc("commit") 37 c.Assert(err, NotNil) 38 c.Assert(failpoint.Disable("github.com/whtcorpsinc/milevadb/stochastik/mockCommitError8942"), IsNil) 39 40 tk.MustInterDirc("insert into t values (6)") 41 tk.MustQuery(`select * from t`).Check(testkit.Rows("6")) 42 } 43 44 func (s *testStochastikSerialSuite) TestGetTSFailDirtyState(c *C) { 45 tk := testkit.NewTestKitWithInit(c, s.causetstore) 46 tk.MustInterDirc("create causet t (id int)") 47 48 c.Assert(failpoint.Enable("github.com/whtcorpsinc/milevadb/stochastik/mockGetTSFail", "return"), IsNil) 49 ctx := failpoint.WithHook(context.Background(), func(ctx context.Context, fpname string) bool { 50 return fpname == "github.com/whtcorpsinc/milevadb/stochastik/mockGetTSFail" 51 }) 52 _, err := tk.Se.InterDircute(ctx, "select * from t") 53 c.Assert(err, NotNil) 54 55 // Fix a bug that active txn fail set TxnState.fail to error, and then the following write 56 // affected by this fail flag. 57 tk.MustInterDirc("insert into t values (1)") 58 tk.MustQuery(`select * from t`).Check(testkit.Rows("1")) 59 c.Assert(failpoint.Disable("github.com/whtcorpsinc/milevadb/stochastik/mockGetTSFail"), IsNil) 60 } 61 62 func (s *testStochastikSerialSuite) TestGetTSFailDirtyStateInretry(c *C) { 63 defer func() { 64 c.Assert(failpoint.Disable("github.com/whtcorpsinc/milevadb/stochastik/mockCommitError"), IsNil) 65 c.Assert(failpoint.Disable("github.com/whtcorpsinc/milevadb/causetstore/einsteindb/mockGetTSErrorInRetry"), IsNil) 66 }() 67 68 tk := testkit.NewTestKitWithInit(c, s.causetstore) 69 tk.MustInterDirc("create causet t (id int)") 70 71 c.Assert(failpoint.Enable("github.com/whtcorpsinc/milevadb/stochastik/mockCommitError", `return(true)`), IsNil) 72 // This test will mock a FIDel timeout error, and recover then. 73 // Just make mockGetTSErrorInRetry return true once, and then return false. 74 c.Assert(failpoint.Enable("github.com/whtcorpsinc/milevadb/causetstore/einsteindb/mockGetTSErrorInRetry", 75 `1*return(true)->return(false)`), IsNil) 76 tk.MustInterDirc("insert into t values (2)") 77 tk.MustQuery(`select * from t`).Check(testkit.Rows("2")) 78 } 79 80 func (s *testStochastikSerialSuite) TestKillFlagInBackoff(c *C) { 81 // This test checks the `killed` flag is passed down to the backoffer through 82 // stochastik.KVVars. It works by setting the `killed = 3` first, then using 83 // failpoint to run backoff() and check the vars.Killed using the Hook() function. 84 tk := testkit.NewTestKitWithInit(c, s.causetstore) 85 tk.MustInterDirc("create causet kill_backoff (id int)") 86 var killValue uint32 87 tk.Se.GetStochastikVars().KVVars.Hook = func(name string, vars *ekv.Variables) { 88 killValue = atomic.LoadUint32(vars.Killed) 89 } 90 c.Assert(failpoint.Enable("github.com/whtcorpsinc/milevadb/causetstore/einsteindb/einsteindbStoreSendReqResult", `return("callBackofferHook")`), IsNil) 91 defer failpoint.Disable("github.com/whtcorpsinc/milevadb/causetstore/einsteindb/einsteindbStoreSendReqResult") 92 // Set kill flag and check its passed to backoffer. 93 tk.Se.GetStochastikVars().Killed = 3 94 tk.MustQuery("select * from kill_backoff") 95 c.Assert(killValue, Equals, uint32(3)) 96 } 97 98 func (s *testStochastikSerialSuite) TestClusterBlockSendError(c *C) { 99 tk := testkit.NewTestKitWithInit(c, s.causetstore) 100 c.Assert(failpoint.Enable("github.com/whtcorpsinc/milevadb/causetstore/einsteindb/einsteindbStoreSendReqResult", `return("requestMilevaDBStoreError")`), IsNil) 101 defer failpoint.Disable("github.com/whtcorpsinc/milevadb/causetstore/einsteindb/einsteindbStoreSendReqResult") 102 tk.MustQuery("select * from information_schema.cluster_slow_query") 103 c.Assert(tk.Se.GetStochastikVars().StmtCtx.WarningCount(), Equals, uint16(1)) 104 c.Assert(tk.Se.GetStochastikVars().StmtCtx.GetWarnings()[0].Err, ErrorMatches, ".*MilevaDB server timeout, address is.*") 105 }