github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/causetstore/stochastikctx/stmtctx/stmtctx_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 stmtctx_test 15 16 import ( 17 "fmt" 18 "testing" 19 "time" 20 21 . "github.com/whtcorpsinc/check" 22 "github.com/whtcorpsinc/milevadb/stochastikctx/stmtctx" 23 "github.com/whtcorpsinc/milevadb/soliton/execdetails" 24 ) 25 26 func TestT(t *testing.T) { 27 TestingT(t) 28 } 29 30 type stmtctxSuit struct{} 31 32 var _ = Suite(&stmtctxSuit{}) 33 34 func (s *stmtctxSuit) TestCausetTasksDetails(c *C) { 35 ctx := new(stmtctx.StatementContext) 36 backoffs := []string{"einsteindbRPC", "FIDelRPC", "regionMiss"} 37 for i := 0; i < 100; i++ { 38 d := &execdetails.InterDircDetails{ 39 CalleeAddress: fmt.Sprintf("%v", i+1), 40 ProcessTime: time.Second * time.Duration(i+1), 41 WaitTime: time.Millisecond * time.Duration(i+1), 42 BackoffSleep: make(map[string]time.Duration), 43 BackoffTimes: make(map[string]int), 44 } 45 for _, backoff := range backoffs { 46 d.BackoffSleep[backoff] = time.Millisecond * 100 * time.Duration(i+1) 47 d.BackoffTimes[backoff] = i + 1 48 } 49 ctx.MergeInterDircDetails(d, nil) 50 } 51 d := ctx.CausetTasksDetails() 52 c.Assert(d.NumCausetTasks, Equals, 100) 53 c.Assert(d.AvgProcessTime, Equals, time.Second*101/2) 54 c.Assert(d.P90ProcessTime, Equals, time.Second*91) 55 c.Assert(d.MaxProcessTime, Equals, time.Second*100) 56 c.Assert(d.MaxProcessAddress, Equals, "100") 57 c.Assert(d.AvgWaitTime, Equals, time.Millisecond*101/2) 58 c.Assert(d.P90WaitTime, Equals, time.Millisecond*91) 59 c.Assert(d.MaxWaitTime, Equals, time.Millisecond*100) 60 c.Assert(d.MaxWaitAddress, Equals, "100") 61 fields := d.ToZapFields() 62 c.Assert(len(fields), Equals, 9) 63 for _, backoff := range backoffs { 64 c.Assert(d.MaxBackoffAddress[backoff], Equals, "100") 65 c.Assert(d.MaxBackoffTime[backoff], Equals, 100*time.Millisecond*100) 66 c.Assert(d.P90BackoffTime[backoff], Equals, time.Millisecond*100*91) 67 c.Assert(d.AvgBackoffTime[backoff], Equals, time.Millisecond*100*101/2) 68 c.Assert(d.TotBackoffTimes[backoff], Equals, 101*50) 69 c.Assert(d.TotBackoffTime[backoff], Equals, 101*50*100*time.Millisecond) 70 } 71 } 72 73 func (s *stmtctxSuit) TestStatementContextPushDownFLags(c *C) { 74 testCases := []struct { 75 in *stmtctx.StatementContext 76 out uint64 77 }{ 78 {&stmtctx.StatementContext{InInsertStmt: true}, 8}, 79 {&stmtctx.StatementContext{InUFIDelateStmt: true}, 16}, 80 {&stmtctx.StatementContext{InDeleteStmt: true}, 16}, 81 {&stmtctx.StatementContext{InSelectStmt: true}, 32}, 82 {&stmtctx.StatementContext{IgnoreTruncate: true}, 1}, 83 {&stmtctx.StatementContext{TruncateAsWarning: true}, 2}, 84 {&stmtctx.StatementContext{OverflowAsWarning: true}, 64}, 85 {&stmtctx.StatementContext{IgnoreZeroInDate: true}, 128}, 86 {&stmtctx.StatementContext{DividedByZeroAsWarning: true}, 256}, 87 {&stmtctx.StatementContext{InLoadDataStmt: true}, 1024}, 88 {&stmtctx.StatementContext{InSelectStmt: true, TruncateAsWarning: true}, 34}, 89 {&stmtctx.StatementContext{DividedByZeroAsWarning: true, IgnoreTruncate: true}, 257}, 90 {&stmtctx.StatementContext{InUFIDelateStmt: true, IgnoreZeroInDate: true, InLoadDataStmt: true}, 1168}, 91 } 92 for _, tt := range testCases { 93 got := tt.in.PushDownFlags() 94 c.Assert(got, Equals, tt.out, Commentf("get %v, want %v", got, tt.out)) 95 } 96 }